dataguard环境破坏后采用rman备份集重新部署
1. 环境
主库: 192.168.1.118
备库: 192.168.1.85
OS: Centos7
DB: 11.2.0.4
前提条件:dataguard之前已经搭建好,从库的spfile和密码文件不需要创建,主库的数据文件目录在从库必须存在,这里的场景是主库的数据文件目录和从库的数据文件目录需要保持一致.
2. 主库备份
run{ allocate channel ch1 device type disk; backup as compressed backupset format '/home/oracle/rman_backup/df_t%t_s%s_p%p' database; sql 'alter system archive log current'; backup as compressed backupset format '/home/oracle/rman_backup/archive_log_t%t_s%s_p%p' archivelog all; backup current controlfile for standby format '/home/oracle/rman_backup/ctl_for_std.bak' tag 'std controlfile'; release channel ch1; } |
3.备份集拷贝到从库
scp ctl_for_std.bak oracle@192.168.1.85:/tmp/rman_bak scp df_t1026569938_s769_p1 oracle@192.168.1.85:/tmp/rman_bak scp df_t1026570043_s770_p1 oracle@192.168.1.85:/tmp/rman_bak |
4. 关闭从库
先查出原来从库的数据库的数据文件路径,等下我们要删除这些文件
SQL> set linesize 1000; SQL> Select file#,Name From v$datafile; FILE# NAME ---------- ------------------------------------------------------------ 1 /u01/app/oracle/oradata/slnngkdg/system01.dbf 2 /u01/app/oracle/oradata/slnngkdg/sysaux01.dbf 3 /u01/app/oracle/oradata/slnngkdg/undotbs01.dbf 4 /u01/app/oracle/oradata/slnngkdg/users01.dbf 5 /u01/app/oracle/oradata/slnngkdg/tps_data01.dbf 6 /u01/app/oracle/oradata/slnngkdg/mrkt.dbf 7 /u01/app/oracle/oradata/slnngkdg/tps_data02.dbf 8 /u01/app/oracle/oradata/tps_data02.dbf 9 /u01/app/oracle/oradata/slnngkdg/tps_data04.dbf 10 /u01/app/oracle/oradata/tps_data05.dbf 11 /u01/app/oracle/oradata/tps_data06.dbf 12 /u01/app/oracle/oradata/tps_data07.dbf 13 /u01/app/oracle/oradata/tps_data08.dbf 14 /u02/oradata/tps_data09.dbf 15 /u02/oradata/tps_data10.dbf 16 /u01/app/oracle/oradata/tps_data11.dbf 17 /u02/oradata/tps_data12.dbf 18 /u01/app/oracle/oradata/slnngkdg/tps_data13.dbf 19 /u01/app/oracle/oradata/tps_data14.dbf 19 rows selected. |
SQL>shutdown immediate
5. 删除从库的相应数据文件
rm /u01/app/oracle/oradata/*
rm /u02/oradata/*
rm /u01/app/oracle/oradata/slnngkdg/*
注意这里控制文件不需要删除
或是采用dbca进行删除
dbca -silent -deleteDatabase -sourcedb slnngkdg -sid slnngkdg
6. 从库恢复控制文件(系统根据控制文件参数指定的目录复制多份)
RMAN>startup nomount;
RMAN>restore standby controlfile from '/tmp/rman_bak/ctl_for_std.bak';
RMAN>alter database mount;
RMAN> restore standby controlfile from '/tmp/rman_bak/ctl_for_std.bak';
Starting restore at 27-AUG-20
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 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/slnngkdg/control01.ctl
output file name=/u01/app/oracle/oradata/slnngkdg/control02.ctl
output file name=/u01/app/oracle/oradata/slnngkdg/control03.ctl
Finished restore at 27-AUG-20
或是具体指定路径
restore standby controlfile to '/u01/app/oracle/oradata/slnngkdg/control01.ctl' from '/u01/app/rmanbak/ctl_for_std.bak';
restore standby controlfile to '/u01/app/oracle/oradata/slnngkdg/control02.ctl' from '/u01/app/rmanbak/ctl_for_std.bak';
restore standby controlfile to '/u01/app/oracle/oradata/slnngkdg/control03.ctl' from '/u01/app/rmanbak/ctl_for_std.bak';
7.从库注册主库拷贝过来的备份集
RMAN> catalog start with '/tmp/rman_bak';
8. 备库恢复
RMAN>restore database;
9.添加standby日志组
SQL> select group#,bytes from v$log; GROUP# BYTES ---------- ---------- 1 52428800 2 52428800 3 52428800 |
日志组序号从4开始,大小跟redo log保持一致
SQL> alter database add standby logfile group 4 '/u01/app/oracle/oradata/slnngkdg/standby_redo01.log' size 50m reuse; SQL> alter database add standby logfile group 5 '/u01/app/oracle/oradata/slnngkdg/standby_redo02.log' size 50m reuse; SQL> alter database add standby logfile group 6 '/u01/app/oracle/oradata/slnngkdg/standby_redo03.log' size 50m reuse; |
10.日志应用
alter database recover managed standby database using current logfile disconnect from session;
11.打开数据库
应用日志
alter database recover managed standby database using current logfile disconnect from session;
等日志应用同步完成后退出日志应用,然后打开数据库,否则打开数据库的时候也会先应用日志,等日志应用追上来了后才能打开数据库
alter database recover managed standby database cancel;
alter database open;
然后启用日志应用
alter database recover managed standby database using current logfile disconnect from session;
12.online redo和temp文件不需要创建
打开数据库的时候,日志信息会有如下的输出: