Dataguard环境下的备份与恢复

2018-01-05 10:30:31来源:oschina作者:rootliu人点击

分享
Dataguard环境下的备份与恢复

原创 ylw6006 2012-10-29 14:02:06 评论(0) 2312人阅读


在部署完active data guard后,不但可以将只读的查询交给备库执行,还可以把日常的数据库备份工作放在备库上执行,从而减轻主库的压力,充分的发挥服务器资源,下面演示下利用备库备份来还原主库数据的过程!


一:主库上创建表空间,并在表空间上建表,插入测试数据,同时检查备库的同步情况


SQL> create tablespace test01 datafile '/u01/app/oracle/oradata/db1/test01.dbf' size 10M; Tablespace created.
SQL>createtablermantablespacetest01asselectobject_id,object_namefromdba_objects;
Tablecreated. SQL>selectcount(*)fromrman; COUNT(*)
----------
76379 [oracle@db2db1]$sqlplus/nolog
SQL*Plus:Release11.2.0.3.0ProductiononMonOct2911:37:382012
Copyright(c)1982,2011,Oracle.Allrightsreserved. SQL>conn/assysdba
Connected.
SQL>selectcount(*)fromrman; COUNT(*)
----------
76379

二:在备库上使用rman对新建的表空间test01进行备份


[oracle@db2db1]$rmantarget/
RecoveryManager:Release11.2.0.3.0-ProductiononMonOct2911:38:012012
Copyright(c)1982,2011,Oracleand/oritsaffiliates.Allrightsreserved.
connectedtotargetdatabase:DB1(DBID=1387827106) RMAN>reportschema; RMAN>backuptablespacetest01format'/home/oracle/test01_%U'; Startingbackupat2012-10-29-11:38:50
allocatedchannel:ORA_DISK_1
channelORA_DISK_1:SID=1devicetype=DISK
channelORA_DISK_1:startingfulldatafilebackupset
channelORA_DISK_1:specifyingdatafile(s)inbackupset
inputdatafilefilenumber=00034name=/u01/app/oracle/oradata/db1/test01.dbf
channelORA_DISK_1:startingpiece1at2012-10-29-11:38:51
channelORA_DISK_1:finishedpiece1at2012-10-29-11:38:52
piecehandle=/home/oracle/test01_03novc2b_1_1tag=TAG20121029T113851comment=NONE
channelORA_DISK_1:backupsetcomplete,elapsedtime:00:00:01
Finishedbackupat2012-10-29-11:38:52

三:关闭主库后删除表空间数据文件,模拟数据丢失场景


[oracle@db1~]$sqlplus/nolog
SQL*Plus:Release11.2.0.3.0ProductiononMonOct2911:39:492012
Copyright(c)1982,2011,Oracle.Allrightsreserved. SQL>conn/assysdba
Connected.
SQL>shutdownimmediate
Databaseclosed.
Databasedismounted.
ORACLEinstanceshutdown.
SQL>exit [oracle@db1~]$rm-rf/u01/app/oracle/oradata/db1/test01.dbf

四:重新启动主库,只能启动到mount状态


[oracle@db1~]$sqlplus/nolog
SQL*Plus:Release11.2.0.3.0ProductiononMonOct2911:41:422012
Copyright(c)1982,2011,Oracle.Allrightsreserved.
SQL>conn/assysdba
Connectedtoanidleinstance.
SQL>startup
ORACLEinstancestarted. TotalSystemGlobalArea1536602112bytes
FixedSize2228624bytes
VariableSize1174408816bytes
DatabaseBuffers352321536bytes
RedoBuffers7643136bytes
Databasemounted.
ORA-01157:cannotidentify/lockdatafile34-seeDBWRtracefile
ORA-01110:datafile34:'/u01/app/oracle/oradata/db1/test01.dbf' SQL>selectopen_mode,database_rolefromv$database; OPEN_MODEDATABASE_ROLE
------------------------------------
MOUNTEDPRIMARY

五:将备库的备份数据复制到主库,并使用catalog命令注册到主库的控制文件中


[oracle@db2~]$scptest01_03novc2b_1_1db1:/home/oracle/
[oracle@db1~]$rmantarget/
RecoveryManager:Release11.2.0.3.0-ProductiononMonOct2911:45:022012
Copyright(c)1982,2011,Oracleand/oritsaffiliates.Allrightsreserved.
connectedtotargetdatabase:DB1(DBID=1387827106,notopen) RMAN>listbackupoftablespacetest01;
specificationdoesnotmatchanybackupintherepository RMAN>catalogbackuppiece'/home/oracle/test01_03novc2b_1_1'; catalogedbackuppiece
backuppiecehandle=/home/oracle/test01_03novc2b_1_1RECID=42STAMP=797946436RMAN>listbackupoftablespacetest01; ListofBackupSets
=================== BSKeyTypeLVSizeDeviceTypeElapsedTimeCompletionTime
-----------------------------------------------------------------
42Full3.98MDISK00:00:002012-10-29-11:38:51
BPKey:42Status:AVAILABLECompressed:NOTag:TAG20121029T113851
PieceName:/home/oracle/test01_03novc2b_1_1
ListofDatafilesinbackupset42
FileLVTypeCkpSCNCkpTimeName
-------------------------------------------
34Full103504652012-10-29-11:35:32/u01/app/oracle/oradata/db1/test01.dbf

六:还原和恢复表空间test01,并将主库启动到读写状态,测试主备库数据实时同步情况


RMAN>restoretablespacetest01;
Startingrestoreat2012-10-29-11:47:50
allocatedchannel:ORA_DISK_1
channelORA_DISK_1:SID=21devicetype=DISKchannelORA_DISK_1:startingdatafilebackupsetrestore
channelORA_DISK_1:specifyingdatafile(s)torestorefrombackupset
channelORA_DISK_1:restoringdatafile00034to/u01/app/oracle/oradata/db1/test01.dbf
channelORA_DISK_1:readingfrombackuppiece/home/oracle/test01_03novc2b_1_1
channelORA_DISK_1:piecehandle=/home/oracle/test01_03novc2b_1_1tag=TAG20121029T113851
channelORA_DISK_1:restoredbackuppiece1
channelORA_DISK_1:restorecomplete,elapsedtime:00:00:01
Finishedrestoreat2012-10-29-11:47:52 RMAN>recovertablespacetest01;
Startingrecoverat2012-10-29-11:48:02
usingchannelORA_DISK_1 startingmediarecovery
mediarecoverycomplete,elapsedtime:00:00:01 Finishedrecoverat2012-10-29-11:48:03 RMAN>alterdatabaseopen;
databaseopened [oracle@db1~]$sqlplus/nolog
SQL*Plus:Release11.2.0.3.0ProductiononMonOct2911:48:472012
Copyright(c)1982,2011,Oracle.Allrightsreserved. SQL>conn/assysdba
Connected.
SQL>truncatetablerman;
Tabletruncated. [oracle@db2~]$sqlplus/nolog
SQL*Plus:Release11.2.0.3.0ProductiononMonOct2911:49:122012
Copyright(c)1982,2011,Oracle.Allrightsreserved. SQL>conn/assysdba
Connected.
SQL>selectcount(*)fromrman; COUNT(*)
----------
0

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台