前期参数设置部分忽略,可参考其它文章介绍。
1、从主库创建备库控制文件备份
backup current controlfile for standby format '/home/oracle/standby_controlfile.bak';
2、备份主库
run
{
allocate channel ch1 type disk;
allocate channel ch2 type disk;
allocate channel ch3 type disk;
allocate channel ch4 type disk;
backup database format '/home/oracle/DB0_%U.bak';
release channel ch1;
release channel ch2;
release channel ch3;
release channel ch4;
}
3、传输备份集到备库
scp xxxxxx.bak xxxxxx.bak oracle@xxx.xxx.xxx.xxx:/home/oracle/backup/
4、备库启动到umount状态
startup nomount
5、恢复备库控制文件
restore standby controlfile from '/home/oracle/xxxxxx.bak';
6、启动到mount状态
alter database mount;
7、注册备份集到控制文件
catalog start with '/home/oracle/backup/';
8、批量生成set newname语句
select 'set newname for datafile '||file#||' to ''/u01/app/oracle/oradata/orcl/'||substr(name,21,100)||''';' from v$datafile;
select 'set newname for tempfile '||file#||' to ''/u01/app/oracle/oradata/orcl/'||substr(name,21,100)||''';' from v$tempfile;
9、全库恢复
run
{
allocate channel ch1 type disk;
allocate channel ch2 type disk;
allocate channel ch3 type disk;
allocate channel ch4 type disk;
set newname for datafile 1 to '/u01/app/oracle/oradata/orclstd/system01.dbf';
set newname for datafile 2 to '/u01/app/oracle/oradata/orclstd/sysaux01.dbf';
set newname for datafile 3 to '/u01/app/oracle/oradata/orclstd/undotbs01.dbf';
set newname for datafile 4 to '/u01/app/oracle/oradata/orclstd/user01.dbf';
set newname for datafile 5 to '/u01/app/oracle/oradata/orclstd/test.dbf';
set newname for datafile 6 to '/u01/app/oracle/oradata/orclstd/testdg.dbf';
set newname for datafile 7 to '/u01/app/oracle/oradata/orclstd/testdg01.dbf';
set newname for datafile 8 to '/u01/app/oracle/oradata/orclstd/test02.dbf';
set newname for datafile 9 to '/u01/app/oracle/oradata/orclstd/testdg03.dbf';
restore database;
switch datafile all;
release channel ch1;
release channel ch2;
release channel ch3;
release channel ch4;
}
10、追加归档
recover database;
11、启用实时应用
alter database recover managed standby database using current logfile disconnect from session;
12、关闭实时应用
alter database recover managed standby database cancel;
13、打开数据库
alter database open;
14、开启实时应用
alter database recover managed standby database using current logfile disconnect from session;