恢復處於NOARCHIVELOG模式的數據庫數據庫
當數據庫處於NOARCHIVELOG模式時,若是出現介質故障 ,則最後一次備份以後對數據庫所作的任何操做都將丟失。經過RMAN執行恢復時,只須要執行restore命令將數據庫文件修復到正確的位置,而後就能夠打開數據庫。也就是說,對於處於NOARCHIVELOG模式下的數據庫,管理員不須要執行recover命令。oracle
1.Sys登錄,並確認數據庫屬於NOARCHIVELOG模式app
SQL> select log_mode from v$database;ide
LOG_MODE測試
------------spa
ARCHIVELOGrest
SQL>orm
SQL>blog
SQL>get
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 2755870720 bytes
Fixed Size 2256432 bytes
Variable Size 671089104 bytes
Database Buffers 2063597568 bytes
Redo Buffers 18927616 bytes
Database mounted.
2.更改數據庫爲noarchivelog狀態
SQL> alter database noarchivelog;
alter database noarchivelog
*
ERROR at line 1:
ORA-38774: cannot disable media recovery - flashback database is enabled
SQL> alter database flashback off;
Database altered.
SQL> alter database noarchivelog;
Database altered.
SQL> archive log list;
3.執行一下命令,備份整個數據庫
RMAN> run{
2> allocate channel ch_1 type disk;
3> backup database
4> format '/u01/app/oracle/oradata/Backup/orcl_%t_%u.bak';
5> }
4.能夠查看一下備份下來的文件,上邊有路徑,數據文件和控制文件
5.模擬users.dbf丟失,這裏能夠先查找數據文件的位置
SQL> select file_name,tablespace_name,bytes from dba_data_files;
[oracle@orcl Backup]$ cd /u01/app/oracle/oradata/orcl
[oracle@orcl orcl]$ rm users01.dbf
6.刪除的時候數據庫必須是關閉的,否則系統禁止刪除正在使用的數據文件,如今到起庫測試一下,提示找不到數據文件
RMAN> startup
database is already started
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of startup command at 12/04/2019 03:39:53
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/orcl/users01.dbf'
RMAN> run{
7.startup mount狀態才能訪問數據文件,就能夠執行restore
RMAN> run{
2> allocate channel ch_1 type disk;
3> restore database;
4> }
這時候看一下數據文件是能夠恢復到目錄下的
8.起庫看一下是能夠起來的
RMAN> startup
database is already started
database opened
處於ARCHIVE模式
恢復處於archivelog模式的數據庫
1.查看數據庫是否處於歸檔
SQL> archive log list;
2.啓動rman對目標表空間進行備份,而後模擬刪除
[oracle@orcl Backup]$ ramn target /
RMAN> run{
2> allocate channel ch_1 type disk;
3> allocate channel ch_2 type disk;
4> backup tablespace users
5> format '/u01/app/oracle/oradata/Backup/users_tablespace.bak';
6> }
3.關閉數據庫,而後模擬刪除掉users.dbf,users.dbf的路徑怎麼找上邊寫的有命令
RMAN> shutdown immediate
database closed
database dismounted
Oracle instance shut down
RMAN> startup mount
RMAN> alter database open;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 12/04/2019 05:20:32
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/orcl/users01.dbf'
4.數據庫如今mount狀態,恢復表空間
RMAN> run{
2> allocate channel ch_1 type disk;
3> restore tablespace users;
4> recover tablespace users;
5> }
5.更改爲open狀態是沒有問題的,users的數據文件仍是在的
RMAN> alter database open;
database opened