增量备份恢复DATAGUARD(gap没有增数据文件)

1.环境

主库 192.168.1.118
备库 192.168.1.85
OS Centos7
DB 11.2.0.4

 

 

 

 

 

 

 

 

2.发现有gap的归档日志
主库进行备份后带上了删除归档的命令
backup archivelog all delete all input format '/home/oracle/rman_backup/arch_level_0_%d_%s_%p_%T';

而且归档日志删除策略如下:
CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 1 TIMES TO DISK;

而不是强制从库应用后再删除
CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON ALL STANDBY;

 

从库查询:

SQL> select thread#, low_sequence#, high_sequence# from v$archive_gap;

 

   THREAD# LOW_SEQUENCE# HIGH_SEQUENCE#

---------- ------------- --------------

         1          1691           1702

 

 

 

 

 

 

发现这里确实出现了gap日志
即使出现gap的归档日志,但是mgr进程也是正常的,但是这个时候整个dataguard环境是不可用的

 

SQL> select process,status from v$managed_standby;

 

ARCH      CLOSING

ARCH      CLOSING

ARCH      CONNECTED

ARCH      CLOSING

RFS       IDLE

RFS       IDLE

RFS       IDLE

RFS       IDLE

MRP0      APPLYING_LOG

 

9 rows selected

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

3 查询主备库数据文件路径(避免主从库数据路径不一致需要转换)

主库:

SQL> set linesize 1000;

SQL> set heading off;

SQL> select FILE#,name from v$datafile;

 

         1 /u01/app/oracle/oradata/slnngk/system01.dbf

         2 /u01/app/oracle/oradata/slnngk/sysaux01.dbf

         3 /u01/app/oracle/oradata/slnngk/undotbs01.dbf

         4 /u01/app/oracle/oradata/slnngk/users01.dbf

         5 /u01/app/oracle/oradata/slnngk/tps_data01.dbf

         6 /u01/app/oracle/oradata/slnngk/mrkt.dbf

         7 /u01/app/oracle/oradata/slnngk/tps_data02.dbf

         8 /u01/app/oracle/oradata/tps_data02.dbf

         9 /u01/app/oracle/oradata/slnngk/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/slnngk/tps_data13.dbf

        19 /u01/app/oracle/oradata/tps_data14.dbf

        20 /u01/app/oracle/oradata/tps_data15.dbf

        21 /u01/app/oracle/oradata/tps_data16.dbf

        22 /u02/oradata/tps_data17.dbf

 

22 rows selected.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

从库:

SQL> set linesize 1000;

SQL> set heading off;

SQL> select FILE#,name from v$datafile;

 

         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

        20 /u01/app/oracle/oradata/tps_data15.dbf

        21 /u01/app/oracle/oradata/tps_data16.dbf

        22 /u02/oradata/tps_data17.dbf

 

22 rows selected.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

4.备库停掉日志应用

 

SQL> alter database recover managed standby database cancel;

Database altered.

这个时候相应的进程已经关闭,如下

SQL> select process,status from v$managed_standby;

PROCESS   STATUS
--------- ------------
ARCH      CONNECTED
ARCH      CONNECTED
ARCH      CLOSING

 

 

 

 

 

5.找到主库需要增量备份的SCN

备库执行

SQL> select current_scn from v$database;

 

CURRENT_SCN

-----------

  142237796

 

 

 

 

 

 

 

 

 

