1 Incrementally Updated Backup 特性概述
Oracle 在10g 版本引入了一个特性:incrementally updated backup, 其不是我们通常理解的增量备份,而是基于image copy 的增量备份。
官方的说明参考:
http://docs.oracle.com/database/122/BRADV/getting-started-rman.htm#BRADV89354
RMAN incrementally updated backup 特性有如下主要特性:
· The strategy requires a level 0 data file copy as a base. This copy has either a system-defined or user-defined tag.
·
Periodically, level 1 differential backups are created with the same tag as the level 0 data file copy. The BACKUP FOR RECOVER OF COPY
command specifies that an incremental backup contains only blocks changed since the most recent incremental backup with the same tag.
· Periodically, the incremental backups are applied to the level 0 data file copy. Because the data file copy has been updated with more recent changes, it now requires less media recovery.
实现 incrementally updated backup 功能只需要定期的RMAN 中执行如下命令即可:
run{
RECOVER COPY OF DATABASE
WITH TAG 'incr_cndba_backup';
BACKUP
INCREMENTAL LEVEL 1
FOR RECOVER OF COPY WITH TAG 'incr_cndba_backup'
DATABASE;
}
Incrementally updated backup 只需要用到上面的2段代码即可。 注意:
1. 对于RECOVER COPY OF DATABASE WITH TAG 'incr_update'; 命令如果没有增量备份的数据则不进行recover copy的操作。
2. 对于BACKUP INCREMENTAL LEVEL 1 FOR RECOVER OF COPY WITH TAG 'incr_update' DATABASE; 命令,如果没有没有0级的image copy备份,则默认执行0级备份。 同样,如果增加新的数据文件,也会单独的备份没有做过0级备份的数据文件。
3. 1和2 之间必须使用相同的tag,才有效。
2 备份
测试数据库信息:
[oracle@cndba.cn ~]$ sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Sun Apr 16 14:56:55 2017
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 DAVE MOUNTED
SQL> alter pluggable database dave open;
Pluggable database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 DAVE READ WRITE NO
SQL>
对PDB: DAVE 进行备份
--第一次备份:从日志可以看出是0级备份
[oracle@cndba.cn admin]$ rman target sys/oracle@dave
Recovery Manager: Release 12.2.0.1.0 - Production on Sun Apr 16 14:59:56 2017
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
connected to target database: CNDBA:DAVE (DBID=3644522783)
RMAN>
RMAN> RECOVER COPY OF DATABASE
WITH TAG 'incr_cndba_backup';
BACKUP
INCREMENTAL LEVEL 1
FOR RECOVER OF COPY WITH TAG 'incr_cndba_backup'
DATABASE;
2>
Starting recover at 16-APR-17
using channel ORA_DISK_1
no copy of datafile 9 found to recover
no copy of datafile 10 found to recover
no copy of datafile 11 found to recover
no copy of datafile 12 found to recover
Finished recover at 16-APR-17
RMAN> 2> 3> 4>
Starting backup at 16-APR-17
using channel ORA_DISK_1
no parent backup or copy of datafile 10 found
no parent backup or copy of datafile 9 found
no parent backup or copy of datafile 11 found
no parent backup or copy of datafile 12 found
channel ORA_DISK_1: starting datafile copy
input datafile file number=00010 name=/u01/app/oracle/oradata/cndba/dave/sysaux01.dbf
output file name=/u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/datafile/o1_mf_sysaux_dh665zox_.dbf tag=INCR_CNDBA_BACKUP RECID=8 STAMP=941469001
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00009 name=/u01/app/oracle/oradata/cndba/dave/system01.dbf
output file name=/u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/datafile/o1_mf_system_dh666gvh_.dbf tag=INCR_CNDBA_BACKUP RECID=9 STAMP=941469014
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00011 name=/u01/app/oracle/oradata/cndba/dave/undotbs01.dbf
output file name=/u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/datafile/o1_mf_undotbs1_dh666y07_.dbf tag=INCR_CNDBA_BACKUP RECID=10 STAMP=941469023
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile file number=00012 name=/u01/app/oracle/oradata/cndba/dave/users01.dbf
output file name=/u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/datafile/o1_mf_users_dh66714f_.dbf tag=INCR_CNDBA_BACKUP RECID=11 STAMP=941469025
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 16-APR-17
RMAN>
--第二次:创建一个表空间,在备份,备份代码和之前一样,通过备份日志可以看到对新添加的数据文件进行了0级备份,其他数据进行了增量备份:
SQL> alter session set container=dave;
Session altered.
SQL> create tablespace dave datafile '/u01/app/oracle/oradata/cndba/dave/dave.dbf' size 10m;
Tablespace created.
RMAN> RECOVER COPY OF DATABASE
WITH TAG 'incr_cndba_backup';
BACKUP
INCREMENTAL LEVEL 1
FOR RECOVER OF COPY WITH TAG 'incr_cndba_backup'
DATABASE;
2>
Starting recover at 16-APR-17
using channel ORA_DISK_1
no copy of datafile 9 found to recover
no copy of datafile 10 found to recover
no copy of datafile 11 found to recover
no copy of datafile 12 found to recover
no copy of datafile 13 found to recover
Finished recover at 16-APR-17
RMAN> 2> 3> 4>
Starting backup at 16-APR-17
using channel ORA_DISK_1
no parent backup or copy of datafile 13 found
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00010 name=/u01/app/oracle/oradata/cndba/dave/sysaux01.dbf
input datafile file number=00009 name=/u01/app/oracle/oradata/cndba/dave/system01.dbf
input datafile file number=00011 name=/u01/app/oracle/oradata/cndba/dave/undotbs01.dbf
input datafile file number=00012 name=/u01/app/oracle/oradata/cndba/dave/users01.dbf
channel ORA_DISK_1: starting piece 1 at 16-APR-17
channel ORA_DISK_1: finished piece 1 at 16-APR-17
piece handle=/u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/backupset/2017_04_16/o1_mf_nnnd1_INCR_CNDBA_BACKUP_dh66cxwv_.bkp tag=INCR_CNDBA_BACKUP comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: starting datafile copy
input datafile file number=00013 name=/u01/app/oracle/oradata/cndba/dave/dave.dbf
output file name=/u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/datafile/o1_mf_dave_dh66cz1s_.dbf tag=INCR_CNDBA_BACKUP RECID=12 STAMP=941469183
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 16-APR-17
--第三次: 在进行一次备份,备份代码和之前一样,这次只有增量备份, 先对增量进行recover,再进行backup:
RMAN> RECOVER COPY OF DATABASE
WITH TAG 'incr_cndba_backup';
BACKUP
INCREMENTAL LEVEL 1
FOR RECOVER OF COPY WITH TAG 'incr_cndba_backup'
DATABASE;
2>
Starting recover at 16-APR-17
using channel ORA_DISK_1
no copy of datafile 13 found to recover
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile copies to recover
recovering datafile copy file number=00009 name=/u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/datafile/o1_mf_system_dh666gvh_.dbf
recovering datafile copy file number=00010 name=/u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/datafile/o1_mf_sysaux_dh665zox_.dbf
recovering datafile copy file number=00011 name=/u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/datafile/o1_mf_undotbs1_dh666y07_.dbf
recovering datafile copy file number=00012 name=/u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/datafile/o1_mf_users_dh66714f_.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/backupset/2017_04_16/o1_mf_nnnd1_INCR_CNDBA_BACKUP_dh66cxwv_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/backupset/2017_04_16/o1_mf_nnnd1_INCR_CNDBA_BACKUP_dh66cxwv_.bkp tag=INCR_CNDBA_BACKUP
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
Finished recover at 16-APR-17
RMAN> 2> 3> 4>
Starting backup at 16-APR-17
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00010 name=/u01/app/oracle/oradata/cndba/dave/sysaux01.dbf
input datafile file number=00009 name=/u01/app/oracle/oradata/cndba/dave/system01.dbf
input datafile file number=00011 name=/u01/app/oracle/oradata/cndba/dave/undotbs01.dbf
input datafile file number=00013 name=/u01/app/oracle/oradata/cndba/dave/dave.dbf
input datafile file number=00012 name=/u01/app/oracle/oradata/cndba/dave/users01.dbf
channel ORA_DISK_1: starting piece 1 at 16-APR-17
channel ORA_DISK_1: finished piece 1 at 16-APR-17
piece handle=/u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/backupset/2017_04_16/o1_mf_nnnd1_INCR_CNDBA_BACKUP_dh66hgct_.bkp tag=INCR_CNDBA_BACKUP comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 16-APR-17
3 恢复
使用 incrementally updated backup 特性进行备份的主要原因就是其是image copy方式进行的备份,所以恢复起来非常快。 但缺点也很明显,需要的备份空间比较多。
对于image copy方式的备份,恢复有2种方法:
1. 传统的restore 和 recover
2. 直接进行switch
3.1 恢复方法1:swith
这里我们把创建的dave 表空间的数据文件删掉:
[oracle@cndba.cn recovery_area]$ rm -rf /u01/app/oracle/oradata/cndba/dave/dave.dbf
SQL> l
1* select file_id,file_name,tablespace_name from dba_data_files
SQL> /
FILE_ID FILE_NAME TABLESPACE_NAME
---------- ------------------------------------------------------------ ------------------------------
9 /u01/app/oracle/oradata/cndba/dave/system01.dbf SYSTEM
10 /u01/app/oracle/oradata/cndba/dave/sysaux01.dbf SYSAUX
11 /u01/app/oracle/oradata/cndba/dave/undotbs01.dbf UNDOTBS1
12 /u01/app/oracle/oradata/cndba/dave/users01.dbf USERS
13 /u01/app/oracle/oradata/cndba/dave/dave.dbf DAVE
SQL> alter pluggable database dave close;
Pluggable database altered.
SQL> alter pluggable database dave open;
alter pluggable database dave open
*
ERROR at line 1:
ORA-01157: cannot identify/lock data file 13 - see DBWR trace file
ORA-01110: data file 13: '/u01/app/oracle/oradata/cndba/dave/dave.dbf'
现在库已经不能打开了。
SQL> alter pluggable database dave open;
alter pluggable database dave open
*
ERROR at line 1:
ORA-01113: file 12 needs media recovery
ORA-01110: data file 12: '/u01/app/oracle/oradata/cndba/dave/users01.dbf'
SQL> recover datafile 12;
Media recovery complete.
SQL> recover datafile 11;
Media recovery complete.
SQL> recover datafile 10;
Media recovery complete.
SQL> recover datafile 9;
Media recovery complete.
SQL> alter pluggable database dave open;
Pluggable database altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
3 DAVE READ WRITE NO
SQL>
库已经打开,现在恢复删除的数据文件:
RMAN> switch datafile 13 to copy;
using target database control file instead of recovery catalog
datafile 13 switched to datafile copy "/u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/datafile/o1_mf_dave_dh66cz1s_.dbf"
SQL> select file_id,file_name,tablespace_name from dba_data_files;
FILE_ID FILE_NAME TABLESPACE_NAME
---------- ------------------------------------------------------------ ------------------------------
9 /u01/app/oracle/oradata/cndba/dave/system01.dbf SYSTEM
10 /u01/app/oracle/oradata/cndba/dave/sysaux01.dbf SYSAUX
11 /u01/app/oracle/oradata/cndba/dave/undotbs01.dbf UNDOTBS1
12 /u01/app/oracle/oradata/cndba/dave/users01.dbf USERS
13 /u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCA DAVE
EA00C8B8/datafile/o1_mf_dave_dh66cz1s_.dbf
恢复完成。
3.2 恢复方法2:使用restore 和 recover
也可以利用image copy的备份进行普通的RMAN 恢复,操作如下:
在删dave的数据文件:
[oracle@cndba.cn cndba]$ rm -rf /u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/datafile/o1_mf_dave_dh66cz1s_.dbf
[oracle@cndba.cn cndba]$
进行普通的RMAN 恢复:
RMAN> run {
shutdown immediate;
startup mount;
restore database;
recover database;
alter database open;
}
2> 3> 4> 5> 6> 7>
database closed
Starting restore at 16-APR-17
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1 device type=DISK
creating datafile file number=13 name=/u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/datafile/o1_mf_dave_dh66cz1s_.dbf
channel ORA_DISK_1: restoring datafile 00009
input datafile copy RECID=20 STAMP=941469444 file name=/u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/datafile/o1_mf_system_dh666gvh_.dbf
destination for restore of datafile 00009: /u01/app/oracle/oradata/cndba/dave/system01.dbf
channel ORA_DISK_1: copied datafile copy of datafile 00009
output file name=/u01/app/oracle/oradata/cndba/dave/system01.dbf RECID=0 STAMP=0
channel ORA_DISK_1: restoring datafile 00010
input datafile copy RECID=21 STAMP=941469444 file name=/u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/datafile/o1_mf_sysaux_dh665zox_.dbf
destination for restore of datafile 00010: /u01/app/oracle/oradata/cndba/dave/sysaux01.dbf
channel ORA_DISK_1: copied datafile copy of datafile 00010
output file name=/u01/app/oracle/oradata/cndba/dave/sysaux01.dbf RECID=0 STAMP=0
channel ORA_DISK_1: restoring datafile 00011
input datafile copy RECID=19 STAMP=941469444 file name=/u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/datafile/o1_mf_undotbs1_dh666y07_.dbf
destination for restore of datafile 00011: /u01/app/oracle/oradata/cndba/dave/undotbs01.dbf
channel ORA_DISK_1: copied datafile copy of datafile 00011
output file name=/u01/app/oracle/oradata/cndba/dave/undotbs01.dbf RECID=0 STAMP=0
channel ORA_DISK_1: restoring datafile 00012
input datafile copy RECID=18 STAMP=941469444 file name=/u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/datafile/o1_mf_users_dh66714f_.dbf
destination for restore of datafile 00012: /u01/app/oracle/oradata/cndba/dave/users01.dbf
channel ORA_DISK_1: copied datafile copy of datafile 00012
output file name=/u01/app/oracle/oradata/cndba/dave/users01.dbf RECID=0 STAMP=0
Finished restore at 16-APR-17
Starting recover at 16-APR-17
using channel ORA_DISK_1
datafile 13 not processed because file is offline
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 00009: /u01/app/oracle/oradata/cndba/dave/system01.dbf
destination for restore of datafile 00010: /u01/app/oracle/oradata/cndba/dave/sysaux01.dbf
destination for restore of datafile 00011: /u01/app/oracle/oradata/cndba/dave/undotbs01.dbf
destination for restore of datafile 00012: /u01/app/oracle/oradata/cndba/dave/users01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/backupset/2017_04_16/o1_mf_nnnd1_INCR_CNDBA_BACKUP_dh66n845_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/recovery_area/CNDBA/4B3DCC40385970DCE0558DCAEA00C8B8/backupset/2017_04_16/o1_mf_nnnd1_INCR_CNDBA_BACKUP_dh66n845_.bkp tag=INCR_CNDBA_BACKUP
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
starting media recovery
media recovery complete, elapsed time: 00:00:02
Finished recover at 16-APR-17
Statement processed
RMAN>
恢复完成。
版权声明:本文为博主原创文章,未经博主允许不得转载。