全部博文(389)
分类: Oracle
2016-03-26 11:29:18
Oracle Physical Dataguard环境使用RMAN备份和恢复
由于Physical Dataguard使用的是块恢复技术来保持和PRIMARY的一致性,因此可以在STANDBY
上进行rman备份,从而减轻PRIMARY的压力.当PRIMARY出现数据库故障时,可以使用在STANDBY上
的备份来进行恢复.
先决条件:需要配置catalog.
在PRIMARY上以catalog方式连接,并且注册数据库
[oracle@PRIMARY admin]$ $ORACLE_HOME/bin/rman target / catalog
> register database;
database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
RMAN> configure db_unique_name CP connect identifier 'cp';
new RMAN configuration parameters:
CONFIGURE DB_UNIQUE_NAME 'cp' CONNECT IDENTIFIER 'cp';
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete
RMAN> configure db_unique_name cepstby connect identifier 'cepstby';
new RMAN configuration parameters:
CONFIGURE DB_UNIQUE_NAME 'cepstby' CONNECT IDENTIFIER 'cepstby';
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete
查看已注册的数据库信息,rman自动识别数据库角色等信息.
RMAN> list db_unique_name of database;
List of Databases
DB Key DB Name DB ID Database Role Db_unique_name
------- ------- ----------------- --------------- ------------------
1 CP 2894644313 PRIMARY CP
1 CP 2894644313 STANDBY CEPSTBY
rman 连接到STANDBY的target进行备份
[oracle@standby ~]$ $ORACLE_HOME/bin/rman target / catalog
Manager: Release 11.1.0.7.0 - Production on Sat Mar 26 10:52:00 2016
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: CP (DBID=2894644313, not open)
connected to recovery catalog database
在standby上执行备份操作.
RMAN> run
2> {
3> allocate channel c2 device type disk;
4> backup as backupset database format '/home/oracle/%U';
5> release channel c2;
6> }
allocated channel: c2
channel c2: SID=1085 device type=DISK
Starting backup at 26-MAR-16
Starting implicit crosscheck backup at 26-MAR-16
Finished implicit crosscheck backup at 26-MAR-16
.............................
我们通过在主库移动文件来摸拟数据文件被破坏的情形
[oracle@primary]$ mv /u01/app/oracle/oradata/cp/users01.dbf /u01/app/oracle/oradata/cp/oldusers01.dbf
DONGDONGTANG> startup;
ORACLE instance started.
Total System Global Area 1135747072 bytes
Fixed Size 2158992 bytes
Variable Size 822087280 bytes
Database Buffers 301989888 bytes
Redo Buffers 9510912 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/cp/users01.dbf'
接下来我们要做的是从备库上复制相关备份文件到主库中
[oracle@standby ~]$ scp /home/oracle/0* 192.168.56.21:/home/oracle/bak
在主库中对相关文件进行catalog
[oracle@PRIMARY admin]$ $ORACLE_HOME/bin/rman target / catalog
Manager: Release 11.1.0.7.0 - Production on Sat Mar 26 10:56:56 2016
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: CP (DBID=2894644313, not open)
connected to recovery catalog database
RMAN> catalog start with '/home/oracle/bak';
searching for all files that match the pattern /home/oracle/bak
List of Files Unknown to the Database
=====================================
File Name: /home/oracle/bak/09r1eku6_1_1
File Name: /home/oracle/bak/08r1ekse_1_1
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /home/oracle/bak/09r1eku6_1_1
File Name: /home/oracle/bak/08r1ekse_1_1
现在可以发现4号文件的相关备份信息
RMAN> list backup of datafile 4;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
111 Full 1.08G DISK 00:00:53 26-MAR-16
BP Key: 176 Status: AVAILABLE Compressed: NO Tag: TAG20160326T105302
PRIMARYece Name: /home/oracle/bak/08r1ekse_1_1
List of Datafiles in backup set 111
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
4 Full 927757 26-MAR-16 /u01/app/oracle/oradata/cp/users01.dbf
恢复/u01/app/oracle/oradata/cp/users01.dbf文件
RMAN> run
{
allocate channel c1 device type disk;
restore datafile 4;
recover datafile 4;
release channel c1;
}2> 3> 4> 5> 6> 7>
allocated channel: c1
channel c1: SID=1090 device type=DISK
Starting restore at 26-MAR-16
channel c1: starting datafile backup set restore
channel c1: specifying datafile(s) to restore from backup set
channel c1: restoring datafile 00004 to /u01/app/oracle/oradata/cp/users01.dbf
channel c1: reading from backup PRIMARYece /home/oracle/bak/08r1ekse_1_1
channel c1: PRIMARYece handle=/home/oracle/bak/08r1ekse_1_1 tag=TAG20160326T105302
channel c1: restored backup PRIMARYece 1
channel c1: restore complete, elapsed time: 00:00:03
Finished restore at 26-MAR-16
Starting recover at 26-MAR-16
starting media recovery
media recovery complete, elapsed time: 00:00:01
Finished recover at 26-MAR-16
released channel: c1
再次尝试打开数据库.
....................
Variable Size 822087280 bytes
Database Buffers 301989888 bytes
Redo Buffers 9510912 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/cp/users01.dbf'
DONGDONGTANG> alter database open;
Database altered.
DONGDONGTANG> select name,status from v$datafile where file#=4;
NAME
--------------------------------------------------------------------------------
STATUS
-------
/u01/app/oracle/oradata/cp/users01.dbf
ONLINE
主数据库已经可以成功打开.