oracle data guard備庫備份恢復
阿新 • • 發佈:2017-10-18
startup ring pset 文件拷貝 style pga patch physical size
客戶有套data guard環境,主庫在阿裏雲上,備庫在本地機房,現在想定期做備份,但是因為一些原因,備份阿裏雲上的主庫實現會有些問題,所以只能備份本地的備庫。目前需求就是測試備庫的備份文件是否可以進行恢復,當誤刪除等操作之後,能否通過備份找回數據。以下為具體的測試:
1. 在data guard的備庫進行完整+歸檔的備份
RMAN> run { 2> allocate channel t1 type disk; 3> allocate channel t2 type disk; 4> allocate channel t3 type disk; 5> allocate channel t4 type disk; 6> backup as compressed backupset INCREMENTAL LEVEL 0 FORMAT ‘/u01/app/oracle/racdb_data_%T_%s‘ database; 7> backup format ‘/u01/app/oracle/racdb_arch_%T_%s‘ skip inaccessible archivelog ALL not backed up; 8> backup format ‘/u01/app/oracle/racdb_cont_%T_%s‘ current controlfile; 9> release channel t1;10> release channel t2; 11> release channel t3; 12> release channel t4; 13> }
2. 將文件拷貝到測試庫上
[oracle@dg1 oracle]$ scp racdb_* 192.168.100.100:/u01/app/oracle/ oracle@192.168.100.100‘s password: racdb_arch_20171018_24 100% 3646KB 3.6MB/s 00:00 racdb_arch_20171018_25 100% 30MB 30.1MB/s 00:01 racdb_arch_20171018_26 100% 2995KB 2.9MB/s 00:00 racdb_arch_20171018_27 100% 59MB 59.2MB/s 00:01 racdb_arch_20171018_28 100% 21MB 20.9MB/s 00:00 racdb_cont_20171018_29 100% 9856KB 9.6MB/s 00:00 racdb_data_20171018_19 100% 194MB 48.6MB/s 00:04 racdb_data_20171018_20 100% 77MB 77.0MB/s 00:01 racdb_data_20171018_21 100% 30MB 30.2MB/s 00:01 racdb_data_20171018_22 100% 1104KB 1.1MB/s 00:00 racdb_data_20171018_23 100% 96KB 96.0KB/s 00:00
3. 在主庫上生成pfile文件,並拷貝到測試庫上
SQL> create pfile=‘/home/oracle/pfileabbott‘ from spfile; File created. [oracle@dg1 ~]$ scp pfileabbott 192.168.100.100:/home/oracle oracle@192.168.100.100‘s password: pfileabbott 100% 1375 1.3KB/s 00:00
4. 在測試庫上修改參數文件
[oracle@Abbott ~]$ mv pfileabbott $ORACLE_HOME/dbs/initabbott.ora [oracle@Abbott ~]$ cd $ORACLE_HOME/dbs [oracle@Abbott dbs]$ export ORACLE_SID=abbott [oracle@Abbott dbs]$ vi initabbott.ora *.audit_file_dest=‘/u01/app/oracle/admin/abbott/adump‘ *.audit_trail=‘db‘ *.compatible=‘11.2.0.4.0‘ *.control_files=‘/u01/app/oracle/oradata/abbott/control01.ctl‘,‘/u01/app/oracle/fast_recovery_area/abbott/control02.ctl‘ *.db_block_size=8192 *.db_domain=‘‘ *.db_name=‘abbott‘ *.db_recovery_file_dest=‘/u01/app/oracle/fast_recovery_area‘ *.db_recovery_file_dest_size=4385144832 *.diagnostic_dest=‘/u01/app/oracle‘ *.dispatchers=‘(PROTOCOL=TCP) (SERVICE=abbottXDB)‘ *.log_archive_dest_1=‘LOCATION=/u01/app/oracle/archivelog‘ *.log_archive_format=‘%t_%s_%r.arc‘ *.log_archive_max_processes=30 *.open_cursors=300 *.pga_aggregate_target=655360000 *.processes=150 *.remote_login_passwordfile=‘EXCLUSIVE‘ *.sga_target=1967128576 *.standby_file_management=‘AUTO‘ *.undo_tablespace=‘UNDOTBS1‘
5. 測試庫開啟到nomount
[oracle@Abbott dbs]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Tue Oct 17 08:24:18 2017 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to an idle instance. SQL> startup nomount; ORACLE instance started. Total System Global Area 1970864128 bytes Fixed Size 2254544 bytes Variable Size 520096048 bytes Database Buffers 1442840576 bytes Redo Buffers 5672960 bytes SQL>
6. 恢復控制文件
[oracle@Abbott ~]$ rman target / Recovery Manager: Release 11.2.0.4.0 - Production on Tue Oct 17 09:29:20 2017 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database: ABBOTT (not mounted) RMAN> restore controlfile from ‘/u01/app/oracle/racdb_cont_20171018_29‘; Starting restore at 17-OCT-17 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=134 device type=DISK channel ORA_DISK_1: restoring control file channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 output file name=/u01/app/oracle/oradata/abbott/control01.ctl output file name=/u01/app/oracle/fast_recovery_area/abbott/control02.ctl Finished restore at 17-OCT-17 RMAN> alter database mount; database mounted released channel: ORA_DISK_1
7. 恢復數據文件
RMAN> restore database; Starting restore at 17-OCT-17 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=150 device type=DISK channel ORA_DISK_1: starting datafile backup set restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/abbott/undotbs01.dbf channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/abbott/example01.dbf channel ORA_DISK_1: reading from backup piece /u01/app/oracle/racdb_data_20171018_21 channel ORA_DISK_1: piece handle=/u01/app/oracle/racdb_data_20171018_21 tag=TAG20171018T153509 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:00:15 channel ORA_DISK_1: starting datafile backup set restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/abbott/sysaux01.dbf channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/abbott/users01.dbf channel ORA_DISK_1: reading from backup piece /u01/app/oracle/racdb_data_20171018_20 channel ORA_DISK_1: piece handle=/u01/app/oracle/racdb_data_20171018_20 tag=TAG20171018T153509 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:00:25 channel ORA_DISK_1: starting datafile backup set restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/abbott/system01.dbf channel ORA_DISK_1: reading from backup piece /u01/app/oracle/racdb_data_20171018_19 channel ORA_DISK_1: piece handle=/u01/app/oracle/racdb_data_20171018_19 tag=TAG20171018T153509 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:00:45 Finished restore at 17-OCT-17
8. 恢復數據庫
RMAN> recover database; Starting recover at 17-OCT-17 using channel ORA_DISK_1 starting media recovery channel ORA_DISK_1: starting archived log restore to default destination channel ORA_DISK_1: restoring archived log archived log thread=1 sequence=196 channel ORA_DISK_1: reading from backup piece /u01/app/oracle/racdb_arch_20171018_28 channel ORA_DISK_1: piece handle=/u01/app/oracle/racdb_arch_20171018_28 tag=TAG20171018T153550 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 archived log file name=/u01/app/oracle/archivelog1_196_953375126.arc thread=1 sequence=196 unable to find archived log archived log thread=1 sequence=197 RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of recover command at 10/17/2017 09:33:30 RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 197 and starting SCN of 1907246
9. 將數據庫open
RMAN> alter database open; database opened RMAN> quit Recovery Manager complete.
10. 連接數據庫後,無法創建表等,因為控制文件是standby controlfile,所以打開的模式為READ ONLY
[oracle@Abbott ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Tue Oct 17 09:41:46 2017 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> create table t1(a int); create table t1(a int) * ERROR at line 1: ORA-00604: error occurred at recursive SQL level 1 ORA-16000: database open for read-only access SQL> select open_mode , database_role, flashback_on from v$database; OPEN_MODE DATABASE_ROLE FLASHBACK_ON -------------------- ---------------- ------------------ READ ONLY PHYSICAL STANDBY NO
11. 嘗試啟用備庫,因缺少standby log報錯
SQL> alter database activate standby database; alter database activate standby database * ERROR at line 1: ORA-00314: log 4 of thread 1, expected sequence# 197 doesn‘t match 0 ORA-00312: online log 4 thread 1: ‘/u01/app/oracle/oradata/abbott/std_log4.log‘ SQL> select * from v$standby_log; select * from v$standby_log * ERROR at line 1: ORA-00339: archived log does not contain any redo ORA-00334: archived log: ‘/u01/app/oracle/oradata/abbott/std_log4.log‘
12. 因此對缺少的log進行clear及drop(當然,這裏也可以把standby redo拷貝過來,並進行open)
SQL> alter database drop logfile group 4; alter database drop logfile group 4 * ERROR at line 1: ORA-00314: log 4 of thread 1, expected sequence# 197 doesn‘t match 0 ORA-00312: online log 4 thread 1: ‘/u01/app/oracle/oradata/abbott/std_log4.log‘ SQL> ALTER DATABASE CLEAR LOGFILE GROUP 4; Database altered. SQL> alter database drop logfile group 4; Database altered.
13. 再次arctive備庫,啟動正常,並且open之後可讀寫
SQL> alter database activate standby database; Database altered. SQL> select open_mode , database_role, flashback_on from v$database; OPEN_MODE DATABASE_ROLE FLASHBACK_ON -------------------- ---------------- ------------------ MOUNTED PRIMARY NO SQL> alter database open; Database altered. SQL> select open_mode , database_role, flashback_on from v$database; OPEN_MODE DATABASE_ROLE FLASHBACK_ON -------------------- ---------------- ------------------ READ WRITE PRIMARY NO SQL> create table t1(a int); Table created. SQL> SQL> archive log list; Database log mode Archive Mode Automatic archival Enabled Archive destination /u01/app/oracle/archivelog Oldest online log sequence 1 Next log sequence to archive 1 Current log sequence 1 SQL>
oracle data guard備庫備份恢復