rman恢復資料庫--用備份的控制檔案

chicken0915發表於2013-11-12

1、做全庫備份
RMAN> run{
 allocate channel c1 type disk maxpiecesize=500m;
 backup current controlfile format '+dgasm/backup/ctl_%d_%s';
 backup full database format '+dgasm/backup/db_%d_%s_%p_%t';
 sql 'alter system archive log current';
 release channel c1;
 }2> 3> 4> 5> 6> 7>
using target database control file instead of recovery catalog
allocated channel: c1
channel c1: SID=37 device type=DISK
Starting backup at 30-JUN-12
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
including current control file in backup set
channel c1: starting piece 1 at 30-JUN-12
channel c1: finished piece 1 at 30-JUN-12
piece handle=+DGASM/backup/ctl_ora11_37 tag=TAG20120630T094535 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:04
Finished backup at 30-JUN-12
Starting backup at 30-JUN-12
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00001 name=+DGASM/ora11/datafile/system.257.785186755
input datafile file number=00002 name=+DGASM/ora11/datafile/sysaux.258.785186845
input datafile file number=00003 name=+DGASM/ora11/datafile/undotbs1.259.785186901
input datafile file number=00004 name=+DGASM/ora11/datafile/users.272.787009469
channel c1: starting piece 1 at 30-JUN-12
channel c1: finished piece 1 at 30-JUN-12
piece handle=+DGASM/backup/db_ora11_38_1_787311941 tag=TAG20120630T094541 comment=NONE
channel c1: starting piece 2 at 30-JUN-12
channel c1: finished piece 2 at 30-JUN-12
piece handle=+DGASM/backup/db_ora11_38_2_787311941 tag=TAG20120630T094541 comment=NONE
channel c1: backup set complete, elapsed time: 00:01:00
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel c1: starting piece 1 at 30-JUN-12
channel c1: finished piece 1 at 30-JUN-12
piece handle=+DGASM/backup/db_ora11_39_1_787312002 tag=TAG20120630T094541 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
Finished backup at 30-JUN-12
sql statement: alter system archive log current
released channel: c1
RMAN>
2、做操做
建立haozg user 然後建表
SQL> create table haozg_hist as select * from v$loghist;
Table created.
SQL> alter system switch logfile;
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL>
SQL> create table test(id number,name varchar2(13));
Table created.
SQL>  insert into test select object_id,object_name from dba_objects where rownum=1;
1 row created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
SQL> /
System altered.
SQL> /
System altered.
3、關閉資料庫,刪除控制檔案,模擬控制檔案順壞
在grid 使用者下操作
ASMCMD> cd controlfile
ASMCMD> ls
current.260.787304065
ASMCMD> rm -f *
4、啟動資料庫到nomount狀態

5、轉儲控制檔案從備份集中
RMAN> restore controlfile  from '+dgasm/backup/ctl_ora11_37';
Starting restore at 30-JUN-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=26 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
output file name=+DGASM/controlfile/control01.ctl
Finished restore at 30-JUN-12
RMAN>
6、啟動資料庫到mount狀態
7、恢復資料庫
RMAN> recover database;
Starting recover at 30-JUN-12
released channel: ORA_DISK_1
Starting implicit crosscheck backup at 30-JUN-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=26 device type=DISK
Crosschecked 19 objects
Finished implicit crosscheck backup at 30-JUN-12
Starting implicit crosscheck copy at 30-JUN-12
using channel ORA_DISK_1
Crosschecked 8 objects
Finished implicit crosscheck copy at 30-JUN-12
searching for all files in the recovery area
cataloging files...
no files cataloged
using channel ORA_DISK_1
RMAN-06900: WARNING: unable to generate V$RMAN_STATUS or V$RMAN_OUTPUT row
RMAN-06901: WARNING: disabling update of the V$RMAN_STATUS and V$RMAN_OUTPUT rows
ORACLE error from target database:
ORA-19922: there is no parent row with id 0 and level 1

starting media recovery
archived log for thread 1 with sequence 8 is already on disk as file +DGASM/ora11/onlinelog/group_2.264.785192615
archived log for thread 1 with sequence 9 is already on disk as file +DGASM/ora11/onlinelog/group_3.265.785192859
archived log for thread 1 with sequence 10 is already on disk as file +DGASM/ora11/onlinelog/group_1.263.785192081
archived log file name=/oracle/archivelog/1_1_787309225.dbf thread=1 sequence=1
archived log file name=/oracle/archivelog/1_2_787309225.dbf thread=1 sequence=2
archived log file name=/oracle/archivelog/1_3_787309225.dbf thread=1 sequence=3
archived log file name=/oracle/archivelog/1_4_787309225.dbf thread=1 sequence=4
archived log file name=/oracle/archivelog/1_5_787309225.dbf thread=1 sequence=5
archived log file name=/oracle/archivelog/1_6_787309225.dbf thread=1 sequence=6
archived log file name=/oracle/archivelog/1_7_787309225.dbf thread=1 sequence=7
archived log file name=+DGASM/ora11/onlinelog/group_2.264.785192615 thread=1 sequence=8
archived log file name=+DGASM/ora11/onlinelog/group_3.265.785192859 thread=1 sequence=9
archived log file name=+DGASM/ora11/onlinelog/group_1.263.785192081 thread=1 sequence=10
media recovery complete, elapsed time: 00:00:02
Finished recover at 30-JUN-12
RMAN>
從上面的恢復過程可以看到,應用了所有的日誌,包括線上日誌,歸檔日誌到sequence9,但是恢復sequence 到10。
10作為當前日誌。
8、以resetlogs 方式開啟資料庫
9、檢查使用者和表,資料都存在。
總結:rman 自動以datafile 為基準,應用所有歸檔日誌檔案,包括線上日誌檔案,完成不完全恢復。oracle 不知道恢復的終點,
      有多少日誌,應用多少日誌,日誌都存在的情況下,資料沒有丟失。在這個過程中沒有讓dba參與。
      v$log 中的內容來自控制檔案。
    

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7755871/viewspace-776377/,如需轉載,請註明出處,否則將追究法律責任。

相關文章