[20161212]备份archivelog.txt
--许多人都知道如果执行backup database plus archivelog;实际上是先执行如下:
1.alter system archive log current ;
2.备份archivelog;
3.备份数据库
4.alter system archive log current ;
5.备份剩下的archivelog备份.
自己测试看看:
1.环境:
SYS@book> @ &r/ver1
PORT_STRING VERSION BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
SYS@book> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/archivelog/book
Oldest online log sequence 9
Next log sequence to archive 11
Current log sequence 11
--当前Current log sequence=11.
$ ls -ltr /u01/app/oracle/archivelog/book/1_*
-rw-r----- 1 oracle oinstall 47245824 2016-12-12 09:01:58 /u01/app/oracle/archivelog/book/1_6_896605872.dbf
-rw-r----- 1 oracle oinstall 1170944 2016-12-12 09:26:56 /u01/app/oracle/archivelog/book/1_7_896605872.dbf
-rw-r----- 1 oracle oinstall 2048 2016-12-12 09:27:53 /u01/app/oracle/archivelog/book/1_8_896605872.dbf
-rw-r----- 1 oracle oinstall 3072 2016-12-12 09:28:04 /u01/app/oracle/archivelog/book/1_9_896605872.dbf
-rw-r----- 1 oracle oinstall 482304 2016-12-12 09:55:58 /u01/app/oracle/archivelog/book/1_10_896605872.dbf
2.备份测试:
RMAN> backup database plus archivelog ;
Starting backup at 2016-12-12 09:58:07
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=6 RECID=2 STAMP=930387718
input archived log thread=1 sequence=7 RECID=3 STAMP=930389216
input archived log thread=1 sequence=8 RECID=4 STAMP=930389273
input archived log thread=1 sequence=9 RECID=5 STAMP=930389284
input archived log thread=1 sequence=10 RECID=6 STAMP=930390958
input archived log thread=1 sequence=11 RECID=7 STAMP=930391087
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<=说明先做了一次切换.alter system archive log current ;并且先备份archivelog.
channel ORA_DISK_1: starting piece 1 at 2016-12-12 09:58:07
channel ORA_DISK_1: finished piece 1 at 2016-12-12 09:58:08
piece handle=/u01/app/oracle/fast_recovery_area/BOOK/backupset/2016_12_12/o1_mf_annnn_TAG20161212T095807_d4w11hf9_.bkp tag=TAG20161212T095807 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2016-12-12 09:58:08
Starting backup at 2016-12-12 09:58:08
using channel ORA_DISK_1
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=/mnt/ramdisk/book/system01.dbf
input datafile file number=00002 name=/mnt/ramdisk/book/sysaux01.dbf
input datafile file number=00005 name=/mnt/ramdisk/book/example01.dbf
input datafile file number=00003 name=/mnt/ramdisk/book/undotbs01.dbf
input datafile file number=00004 name=/mnt/ramdisk/book/users01.dbf
channel ORA_DISK_1: starting piece 1 at 2016-12-12 09:58:08
channel ORA_DISK_1: finished piece 1 at 2016-12-12 09:58:15
piece handle=/u01/app/oracle/fast_recovery_area/BOOK/backupset/2016_12_12/o1_mf_nnndf_TAG20161212T095808_d4w11jno_.bkp tag=TAG20161212T095808 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
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
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 2016-12-12 09:58:16
channel ORA_DISK_1: finished piece 1 at 2016-12-12 09:58:17
piece handle=/u01/app/oracle/fast_recovery_area/BOOK/backupset/2016_12_12/o1_mf_ncsnf_TAG20161212T095808_d4w11rsb_.bkp tag=TAG20161212T095808 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2016-12-12 09:58:17
Starting backup at 2016-12-12 09:58:17
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=12 RECID=8 STAMP=930391097
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<=又做了1次切换,备份剩下的archivelog.
channel ORA_DISK_1: starting piece 1 at 2016-12-12 09:58:17
channel ORA_DISK_1: finished piece 1 at 2016-12-12 09:58:18
piece handle=/u01/app/oracle/fast_recovery_area/BOOK/backupset/2016_12_12/o1_mf_annnn_TAG20161212T095817_d4w11syb_.bkp tag=TAG20161212T095817 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2016-12-12 09:58:18
$ ls -ltr /u01/app/oracle/archivelog/book/1_*
-rw-r----- 1 oracle oinstall 47245824 2016-12-12 09:01:58 /u01/app/oracle/archivelog/book/1_6_896605872.dbf
-rw-r----- 1 oracle oinstall 1170944 2016-12-12 09:26:56 /u01/app/oracle/archivelog/book/1_7_896605872.dbf
-rw-r----- 1 oracle oinstall 2048 2016-12-12 09:27:53 /u01/app/oracle/archivelog/book/1_8_896605872.dbf
-rw-r----- 1 oracle oinstall 3072 2016-12-12 09:28:04 /u01/app/oracle/archivelog/book/1_9_896605872.dbf
-rw-r----- 1 oracle oinstall 482304 2016-12-12 09:55:58 /u01/app/oracle/archivelog/book/1_10_896605872.dbf
-rw-r----- 1 oracle oinstall 29696 2016-12-12 09:58:07 /u01/app/oracle/archivelog/book/1_11_896605872.dbf
-rw-r----- 1 oracle oinstall 1536 2016-12-12 09:58:17 /u01/app/oracle/archivelog/book/1_12_896605872.dbf
--//可以发现多了2个归档日志11,12.也就是讲这样备份对于恢复才有效,因为如果缺少后面的归档日志,可能恢复到某个特定的scn不行.
--//可以查看以前的测试链接:http://blog.itpub.net/267265/viewspace-2106087/
--//如果备份时存在写盘操作,scn大于 CHECKPOINT_CHANGE#的scn,要记录在控制文件中的. 视图 v$backup_datafile的字段
--//ABSOLUTE_FUZZY_CHANGE#可以反应出来.
3.其他方式备份archivelog呢?
RMAN> backup archivelog all ;
Starting backup at 2016-12-12 10:15:35
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=6 RECID=2 STAMP=930387718
input archived log thread=1 sequence=7 RECID=3 STAMP=930389216
input archived log thread=1 sequence=8 RECID=4 STAMP=930389273
input archived log thread=1 sequence=9 RECID=5 STAMP=930389284
input archived log thread=1 sequence=10 RECID=6 STAMP=930390958
input archived log thread=1 sequence=11 RECID=7 STAMP=930391087
input archived log thread=1 sequence=12 RECID=8 STAMP=930391097
input archived log thread=1 sequence=13 RECID=9 STAMP=930392135
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<=做了一次切换.alter system archive log current;
channel ORA_DISK_1: starting piece 1 at 2016-12-12 10:15:35
channel ORA_DISK_1: finished piece 1 at 2016-12-12 10:15:36
piece handle=/u01/app/oracle/fast_recovery_area/BOOK/backupset/2016_12_12/o1_mf_annnn_TAG20161212T101535_d4w22784_.bkp tag=TAG20161212T101535 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2016-12-12 10:15:36
$ ls -ltr /u01/app/oracle/archivelog/book/1_*
-rw-r----- 1 oracle oinstall 47245824 2016-12-12 09:01:58 /u01/app/oracle/archivelog/book/1_6_896605872.dbf
-rw-r----- 1 oracle oinstall 1170944 2016-12-12 09:26:56 /u01/app/oracle/archivelog/book/1_7_896605872.dbf
-rw-r----- 1 oracle oinstall 2048 2016-12-12 09:27:53 /u01/app/oracle/archivelog/book/1_8_896605872.dbf
-rw-r----- 1 oracle oinstall 3072 2016-12-12 09:28:04 /u01/app/oracle/archivelog/book/1_9_896605872.dbf
-rw-r----- 1 oracle oinstall 482304 2016-12-12 09:55:58 /u01/app/oracle/archivelog/book/1_10_896605872.dbf
-rw-r----- 1 oracle oinstall 29696 2016-12-12 09:58:07 /u01/app/oracle/archivelog/book/1_11_896605872.dbf
-rw-r----- 1 oracle oinstall 1536 2016-12-12 09:58:17 /u01/app/oracle/archivelog/book/1_12_896605872.dbf
-rw-r----- 1 oracle oinstall 1771008 2016-12-12 10:15:35 /u01/app/oracle/archivelog/book/1_13_896605872.dbf
--//如果仅仅备份archivelog all,仅仅切换1次.
RMAN> backup archivelog from time 'trunc(sysdate)';
Starting backup at 2016-12-12 10:19:11
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=6 RECID=2 STAMP=930387718
input archived log thread=1 sequence=7 RECID=3 STAMP=930389216
input archived log thread=1 sequence=8 RECID=4 STAMP=930389273
input archived log thread=1 sequence=9 RECID=5 STAMP=930389284
input archived log thread=1 sequence=10 RECID=6 STAMP=930390958
input archived log thread=1 sequence=11 RECID=7 STAMP=930391087
input archived log thread=1 sequence=12 RECID=8 STAMP=930391097
input archived log thread=1 sequence=13 RECID=9 STAMP=930392135
input archived log thread=1 sequence=14 RECID=10 STAMP=930392351
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<=做了一次切换.alter system archive log current;
channel ORA_DISK_1: starting piece 1 at 2016-12-12 10:19:11
channel ORA_DISK_1: finished piece 1 at 2016-12-12 10:19:12
piece handle=/u01/app/oracle/fast_recovery_area/BOOK/backupset/2016_12_12/o1_mf_annnn_TAG20161212T101911_d4w28zm4_.bkp tag=TAG20161212T101911 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2016-12-12 10:19:12
RMAN> backup archivelog from sequence 13;
Starting backup at 2016-12-12 10:20:11
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=13 RECID=9 STAMP=930392135
input archived log thread=1 sequence=14 RECID=10 STAMP=930392351
input archived log thread=1 sequence=15 RECID=11 STAMP=930392412
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<=做了一次切换.alter system archive log current;
channel ORA_DISK_1: starting piece 1 at 2016-12-12 10:20:12
channel ORA_DISK_1: finished piece 1 at 2016-12-12 10:20:13
piece handle=/u01/app/oracle/fast_recovery_area/BOOK/backupset/2016_12_12/o1_mf_annnn_TAG20161212T102012_d4w2bwwj_.bkp tag=TAG20161212T102012 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2016-12-12 10:20:13
4.另外的测试:
$ ls -ltr /u01/app/oracle/archivelog/book/1_1*
-rw-r----- 1 oracle oinstall 482304 2016-12-12 09:55:58 /u01/app/oracle/archivelog/book/1_10_896605872.dbf
-rw-r----- 1 oracle oinstall 29696 2016-12-12 09:58:07 /u01/app/oracle/archivelog/book/1_11_896605872.dbf
-rw-r----- 1 oracle oinstall 1536 2016-12-12 09:58:17 /u01/app/oracle/archivelog/book/1_12_896605872.dbf
-rw-r----- 1 oracle oinstall 1771008 2016-12-12 10:15:35 /u01/app/oracle/archivelog/book/1_13_896605872.dbf
-rw-r----- 1 oracle oinstall 304128 2016-12-12 10:19:11 /u01/app/oracle/archivelog/book/1_14_896605872.dbf
-rw-r----- 1 oracle oinstall 2048 2016-12-12 10:20:12 /u01/app/oracle/archivelog/book/1_15_896605872.dbf
RMAN> backup archivelog sequence between 10 and 20;
Starting backup at 2016-12-12 10:22:49
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=10 RECID=6 STAMP=930390958
input archived log thread=1 sequence=11 RECID=7 STAMP=930391087
input archived log thread=1 sequence=12 RECID=8 STAMP=930391097
input archived log thread=1 sequence=13 RECID=9 STAMP=930392135
input archived log thread=1 sequence=14 RECID=10 STAMP=930392351
input archived log thread=1 sequence=15 RECID=11 STAMP=930392412
channel ORA_DISK_1: starting piece 1 at 2016-12-12 10:22:49
channel ORA_DISK_1: finished piece 1 at 2016-12-12 10:22:50
piece handle=/u01/app/oracle/fast_recovery_area/BOOK/backupset/2016_12_12/o1_mf_annnn_TAG20161212T102249_d4w2hsl0_.bkp tag=TAG20161212T102249 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2016-12-12 10:22:50
--这样不会切换.
总结:
1.backup database plus archivelog方式,至少切换2次,先备份archivelog,然后数据文件,再切换一次,在备份剩下的archivelog.
2.backup archivelog all ;,仅仅先切换归档,再备份.
3.backup archivelog from time 'trunc(sysdate)'; 仅仅先切换归档,再备份.
4.backup archivelog sequence between 10 and 20; 没有切换.
5.估计有范围的单独备份都没有切换,仅仅猜测不做测试了.