RMAN catalog自动备份脚本的创建使用,如果你还不了解catalog如何创建可以参考RMAN catalog的创建和基本使用
创建删除过期备份的全局脚本
[oracle@catalog ~]$ rman catalog cataloguser/cataloguser target sys/oracle@zhong Recovery Manager: Release 10.2.0.1.0 - Production on Wed Mar 28 08:53:27 2012 Copyright (c) 1982, 2005, Oracle. All rights reserved. connected to target database: ZHONG (DBID=1447686871) connected to recovery catalog database RMAN> replace global script global_del comment "delete obsolete backup" { 2> allocate channel c1 device type disk; 3> delete obsolete recovery window of 15 days; 4> release channel c1; 5> } replaced global script global_del RMAN>
RMAN> replace global script global_bkctl comment "backup current controlfile"{ 2> allocate channel c1 device type disk; 3> backup as compressed backupset 4> format='/orabackup/backupctl.ctl' tag='bkctl' 5> channel=c1 6> current controlfile reuse; 7> release channel c1; 8> } replaced global script global_bkctl RMAN>
RMAN> replace global script global_arch comment "backup archivelog as delete input"{ 2> allocate channel c1 device type disk; 3> sql 'alter system archive log current'; 4> set limit channel c1 readrate=10240; 5> set limit channel c1 kbytes=4096000; 6> backup as compressed backupset 7> format='/orabackup/arch_%d_%U' tag='bkarch' 8> channel=c1 9> archivelog all delete input; 10> release channel c1; 11> } replaced global script global_arch RMAN>
RMAN> replace global script global_inc0 comment "backup database as incremental level 0"{ 2> execute global script global_del; 3> allocate channel c1 device type disk; 4> set limit channel c1 readrate=10240; 5> set limit channel c1 kbytes=4096000; 6> backup as compressed backupset 7> incremental level=0 8> format='/orabackup/inc0_%d_%U' tag='inc0' 9> channel=c1 10> database; 11> release channel c1; 12> execute global script global_arch; 13> execute global script global_bkctl; 14> } replaced global script global_inc0 RMAN>
RMAN> replace global script global_inc1 comment "backup database as incremental level 1"{ 2> execute global script global_del; 3> allocate channel c1 device type disk; 4> set limit channel c1 readrate=10240; 5> set limit channel c1 kbytes=4096000; 6> backup as compressed backupset 7> incremental level=1 8> format='/orabackup/inc1_%d_%U' tag='inc1' 9> channel=c1 10> database; 11> release channel c1; 12> execute global script global_arch; 13> execute global script global_bkctl; 14> } replaced global script global_inc1 RMAN>
RMAN> replace global script global_inc2 comment "backup database as incremental level 2"{ 2> execute global script global_del; 3> allocate channel c1 device type disk; 4> set limit channel c1 readrate=10240; 5> set limit channel c1 kbytes=4096000; 6> backup as compressed backupset 7> incremental level=2 8> format='/orabackup/inc2_%d_%U' tag='inc2' 9> channel=c1 10> database; 11> release channel c1; 12> execute global script global_arch; 13> execute global script global_bkctl; 14> } replaced global script global_inc2 RMAN>
RMAN> list global script names; List of Stored Scripts in Recovery Catalog Global Scripts Script Name Description ----------------------------------------------------------------------- global_arch backup archivelog as delete input global_bkctl backup current controlfile global_del delete obsolete backup global_inc0 backup database as incremental level 0 global_inc1 backup database as incremental level 1 global_inc2 backup database as incremental level 2 RMAN>
RMAN> print global script global_arch; printing stored global script: global_arch {allocate channel c1 device type disk; sql 'alter system archive log current'; set limit channel c1 readrate=10240; set limit channel c1 kbytes=4096000; backup as compressed backupset format='/orabackup/arch_%d_%U' tag='bkarch' channel=c1 archivelog all delete input; release channel c1; } RMAN> print global script global_del; printing stored global script: global_del {allocate channel c1 device type disk; delete obsolete recovery window of 15 days; release channel c1; } RMAN> print global script global_bkctl; printing stored global script: global_bkctl {allocate channel c1 device type disk; backup as compressed backupset format='/orabackup/backupctl.ctl' tag='bkctl' channel=c1 current controlfile reuse; release channel c1; } RMAN> print global script global_inc0; printing stored global script: global_inc0 {execute global script global_del; allocate channel c1 device type disk; set limit channel c1 readrate=10240; set limit channel c1 kbytes=4096000; backup as compressed backupset incremental level=0 format='/orabackup/inc0_%d_%U' tag='inc0' channel=c1 database; release channel c1; execute global script global_arch; execute global script global_bkctl; } RMAN> print global script global_inc1; printing stored global script: global_inc1 {execute global script global_del; allocate channel c1 device type disk; set limit channel c1 readrate=10240; set limit channel c1 kbytes=4096000; backup as compressed backupset incremental level=1 format='/orabackup/inc1_%d_%U' tag='inc1' channel=c1 database; release channel c1; execute global script global_arch; execute global script global_bkctl; } RMAN> print global script global_inc2; printing stored global script: global_inc2 {execute global script global_del; allocate channel c1 device type disk; set limit channel c1 readrate=10240; set limit channel c1 kbytes=4096000; backup as compressed backupset incremental level=2 format='/orabackup/inc2_%d_%U' tag='inc2' channel=c1 database; release channel c1; execute global script global_arch; execute global script global_bkctl; } RMAN>
测试脚本。catalog创建脚本的时候不会去验证脚本的语法是否正确
RMAN> run{ 2> execute global script global_inc0; 3> execute global script global_inc1; 4> execute global script global_inc2; 5> } executing global script: global_inc0 executing global script: global_del allocated channel: c1 channel c1: sid=140 devtype=DISK no obsolete backups found released channel: c1 allocated channel: c1 channel c1: sid=140 devtype=DISK Starting backup at 28-MAR-12 channel c1: starting compressed incremental level 0 datafile backupset channel c1: specifying datafile(s) in backupset input datafile fno=00001 name=/u01/app/oracle/oradata/zhong/system01.dbf input datafile fno=00003 name=/u01/app/oracle/oradata/zhong/sysaux01.dbf input datafile fno=00005 name=/u01/app/oracle/oradata/zhong/example01.dbf input datafile fno=00002 name=/u01/app/oracle/oradata/zhong/undotbs01.dbf input datafile fno=00004 name=/u01/app/oracle/oradata/zhong/users01.dbf channel c1: starting piece 1 at 28-MAR-12 channel c1: finished piece 1 at 28-MAR-12 piece handle=/orabackup/inc0_ZHONG_0rn70asb_1_1 tag=INC0 comment=NONE channel c1: backup set complete, elapsed time: 00:00:25 Finished backup at 28-MAR-12 Starting Control File and SPFILE Autobackup at 28-MAR-12 piece handle=/u01/app/oracle/product/10.2.0/db_1/dbs/c-1447686871-20120328-00 comment=NONE Finished Control File and SPFILE Autobackup at 28-MAR-12 released channel: c1 executing global script: global_arch allocated channel: c1 channel c1: sid=140 devtype=DISK sql statement: alter system archive log current Starting backup at 28-MAR-12 current log archived channel c1: starting compressed archive log backupset channel c1: specifying archive log(s) in backup set input archive log thread=1 sequence=5 recid=3 stamp=779041682 input archive log thread=1 sequence=6 recid=4 stamp=779041819 input archive log thread=1 sequence=7 recid=5 stamp=779041826 input archive log thread=1 sequence=8 recid=6 stamp=779042475 input archive log thread=1 sequence=9 recid=7 stamp=779103144 input archive log thread=1 sequence=10 recid=8 stamp=779103145 channel c1: starting piece 1 at 28-MAR-12 channel c1: finished piece 1 at 28-MAR-12 piece handle=/orabackup/arch_ZHONG_0tn70at9_1_1 tag=BKARCH comment=NONE channel c1: backup set complete, elapsed time: 00:00:05 channel c1: deleting archive log(s) archive log filename=/arch/1_5_778974618.dbf recid=3 stamp=779041682 archive log filename=/arch/1_6_778974618.dbf recid=4 stamp=779041819 archive log filename=/arch/1_7_778974618.dbf recid=5 stamp=779041826 archive log filename=/arch/1_8_778974618.dbf recid=6 stamp=779042475 archive log filename=/arch/1_9_778974618.dbf recid=7 stamp=779103144 archive log filename=/arch/1_10_778974618.dbf recid=8 stamp=779103145 Finished backup at 28-MAR-12 Starting Control File and SPFILE Autobackup at 28-MAR-12 piece handle=/u01/app/oracle/product/10.2.0/db_1/dbs/c-1447686871-20120328-01 comment=NONE Finished Control File and SPFILE Autobackup at 28-MAR-12 released channel: c1 executing global script: global_bkctl allocated channel: c1 channel c1: sid=140 devtype=DISK Starting backup at 28-MAR-12 channel c1: starting compressed full datafile backupset channel c1: specifying datafile(s) in backupset including current control file in backupset channel c1: starting piece 1 at 28-MAR-12 channel c1: finished piece 1 at 28-MAR-12 piece handle=/orabackup/backupctl.ctl tag=BKCTL comment=NONE channel c1: backup set complete, elapsed time: 00:00:01 Finished backup at 28-MAR-12 Starting Control File and SPFILE Autobackup at 28-MAR-12 piece handle=/u01/app/oracle/product/10.2.0/db_1/dbs/c-1447686871-20120328-02 comment=NONE Finished Control File and SPFILE Autobackup at 28-MAR-12 released channel: c1 executing global script: global_inc1 executing global script: global_del allocated channel: c1 channel c1: sid=140 devtype=DISK no obsolete backups found released channel: c1 allocated channel: c1 channel c1: sid=140 devtype=DISK Starting backup at 28-MAR-12 channel c1: starting compressed incremental level 1 datafile backupset channel c1: specifying datafile(s) in backupset input datafile fno=00001 name=/u01/app/oracle/oradata/zhong/system01.dbf input datafile fno=00003 name=/u01/app/oracle/oradata/zhong/sysaux01.dbf input datafile fno=00005 name=/u01/app/oracle/oradata/zhong/example01.dbf input datafile fno=00002 name=/u01/app/oracle/oradata/zhong/undotbs01.dbf input datafile fno=00004 name=/u01/app/oracle/oradata/zhong/users01.dbf channel c1: starting piece 1 at 28-MAR-12 channel c1: finished piece 1 at 28-MAR-12 piece handle=/orabackup/inc1_ZHONG_11n70atm_1_1 tag=INC1 comment=NONE channel c1: backup set complete, elapsed time: 00:00:03 Finished backup at 28-MAR-12 Starting Control File and SPFILE Autobackup at 28-MAR-12 piece handle=/u01/app/oracle/product/10.2.0/db_1/dbs/c-1447686871-20120328-03 comment=NONE Finished Control File and SPFILE Autobackup at 28-MAR-12 released channel: c1 executing global script: global_arch allocated channel: c1 channel c1: sid=140 devtype=DISK sql statement: alter system archive log current Starting backup at 28-MAR-12 current log archived channel c1: starting compressed archive log backupset channel c1: specifying archive log(s) in backup set input archive log thread=1 sequence=11 recid=9 stamp=779103165 input archive log thread=1 sequence=12 recid=10 stamp=779103165 channel c1: starting piece 1 at 28-MAR-12 channel c1: finished piece 1 at 28-MAR-12 piece handle=/orabackup/arch_ZHONG_13n70atu_1_1 tag=BKARCH comment=NONE channel c1: backup set complete, elapsed time: 00:00:02 channel c1: deleting archive log(s) archive log filename=/arch/1_11_778974618.dbf recid=9 stamp=779103165 archive log filename=/arch/1_12_778974618.dbf recid=10 stamp=779103165 Finished backup at 28-MAR-12 Starting Control File and SPFILE Autobackup at 28-MAR-12 piece handle=/u01/app/oracle/product/10.2.0/db_1/dbs/c-1447686871-20120328-04 comment=NONE Finished Control File and SPFILE Autobackup at 28-MAR-12 released channel: c1 executing global script: global_bkctl allocated channel: c1 channel c1: sid=140 devtype=DISK Starting backup at 28-MAR-12 channel c1: starting compressed full datafile backupset channel c1: specifying datafile(s) in backupset including current control file in backupset channel c1: starting piece 1 at 28-MAR-12 channel c1: finished piece 1 at 28-MAR-12 piece handle=/orabackup/backupctl.ctl tag=BKCTL comment=NONE channel c1: backup set complete, elapsed time: 00:00:01 Finished backup at 28-MAR-12 Starting Control File and SPFILE Autobackup at 28-MAR-12 piece handle=/u01/app/oracle/product/10.2.0/db_1/dbs/c-1447686871-20120328-05 comment=NONE Finished Control File and SPFILE Autobackup at 28-MAR-12 released channel: c1 executing global script: global_inc2 executing global script: global_del allocated channel: c1 channel c1: sid=140 devtype=DISK no obsolete backups found released channel: c1 allocated channel: c1 channel c1: sid=140 devtype=DISK Starting backup at 28-MAR-12 channel c1: starting compressed incremental level 2 datafile backupset channel c1: specifying datafile(s) in backupset input datafile fno=00001 name=/u01/app/oracle/oradata/zhong/system01.dbf input datafile fno=00003 name=/u01/app/oracle/oradata/zhong/sysaux01.dbf input datafile fno=00005 name=/u01/app/oracle/oradata/zhong/example01.dbf input datafile fno=00002 name=/u01/app/oracle/oradata/zhong/undotbs01.dbf input datafile fno=00004 name=/u01/app/oracle/oradata/zhong/users01.dbf channel c1: starting piece 1 at 28-MAR-12 channel c1: finished piece 1 at 28-MAR-12 piece handle=/orabackup/inc2_ZHONG_17n70au7_1_1 tag=INC2 comment=NONE channel c1: backup set complete, elapsed time: 00:00:03 Finished backup at 28-MAR-12 Starting Control File and SPFILE Autobackup at 28-MAR-12 piece handle=/u01/app/oracle/product/10.2.0/db_1/dbs/c-1447686871-20120328-06 comment=NONE Finished Control File and SPFILE Autobackup at 28-MAR-12 released channel: c1 executing global script: global_arch allocated channel: c1 channel c1: sid=140 devtype=DISK sql statement: alter system archive log current Starting backup at 28-MAR-12 current log archived channel c1: starting compressed archive log backupset channel c1: specifying archive log(s) in backup set input archive log thread=1 sequence=13 recid=11 stamp=779103182 input archive log thread=1 sequence=14 recid=12 stamp=779103182 channel c1: starting piece 1 at 28-MAR-12 channel c1: finished piece 1 at 28-MAR-12 piece handle=/orabackup/arch_ZHONG_19n70auf_1_1 tag=BKARCH comment=NONE channel c1: backup set complete, elapsed time: 00:00:02 channel c1: deleting archive log(s) archive log filename=/arch/1_13_778974618.dbf recid=11 stamp=779103182 archive log filename=/arch/1_14_778974618.dbf recid=12 stamp=779103182 Finished backup at 28-MAR-12 Starting Control File and SPFILE Autobackup at 28-MAR-12 piece handle=/u01/app/oracle/product/10.2.0/db_1/dbs/c-1447686871-20120328-07 comment=NONE Finished Control File and SPFILE Autobackup at 28-MAR-12 released channel: c1 executing global script: global_bkctl allocated channel: c1 channel c1: sid=140 devtype=DISK Starting backup at 28-MAR-12 channel c1: starting compressed full datafile backupset channel c1: specifying datafile(s) in backupset including current control file in backupset channel c1: starting piece 1 at 28-MAR-12 channel c1: finished piece 1 at 28-MAR-12 piece handle=/orabackup/backupctl.ctl tag=BKCTL comment=NONE channel c1: backup set complete, elapsed time: 00:00:01 Finished backup at 28-MAR-12 Starting Control File and SPFILE Autobackup at 28-MAR-12 piece handle=/u01/app/oracle/product/10.2.0/db_1/dbs/c-1447686871-20120328-08 comment=NONE Finished Control File and SPFILE Autobackup at 28-MAR-12 released channel: c1 RMAN>
[oracle@zhong ~]$ ll -trh /orabackup/ total 129M -rw-r----- 1 oracle oinstall 115M Mar 28 09:32 inc0_ZHONG_0rn70asb_1_1 -rw-r----- 1 oracle oinstall 13M Mar 28 09:32 arch_ZHONG_0tn70at9_1_1 -rw-r----- 1 oracle oinstall 72K Mar 28 09:32 inc1_ZHONG_11n70atm_1_1 -rw-r----- 1 oracle oinstall 3.0K Mar 28 09:32 arch_ZHONG_13n70atu_1_1 -rw-r----- 1 oracle oinstall 72K Mar 28 09:32 inc2_ZHONG_17n70au7_1_1 -rw-r----- 1 oracle oinstall 3.0K Mar 28 09:33 arch_ZHONG_19n70auf_1_1 -rw-r----- 1 oracle oinstall 1.1M Mar 28 09:33 backupctl.ctl [oracle@zhong ~]$
[oracle@catalog scripts]$ cat connect.rcv connect catalog cataloguser/cataloguser; connect target sys/oracle@zhong;
[oracle@catalog scripts]$ cat inc0.rcv @@/scripts/connect.rcv run { execute global script global_inc0; } exit
[oracle@catalog scripts]$ cat inc1.rcv @@/scripts/connect.rcv run { execute global script global_inc1; } exit
[oracle@catalog scripts]$ cat inc2.rcv @@/scripts/connect.rcv run { execute global script global_inc2; } exit
[oracle@catalog scripts]$ cat inc0.sh #!/bin/sh nohup /u01/app/oracle/product/10.2.0/db_1/bin/rman cmdfile=/scripts/inc0.rcv log=/scripts/inc0.log append &
[oracle@catalog scripts]$ cat inc1.sh #!/bin/sh nohup /u01/app/oracle/product/10.2.0/db_1/bin/rman cmdfile=/scripts/inc1.rcv log=/scripts/inc1.log append &
[oracle@catalog scripts]$ cat inc2.sh #!/bin/sh nohup /u01/app/oracle/product/10.2.0/db_1/bin/rman cmdfile=/scripts/inc2.rcv log=/scripts/inc2.log append &
[oracle@catalog scripts]$ crontab -l 0 1 * * 0 /scripts/inc0.sh >/dev/null 2>&1 0 1 * * 1 /scripts/inc2.sh >/dev/null 2>&1 0 1 * * 2 /scripts/inc2.sh >/dev/null 2>&1 0 1 * * 3 /scripts/inc2.sh >/dev/null 2>&1 0 1 * * 4 /scripts/inc1.sh >/dev/null 2>&1 0 1 * * 5 /scripts/inc2.sh >/dev/null 2>&1 0 1 * * 6 /scripts/inc2.sh >/dev/null 2>&1
[oracle@catalog scripts]$ /scripts/inc0.sh [oracle@catalog scripts]$ nohup: appending output to `nohup.out' [oracle@catalog scripts]$ /scripts/inc1.sh nohup: appending output to `nohup.out' [oracle@catalog scripts]$ /scripts/inc2.sh nohup: appending output to `nohup.out'
[oracle@catalog scripts]$ cat inc0.log Recovery Manager: Release 10.2.0.1.0 - Production on Wed Mar 28 10:17:53 2012 Copyright (c) 1982, 2005, Oracle. All rights reserved. RMAN> @@/scripts/connect.rcv 2> connect catalog * 3> connect target * 4> **end-of-file** 5> run { 6> execute global script global_inc0; 7> } 8> exit connected to recovery catalog database connected to target database: ZHONG (DBID=1447686871) executing global script: global_inc0 executing global script: global_del allocated channel: c1 channel c1: sid=139 devtype=DISK no obsolete backups found released channel: c1 allocated channel: c1 channel c1: sid=139 devtype=DISK Starting backup at 28-MAR-12 channel c1: starting compressed incremental level 0 datafile backupset channel c1: specifying datafile(s) in backupset input datafile fno=00001 name=/u01/app/oracle/oradata/zhong/system01.dbf input datafile fno=00003 name=/u01/app/oracle/oradata/zhong/sysaux01.dbf input datafile fno=00005 name=/u01/app/oracle/oradata/zhong/example01.dbf input datafile fno=00002 name=/u01/app/oracle/oradata/zhong/undotbs01.dbf input datafile fno=00004 name=/u01/app/oracle/oradata/zhong/users01.dbf channel c1: starting piece 1 at 28-MAR-12 channel c1: finished piece 1 at 28-MAR-12 piece handle=/orabackup/inc0_ZHONG_1dn70dii_1_1 tag=INC0 comment=NONE channel c1: backup set complete, elapsed time: 00:00:25 channel c1: starting compressed incremental level 0 datafile backupset channel c1: specifying datafile(s) in backupset including current control file in backupset including current SPFILE in backupset channel c1: starting piece 1 at 28-MAR-12 channel c1: finished piece 1 at 28-MAR-12 piece handle=/orabackup/inc0_ZHONG_1en70djb_1_1 tag=INC0 comment=NONE channel c1: backup set complete, elapsed time: 00:00:01 Finished backup at 28-MAR-12 released channel: c1 executing global script: global_arch allocated channel: c1 channel c1: sid=139 devtype=DISK sql statement: alter system archive log current Starting backup at 28-MAR-12 current log archived channel c1: starting compressed archive log backupset channel c1: specifying archive log(s) in backup set input archive log thread=1 sequence=15 recid=13 stamp=779105902 input archive log thread=1 sequence=16 recid=14 stamp=779105902 channel c1: starting piece 1 at 28-MAR-12 channel c1: finished piece 1 at 28-MAR-12 piece handle=/orabackup/arch_ZHONG_1fn70djf_1_1 tag=BKARCH comment=NONE channel c1: backup set complete, elapsed time: 00:00:02 channel c1: deleting archive log(s) archive log filename=/arch/1_15_778974618.dbf recid=13 stamp=779105902 archive log filename=/arch/1_16_778974618.dbf recid=14 stamp=779105902 Finished backup at 28-MAR-12 released channel: c1 executing global script: global_bkctl allocated channel: c1 channel c1: sid=139 devtype=DISK Starting backup at 28-MAR-12 channel c1: starting compressed full datafile backupset channel c1: specifying datafile(s) in backupset including current control file in backupset channel c1: starting piece 1 at 28-MAR-12 channel c1: finished piece 1 at 28-MAR-12 piece handle=/orabackup/backupctl.ctl tag=BKCTL comment=NONE channel c1: backup set complete, elapsed time: 00:00:01 Finished backup at 28-MAR-12 released channel: c1 Recovery Manager complete.
RMAN> list backupset summary; List of Backups =============== Key TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag ------- -- -- - ----------- --------------- ------- ------- ---------- --- 1783 B 0 A DISK 28-MAR-12 1 1 YES INC0 1784 B 0 A DISK 28-MAR-12 1 1 YES INC0 1812 B A A DISK 28-MAR-12 1 1 YES BKARCH 1839 B 1 A DISK 28-MAR-12 1 1 YES INC1 1840 B 1 A DISK 28-MAR-12 1 1 YES INC1 1869 B A A DISK 28-MAR-12 1 1 YES BKARCH 1896 B 2 A DISK 28-MAR-12 1 1 YES INC2 1897 B 2 A DISK 28-MAR-12 1 1 YES INC2 1926 B A A DISK 28-MAR-12 1 1 YES BKARCH 1938 B F A DISK 28-MAR-12 1 1 YES BKCTL RMAN>
[oracle@zhong ~]$ ll -trh /orabackup/ total 121M -rw-r----- 1 oracle oinstall 115M Mar 28 10:18 inc0_ZHONG_1dn70dii_1_1 -rw-r----- 1 oracle oinstall 1.1M Mar 28 10:18 inc0_ZHONG_1en70djb_1_1 -rw-r----- 1 oracle oinstall 696K Mar 28 10:18 arch_ZHONG_1fn70djf_1_1 -rw-r----- 1 oracle oinstall 72K Mar 28 10:18 inc1_ZHONG_1hn70dke_1_1 -rw-r----- 1 oracle oinstall 1.1M Mar 28 10:18 inc1_ZHONG_1in70dkh_1_1 -rw-r----- 1 oracle oinstall 3.0K Mar 28 10:19 arch_ZHONG_1jn70dkm_1_1 -rw-r----- 1 oracle oinstall 208K Mar 28 10:19 inc2_ZHONG_1ln70dlm_1_1 -rw-r----- 1 oracle oinstall 1.1M Mar 28 10:19 inc2_ZHONG_1mn70dlp_1_1 -rw-r----- 1 oracle oinstall 14K Mar 28 10:19 arch_ZHONG_1nn70dlu_1_1 -rw-r----- 1 oracle oinstall 1.1M Mar 28 10:19 backupctl.ctl