Oracle DG基于SCN的增量备份与恢复

说明:本文为Oracle DG中使用RMAN进行基于SCN的增量备份与恢复指导手册
标签:基于SCN的增量备份于恢复、DG备库恢复、DG断档恢复、Rman备份恢复
基础环境:对于DG(Oracle DATAGUARD)的安装配置本文不再指导,用户可以自行搜索相关文章
温馨提示:如果您发现本文哪里写的有问题或者有更好的写法请留言或私信我进行修改优化

※ 实验环境
系统  :Linux 6.4
Oracle:11.2.0.3 单实例
源端  :IP:1.1.1.7 DB_NAME:orcl SERVICE_NAME:orcl
目标端:IP:1.1.1.8 DB_NAME:orcl SERVICE_NAME:bei


※ 创建临时目录
su - oracle
mkdir -p /home/oracle/zzt/


※ 备库停止应用
rlwrap sqlplus / as sysdba
SQL> alter database recover managed standby database cancel;


※ 主库产生事务操作
rlwrap sqlplus / as sysdba
SQL> set line 170
SQL> set pages 200
SQL> select * from scott.emp where empno=7788;
SQL> update scott.emp set sal=sal+1;
SQL> commit;
SQL> select * from scott.emp where empno=7788;


※ 备库查最小SCN
温馨提示:大多数情况下控制文件和数据文件头SCN值一致,但有时是不同的
rlwrap sqlplus / as sysdba
常规:SQL> select least(a.scn_ctl, b.scn_data) min_scn  from (select current_scn scn_ctl from v$database) a,(select min(CHECKPOINT_CHANGE#) scn_data from v$datafile) b;

优化:SQL> select least(a.scn_ctl, b.scn_data) min_scn,a.scn_ctl,b.scn_data  from (select dbms_flashback.get_system_change_number scn_ctl from v$database) a,(select min(CHECKPOINT_CHANGE#) scn_data from v$datafile) b;

※ 主库备份
温馨提示:假设备库最小SCN为:1169226
rlwrap rman target /
RMAN> backup device type disk incremental from scn 1169226 database format '/home/oracle/zzt/scn_data_%u' tag 'for standby';
scp /home/oracle/zzt/scn_data*  1.1.1.8:/home/oracle/zzt/
 


※ 备库应用增量备份
rlwrap sqlplus / as sysdba
SQL > alter database recover managed standby database cancel;

rlwrap rman target /
RMAN> shutdown immediate;
RMAN> startup mount;
RMAN> catalog start with '/home/oracle/zzt/' noprompt;
RMAN> recover database noredo;


※ 主库生成新的控制文件
rlwrap rman target /
RMAN> backup current controlfile for standby format '/home/oracle/zzt/scn.ctl';
scp /home/oracle/zzt/scn.ctl  1.1.1.8:/home/oracle/zzt/


※ 备库替换控制文件
rlwrap rman target /
RMAN> startup nomount force
RMAN> restore standby controlfile from '/home/oracle/zzt/scn.ctl';
RMAN> alter database mount;


※ 备库开启日志应用
rlwrap sqlplus / as sysdba
SQL > alter database open;
SQL > alter database recover managed standby database using current logfile disconnect from session;


※ 测试
--主库执行
SQL > set line 170
SQL > set pages 200
SQL > select * from scott.emp where empno=7788;
SQL > update scott.emp set sal=sal+1;
SQL > commit;
SQL > select * from scott.emp where empno=7788;
SQL > select current_scn from v$database;
--备库查看
SQL > set line 170
SQL > set pages 200
SQL > select * from scott.emp where empno=7788;
SQL > select current_scn from v$database;
 


★ 相关日志
///////////////////////////////////////////////////////
※ 基于SCN的增量备份

[oracle@dg1 ~]$ rlwrap rman target /

Recovery Manager: Release 11.2.0.3.0 - Production on Fri May 8 16:04:49 2020

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

connected to target database: ORCL (DBID=1468748669)

RMAN> backup device type disk incremental from scn 1169226 database format '/home/oracle/zzt/scn_data_%u' tag 'for standby';

Starting backup at 08-MAY-20

using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=21 device type=DISK
backup will be obsolete on date 15-MAY-20
archived logs will not be kept or backed up
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/oracle/oradata/orcl/system01.dbf
input datafile file number=00002 name=/u01/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00003 name=/u01/oracle/oradata/orcl/undotbs01.dbf
input datafile file number=00004 name=/u01/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: starting piece 1 at 08-MAY-20
channel ORA_DISK_1: finished piece 1 at 08-MAY-20
piece handle=/home/oracle/zzt/scn_data_06uvmll5 tag=FOR STANDBY comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:36

using channel ORA_DISK_1
backup will be obsolete on date 15-MAY-20
archived logs will not be kept or backed up
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 08-MAY-20
channel ORA_DISK_1: finished piece 1 at 08-MAY-20
piece handle=/home/oracle/zzt/scn_data_07uvmlm9 tag=FOR STANDBY comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 08-MAY-20

※ 生成DG备库控制文件

RMAN> backup current controlfile for standby format '/home/oracle/zzt/scn.ctl';

Starting backup at 08-MAY-20
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including standby control file in backup set
channel ORA_DISK_1: starting piece 1 at 08-MAY-20
channel ORA_DISK_1: finished piece 1 at 08-MAY-20
piece handle=/home/oracle/zzt/scn.ctl tag=TAG20200508T160654 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 08-MAY-20

RMAN> 

※ 使用源端的增量备份恢复目标端的备库

[root@dg2 ~]# su - oracle
[oracle@dg2 ~]$ rlwrap rman target /

Recovery Manager: Release 11.2.0.3.0 - Production on Fri May 8 16:06:32 2020

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

connected to target database: ORCL (DBID=1468748669)

shutdown immediate;
startup mount;
catalog start with '/home/oracle/zzt/';
recover database noredo;

using target database control file instead of recovery catalog
database closed
database dismounted
Oracle instance shut down

connected to target database (not started)
Oracle instance started
database mounted

Total System Global Area     780824576 bytes

Fixed Size                     2232432 bytes
Variable Size                473960336 bytes
Database Buffers             297795584 bytes
Redo Buffers                   6836224 bytes

RMAN> 
searching for all files that match the pattern /home/oracle/zzt/

List of Files Unknown to the Database
=====================================
File Name: /home/oracle/zzt/scn_data_06uvmll5
File Name: /home/oracle/zzt/scn_data_07uvmlm9

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/zzt/scn_data_06uvmll5
File Name: /home/oracle/zzt/scn_data_07uvmlm9

RMAN> recover database noredo;

Starting recover at 08-MAY-20
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=13 device type=DISK
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: /u01/oracle/oradata/orcl/system01.dbf
destination for restore of datafile 00002: /u01/oracle/oradata/orcl/sysaux01.dbf
destination for restore of datafile 00003: /u01/oracle/oradata/orcl/undotbs01.dbf
destination for restore of datafile 00004: /u01/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/zzt/scn_data_06uvmll5
channel ORA_DISK_1: piece handle=/home/oracle/zzt/scn_data_06uvmll5 tag=FOR STANDBY
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

Finished recover at 08-MAY-20


※ 生成并替换最新的DG备库控制文件

startup nomount force
restore standby controlfile from '/home/oracle/zzt/scn.ctl';
alter database mount;


Oracle instance started

Total System Global Area     780824576 bytes

Fixed Size                     2232432 bytes
Variable Size                473960336 bytes
Database Buffers             297795584 bytes
Redo Buffers                   6836224 bytes

RMAN> 
Starting restore at 08-MAY-20
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=133 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
output file name=/u01/oracle/oradata/orcl/control01.ctl
output file name=/u01/oracle/fast_recovery_area/orcl/control02.ctl
Finished restore at 08-MAY-20

RMAN> 
database mounted
released channel: ORA_DISK_1

※ 如果您觉得文章写的还不错, 别忘了在文末给作者点个赞哦 ~

over

原创文章 58 获赞 58 访问量 7082

猜你喜欢

转载自blog.csdn.net/zzt_2009/article/details/106000148