SQL> select min(checkpoint_change#) from v$datafile_header where file# not in (select file# from v$datafile where enabled = 'READ ONLY');

 

MIN(CHECKPOINT_CHANGE#)

-----------------------

              142237797

 

 

 

 

 

 

 

 

这里我们取最小的那个值:= 142237796
说明:上面一个为控制文件中记录的SCN号,另一个为数据文件头记录的SCN号,我们需要选择较小SCN号(142237796)在主库上进行增量备份
有些场景如下查询发现显示0或是空,这种情况,以第一个查询获取到的值为准

 

 

 

SQL> select min(checkpoint_change#) from v$datafile_header where file# not in (select file# from v$datafile where enabled = 'READ ONLY');

 

MIN(CHECKPOINT_CHANGE#)

-----------------------

                      0

 

 

 

 

 

 

 

 

6.检查scn之后是否添加有新的数据文件

主库执行

SQL> connect / as sysdba
Connected.
SQL> select FILE#,name from v$datafile where CREATION_CHANGE#> =142237796;

no rows selected

 

 

 

 

 

 

若没有发现新增的数据文件,我们这里的场景是没有新增数据文件的,上面语句没有记录返回

 

 

 

 

7.在主库上进行增量备份

run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
backup as compressed backupset incremental from scn 142237796 database format '/u01/rman/zengliang_%u.bak' tag 'zengliang';
release channel c1;
release channel c2;
}

 

 

 

 

 

 

 

 

8.在主库上生成standby控制文件

RMAN> backup current controlfile for standby format '/home/oracle/rman_backup/standby_ctl.bak';

 

 

9.拷贝上面备份的文件到备库

主库上操作

scp /home/oracle/rman_backup/standby_ctl.bak oracle@192.168.1.85:/tmp/rman_bak
scp /home/oracle/rman_backup/zengliang_pduji9oj.bak oracle@192.168.1.85:/tmp/rman_bak
scp /home/oracle/rman_backup/zengliang_peuji9oj.bak oracle@192.168.1.85:/tmp/rman_bak
scp /home/oracle/rman_backup/zengliang_pfuji9p3.bak oracle@192.168.1.85:/tmp/rman_bak

 

 

 

 

10.恢复控制文件并注册备份集

备库上操作
RMAN> shutdown immediate;
RMAN> startup nomount;
RMAN> restore standby controlfile from '/tmp/rman_bak/standby_ctl.bak';
RMAN> alter database mount;
RMAN> catalog start with '/tmp/rman_bak';


这里需要先恢复控制文件再做下面的恢复,若是先做恢复的话,新增的数据文件在原来的控制文件里是没有记录的,若是主从没有新增数据文件的话,先做恢复再还原控制文件也是可以的.

 

11.使用增量recover备库

moung状态下操作
SQL> connect / as sysdba
Connected.
SQL> select status from v$instance;

STATUS
------------
MOUNTED


Rman模式下执行
RMAN> recover database noredo;

 

 

12.清空日志组

修改数据到mount状态
SQL> select status from v$instance;

STATUS
------------
MOUNTED

 

将所有的日志组进行清空掉
SQL>  select group#,bytes from v$log;

    GROUP#      BYTES
---------- ----------
         1   52428800
         3   52428800
         2   52428800

alter database clear logfile group 1;
alter database clear logfile group 2;
alter database clear logfile group 3;

查看是否采用了standby log
SQL> Select * From v$standby_log;

no rows selected

注:如果采用了standby log模式,不需要清空,如果清空会出现
SQL> ALTER DATABASE CLEAR LOGFILE GROUP 1;
ALTER DATABASE CLEAR LOGFILE GROUP 1
*
ERROR at line 1:
ORA-19527: physical standby redo log must be renamed
ORA-00312: online log 1 thread 1: '/u01/oradata/badly9/redo01.log'
说明:如果没有采用standby log模式,有几组需要清空几组

 

13.从库启动监听器
lsnrctl start

 

14.从库开始应用日志

SQL> select status from v$instance;

STATUS
------------
MOUNTED

SQL> alter database recover managed standby database using current logfile disconnect from session;
alter database recover managed standby database using current logfile disconnect from session
*
ERROR at line 1:
ORA-38500: USING CURRENT LOGFILE option not available without standby redo logs

需要添加standby日志
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;


日志应用
SQL> alter database recover managed standby database using current logfile disconnect from session;

 

 

14.打开数据库

应用日志
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;

 

 

15.再次检查是否有gap日志

从库执行:
SQL> select thread#, low_sequence#, high_sequence# from v$archive_gap;

no rows selected

 

16.主库尝试日志切换
同步正常后第一次要做一次日志切换

SQL> alter system switch logfile;

 

--The End --

posted @ 2019-12-16 10:24  slnngk  阅读(612)  评论(0编辑  收藏  举报