rman恢复数据库--用备份的控制文件


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 中的内容来自控制文件。

相关内容