Dataguard环境下的备份与恢复

Dataguard环境下的备份与恢复

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

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

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

  1. SQL> create tablespace test01 datafile '/u01/app/oracle/oradata/db1/test01.dbf' size 10M;
    Tablespace created.

  2. SQL> create table rman tablespace test01 as select object_id,object_name from dba_objects;  

  3. Table created.  

  4. SQL> select count(*) from rman;  

  5.   COUNT(*)  

  6. ----------  

  7.      76379  

  8. [oracle@db2 db1]$ sqlplus  /nolog  

  9. SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 29 11:37:38 2012  

  10. Copyright (c) 1982, 2011, Oracle.  All rights reserved.  

  11. SQL> conn /as sysdba  

  12. Connected.  

  13. SQL> select count(*) from rman;  

  14.   COUNT(*)  

  15. ----------  

  16.      76379

 

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

  1. [oracle@db2 db1]$ rman target /  

  2. Recovery Manager: Release 11.2.0.3.0 - Production on Mon Oct 29 11:38:01 2012  

  3. Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.  

  4. connected to target database: DB1 (DBID=1387827106)  

  5. RMAN> report schema;  

  6. RMAN> backup tablespace test01 format '/home/oracle/test01_%U';  

  7. Starting backup at 2012-10-29-11:38:50  

  8. allocated channel: ORA_DISK_1  

  9. channel ORA_DISK_1: SID=1 device type=DISK 

  10. channel ORA_DISK_1: starting full datafile backup set  

  11. channel ORA_DISK_1: specifying datafile(s) in backup set  

  12. input datafile file number=00034 name=/u01/app/oracle/oradata/db1/test01.dbf  

  13. channel ORA_DISK_1: starting piece 1 at 2012-10-29-11:38:51  

  14. channel ORA_DISK_1: finished piece 1 at 2012-10-29-11:38:52  

  15. piece handle=/home/oracle/test01_03novc2b_1_1 tag=TAG20121029T113851 comment=NONE 

  16. channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01  

  17. Finished backup at 2012-10-29-11:38:52

 

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

  1. [oracle@db1 ~]$ sqlplus /nolog  

  2. SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 29 11:39:49 2012  

  3. Copyright (c) 1982, 2011, Oracle.  All rights reserved.  

  4. SQL> conn /as sysdba  

  5. Connected.  

  6. SQL> shutdown immediate  

  7. Database closed.  

  8. Database dismounted.  

  9. ORACLE instance shut down.  

  10. SQL> exit  

  11. [oracle@db1 ~]$ rm -rf /u01/app/oracle/oradata/db1/test01.dbf

  

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

  1. [oracle@db1 ~]$ sqlplus  /nolog  

  2. SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 29 11:41:42 2012  

  3. Copyright (c) 1982, 2011, Oracle.  All rights reserved.  

  4. SQL> conn /as sysdba  

  5. Connected to an idle instance.  

  6. SQL> startup  

  7. ORACLE instance started.  

  8. Total System Global Area 1536602112 bytes  

  9. Fixed Size                  2228624 bytes  

  10. Variable Size            1174408816 bytes  

  11. Database Buffers          352321536 bytes  

  12. Redo Buffers                7643136 bytes  

  13. Database mounted.  

  14. ORA-01157: cannot identify/lock data file 34 - see DBWR trace file  

  15. ORA-01110: data file 34: '/u01/app/oracle/oradata/db1/test01.dbf'  

  16. SQL> select open_mode,database_role from v$database;  

  17. OPEN_MODE            DATABASE_ROLE  

  18. -------------------- ----------------  

  19. MOUNTED              PRIMARY

 

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

  1. [oracle@db2 ~]$ scp test01_03novc2b_1_1 db1:/home/oracle/  

  2. [oracle@db1 ~]$ rman target /  

  3. Recovery Manager: Release 11.2.0.3.0 - Production on Mon Oct 29 11:45:02 2012  

  4. Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.  

  5. connected to target database: DB1 (DBID=1387827106, not open)  

  6. RMAN> list backup of tablespace test01;  

  7. specification does not match any backup in the repository  

  8. RMAN>  catalog backuppiece '/home/oracle/test01_03novc2b_1_1';  

  9. cataloged backup piece  

  10. backup piece handle=/home/oracle/test01_03novc2b_1_1 RECID=42 STAMP=797946436 

  11. RMAN> list backup of tablespace test01;  

  12. List of Backup Sets 

  13. ===================  

  14. BS Key  Type LV Size       Device Type Elapsed Time Completion Time      

  15. ------- ---- -- ---------- ----------- ------------ -------------------  

  16. 42      Full    3.98M      DISK        00:00:00     2012-10-29-11:38:51  

  17.         BP Key: 42   Status: AVAILABLE  Compressed: NO  Tag: TAG20121029T113851  

  18.         Piece Name: /home/oracle/test01_03novc2b_1_1  

  19.   List of Datafiles in backup set 42  

  20.   File LV Type Ckp SCN    Ckp Time            Name  

  21.   ---- -- ---- ---------- ------------------- ----  

  22.   34      Full 10350465   2012-10-29-11:35:32 /u01/app/oracle/oradata/db1/test01.dbf

 

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

  1. RMAN> restore tablespace test01;  

  2. Starting restore at 2012-10-29-11:47:50  

  3. allocated channel: ORA_DISK_1  

  4. channel ORA_DISK_1: SID=21 device type=DISK 

  5. channel ORA_DISK_1: starting datafile backup set restore  

  6. channel ORA_DISK_1: specifying datafile(s) to restore from backup set  

  7. channel ORA_DISK_1: restoring datafile 00034 to /u01/app/oracle/oradata/db1/test01.dbf  

  8. channel ORA_DISK_1: reading from backup piece /home/oracle/test01_03novc2b_1_1  

  9. channel ORA_DISK_1: piece handle=/home/oracle/test01_03novc2b_1_1 tag=TAG20121029T113851 

  10. channel ORA_DISK_1: restored backup piece 1  

  11. channel ORA_DISK_1: restore complete, elapsed time: 00:00:01  

  12. Finished restore at 2012-10-29-11:47:52  

  13. RMAN> recover tablespace test01;  

  14. Starting recover at 2012-10-29-11:48:02  

  15. using channel ORA_DISK_1  

  16. starting media recovery  

  17. media recovery complete, elapsed time: 00:00:01  

  18. Finished recover at 2012-10-29-11:48:03  

  19. RMAN> alter database open;  

  20. database opened  

  21. [oracle@db1 ~]$ sqlplus  /nolog  

  22. SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 29 11:48:47 2012  

  23. Copyright (c) 1982, 2011, Oracle.  All rights reserved.  

  24. SQL> conn /as sysdba  

  25. Connected.  

  26. SQL> truncate table rman;  

  27. Table truncated.  

  28. [oracle@db2 ~]$ sqlplus  /nolog  

  29. SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 29 11:49:12 2012  

  30. Copyright (c) 1982, 2011, Oracle.  All rights reserved.  

  31. SQL> conn /as sysdba  

  32. Connected.  

  33. SQL> select count(*) from rman;  

  34.   COUNT(*)  

  35. ----------  

  36.          0

评论

暂无评论