rman儲存指令碼
儲存指令碼是命令檔案的一種替方法用來管理頻繁使用的一系列RMAN命令。儲存指令碼相比命令檔案來說它的優點就是對於任何連線到目標資料庫和恢復目錄的RMAN客戶端都能夠使用它。而命令檔案只有能夠訪問它的RMAN客戶端能夠使用。
儲存指令碼可以是全域性或者區域性指令碼。一個局儲存指令碼與建立該指令碼時RMAN所連線的目標資料庫相關,只能當連線到該目標資料庫時才能執行儲存指令碼。一個全域性的儲存指令碼能在恢復目錄中所註冊的所有資料庫中執行。注意執行儲存指令碼,即使是全域性儲存指令碼,也必須連線到恢復目錄和目標例項才能執行。
建立儲存指令碼
確保RMAN連線到正確的目標資料庫和恢復目錄,然後執行create script命令來建立區域性儲存指令碼。例如:
create script full_backup { backup as backupset database plus archivelog; delete obsolete; } RMAN> create script full_backup 2> { 3> backup as backupset database plus archivelog; 4> delete obsolete; 5> } created script full_backup
執行建立命令如果沒有輸出錯誤資訊,那麼該儲存指令碼full_backup就建立成功並儲存在恢復目錄中。
下面建立一個全域性儲存指令碼,如下所示:
create global script global_full_backup { backup as backupset database plus archivelog; delete obsolete; } RMAN> create global script global_full_backup 2> { 3> backup as backupset database plus archivelog; 4> delete obsolete; 5> } created global script global_full_backup
還可以提供了comment來描述全域性儲存指令碼:
create global script global_full_backup comment 'use only with archivelog mode database' { backup as backupset database plus archivelog; delete obsolete; } RMAN> create global script global_full_backup 2> comment 'use only with archivelog mode database' 3> { 4> backup as backupset database plus archivelog; 5> delete obsolete; 6> } created global script global_full_backup
還可以讀取文字檔案來建立區域性或全域性儲存指令碼:
RMAN> create script test_script from file '/u01/app/oracle/test_script_file.txt'; script commands will be loaded from file /u01/app/oracle/test_script_file.txt created script test_script RMAN> create global script global_test_script from file '/u01/app/oracle/test_script_file.txt'; script commands will be loaded from file /u01/app/oracle/test_script_file.txt created global script global_test_script
文字檔案內賓3必須以{開始,再接RUN塊中的一系列有效的命令,最後以}結束。
執行儲存指令碼
為了執行儲存指令碼,連線到目標資料庫和恢復目錄,使用execute script命令,execute script命令要求使用RUN塊:
RMAN> run 2> { 3> execute script full_backup; 4> } executing script: full_backup Starting backup at 18-MAR-15 current log archived allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=145 devtype=DISK channel ORA_DISK_1: starting archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set input archive log thread=1 sequence=1 recid=9 stamp=871547115 input archive log thread=1 sequence=2 recid=10 stamp=872692777 input archive log thread=1 sequence=3 recid=11 stamp=873390010 input archive log thread=1 sequence=4 recid=12 stamp=873477689 input archive log thread=1 sequence=5 recid=13 stamp=873557205 input archive log thread=1 sequence=6 recid=14 stamp=873628154 input archive log thread=1 sequence=7 recid=15 stamp=873881476 input archive log thread=1 sequence=8 recid=16 stamp=873969596 input archive log thread=1 sequence=9 recid=17 stamp=874234871 input archive log thread=1 sequence=10 recid=18 stamp=874315436 input archive log thread=1 sequence=11 recid=19 stamp=874486364 input archive log thread=1 sequence=12 recid=20 stamp=874574023 input archive log thread=1 sequence=13 recid=21 stamp=874579545 input archive log thread=1 sequence=14 recid=22 stamp=874657043 input archive log thread=1 sequence=15 recid=23 stamp=874663015 channel ORA_DISK_1: starting piece 1 at 18-MAR-15 channel ORA_DISK_1: finished piece 1 at 18-MAR-15 piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T095657_bjkpvd26_.bkp tag=TAG20150318T095657 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:27 channel ORA_DISK_1: starting archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set input archive log thread=1 sequence=44 recid=6 stamp=870948358 input archive log thread=1 sequence=45 recid=7 stamp=870948359 input archive log thread=1 sequence=46 recid=8 stamp=870948359 channel ORA_DISK_1: starting piece 1 at 18-MAR-15 channel ORA_DISK_1: finished piece 1 at 18-MAR-15 piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T095657_bjkpw6cl_.bkp tag=TAG20150318T095657 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02 Finished backup at 18-MAR-15 Starting backup at 18-MAR-15 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset input datafile fno=00001 name=/u01/app/oracle/oradata/jy/system01.dbf input datafile fno=00002 name=/u01/app/oracle/oradata/jy/undotbs01.dbf input datafile fno=00003 name=/u01/app/oracle/oradata/jy/sysaux01.dbf input datafile fno=00005 name=/u01/app/oracle/oradata/jy/example01.dbf input datafile fno=00004 name=/u01/app/oracle/oradata/jy/users01.dbf channel ORA_DISK_1: starting piece 1 at 18-MAR-15 channel ORA_DISK_1: finished piece 1 at 18-MAR-15 piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_nnndf_TAG20150318T095727_bjkpw9xz_.bkp tag=TAG20150318T095727 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15 Finished backup at 18-MAR-15 Starting backup at 18-MAR-15 current log archived using channel ORA_DISK_1 channel ORA_DISK_1: starting archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set input archive log thread=1 sequence=16 recid=24 stamp=874663125 channel ORA_DISK_1: starting piece 1 at 18-MAR-15 channel ORA_DISK_1: finished piece 1 at 18-MAR-15 piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T095845_bjkpyqdc_.bkp tag=TAG20150318T095845 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02 Finished backup at 18-MAR-15 Starting Control File and SPFILE Autobackup at 18-MAR-15 piece handle=/u01/app/oracle/flash_recovery_area/JY/autobackup/2015_03_18/o1_mf_s_874663128_bjkpytxr_.bkp comment=NONE Finished Control File and SPFILE Autobackup at 18-MAR-15 RMAN retention policy will be applied to the command RMAN retention policy is set to redundancy 1 using channel ORA_DISK_1 Deleting the following obsolete backups and copies: Type Key Completion Time Filename/Handle -------------------- ------ ------------------ -------------------- Archive Log 3769 06-FEB-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_02_06/o1_mf_1_44_bf88d537_.arc Archive Log 3770 06-FEB-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_02_06/o1_mf_1_45_bf88d73o_.arc Archive Log 3771 06-FEB-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_02_06/o1_mf_1_46_bf88d7cv_.arc Archive Log 3772 13-FEB-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_02_13/o1_mf_1_1_bftk375y_.arc Archive Log 3773 26-FEB-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_02_26/o1_mf_1_2_bgxhx2ww_.arc Archive Log 3774 03-MAR-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_03/o1_mf_1_3_bhbvorcp_.arc Archive Log 3775 04-MAR-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_04/o1_mf_1_4_bhfk9mdr_.arc Archive Log 3776 05-MAR-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_05/o1_mf_1_5_bhhyxwnp_.arc Archive Log 3777 06-MAR-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_06/o1_mf_1_6_bhl47mgr_.arc Archive Log 3778 09-MAR-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_09/o1_mf_1_7_bhsvmzby_.arc Archive Log 3779 10-MAR-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_10/o1_mf_1_8_bhwkos6m_.arc Archive Log 3780 13-MAR-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_13/o1_mf_1_9_bj4nqm2j_.arc Archive Log 3781 14-MAR-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_14/o1_mf_1_10_bj73f7y4_.arc Archive Log 3782 16-MAR-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_16/o1_mf_1_11_bjdbbrvm_.arc Archive Log 3783 17-MAR-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_17/o1_mf_1_12_bjgzxz92_.arc Archive Log 3784 17-MAR-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_17/o1_mf_1_13_bjh5bqyo_.arc Archive Log 3785 18-MAR-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_14_bjkk0h4p_.arc Backup Set 3786 06-FEB-15 Backup Piece 3788 06-FEB-15 /u01/app/oracle/flash_recovery_area/JY/autobackup/2015_02_06/o1_mf_s_870945982_bf861zo6_.bkp Datafile Copy 3794 03-MAR-15 /u01/app/oracle/users01.dbf Backup Set 3787 06-FEB-15 Backup Piece 3789 06-FEB-15 /u01/app/oracle/flash_recovery_area/JY/autobackup/2015_02_06/o1_mf_s_870948381_bf88dyom_.bkp Archive Log 3806 18-MAR-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_15_bjkpv6py_.arc Backup Set 3813 18-MAR-15 Backup Piece 3817 18-MAR-15 /u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T095657_bjkpvd26_.bkp Backup Set 3814 18-MAR-15 Backup Piece 3818 18-MAR-15 /u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T095657_bjkpw6cl_.bkp Do you really want to delete the above objects (enter YES or NO)? YES deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_02_06/o1_mf_1_44_bf88d537_.arc recid=6 stamp=870948358 deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_02_06/o1_mf_1_45_bf88d73o_.arc recid=7 stamp=870948359 deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_02_06/o1_mf_1_46_bf88d7cv_.arc recid=8 stamp=870948359 deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_02_13/o1_mf_1_1_bftk375y_.arc recid=9 stamp=871547115 deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_02_26/o1_mf_1_2_bgxhx2ww_.arc recid=10 stamp=872692777 deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_03/o1_mf_1_3_bhbvorcp_.arc recid=11 stamp=873390010 deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_04/o1_mf_1_4_bhfk9mdr_.arc recid=12 stamp=873477689 deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_05/o1_mf_1_5_bhhyxwnp_.arc recid=13 stamp=873557205 deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_06/o1_mf_1_6_bhl47mgr_.arc recid=14 stamp=873628154 deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_09/o1_mf_1_7_bhsvmzby_.arc recid=15 stamp=873881476 deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_10/o1_mf_1_8_bhwkos6m_.arc recid=16 stamp=873969596 deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_13/o1_mf_1_9_bj4nqm2j_.arc recid=17 stamp=874234871 deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_14/o1_mf_1_10_bj73f7y4_.arc recid=18 stamp=874315436 deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_16/o1_mf_1_11_bjdbbrvm_.arc recid=19 stamp=874486364 deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_17/o1_mf_1_12_bjgzxz92_.arc recid=20 stamp=874574023 deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_17/o1_mf_1_13_bjh5bqyo_.arc recid=21 stamp=874579545 deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_14_bjkk0h4p_.arc recid=22 stamp=874657043 deleted backup piece backup piece handle=/u01/app/oracle/flash_recovery_area/JY/autobackup/2015_02_06/o1_mf_s_870945982_bf861zo6_.bkp recid=4 stamp=870948272 deleted datafile copy datafile copy filename=/u01/app/oracle/users01.dbf recid=2 stamp=873392067 deleted backup piece backup piece handle=/u01/app/oracle/flash_recovery_area/JY/autobackup/2015_02_06/o1_mf_s_870948381_bf88dyom_.bkp recid=5 stamp=870948382 deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_15_bjkpv6py_.arc recid=23 stamp=874663015 deleted backup piece backup piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T095657_bjkpvd26_.bkp recid=6 stamp=874663020 deleted backup piece backup piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T095657_bjkpw6cl_.bkp recid=7 stamp=874663046 Deleted 23 objects
上面的命令將呼叫指定名稱的區域性指令碼full_script。如果沒有找到區域性指令碼,但存在相同名稱的全域性指令碼,RMAN將執行同名的全域性儲存指令碼。如果存在同名的區域性和全域性指令碼可以使用execute global script來控制只執行全域性指令碼。在恢復目錄中沒有名叫global_full_backup的區域性指令碼存在,那麼執行下面兩個命令的結果是一樣的:
RMAN> run 2> { 3> execute global script global_full_backup; 4> } executing global script: global_full_backup Starting backup at 18-MAR-15 current log archived using channel ORA_DISK_1 channel ORA_DISK_1: starting archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set input archive log thread=1 sequence=16 recid=24 stamp=874663125 input archive log thread=1 sequence=17 recid=25 stamp=874663571 channel ORA_DISK_1: starting piece 1 at 18-MAR-15 channel ORA_DISK_1: finished piece 1 at 18-MAR-15 piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T100613_bjkqdppq_.bkp tag=TAG20150318T100613 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02 Finished backup at 18-MAR-15 Starting backup at 18-MAR-15 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset input datafile fno=00001 name=/u01/app/oracle/oradata/jy/system01.dbf input datafile fno=00002 name=/u01/app/oracle/oradata/jy/undotbs01.dbf input datafile fno=00003 name=/u01/app/oracle/oradata/jy/sysaux01.dbf input datafile fno=00005 name=/u01/app/oracle/oradata/jy/example01.dbf input datafile fno=00004 name=/u01/app/oracle/oradata/jy/users01.dbf channel ORA_DISK_1: starting piece 1 at 18-MAR-15 channel ORA_DISK_1: finished piece 1 at 18-MAR-15 piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_nnndf_TAG20150318T100615_bjkqds89_.bkp tag=TAG20150318T100615 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15 Finished backup at 18-MAR-15 Starting backup at 18-MAR-15 current log archived using channel ORA_DISK_1 channel ORA_DISK_1: starting archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set input archive log thread=1 sequence=18 recid=26 stamp=874663651 channel ORA_DISK_1: starting piece 1 at 18-MAR-15 channel ORA_DISK_1: finished piece 1 at 18-MAR-15 piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T100732_bjkqh6cv_.bkp tag=TAG20150318T100732 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02 Finished backup at 18-MAR-15 Starting Control File and SPFILE Autobackup at 18-MAR-15 piece handle=/u01/app/oracle/flash_recovery_area/JY/autobackup/2015_03_18/o1_mf_s_874663655_bjkqh9db_.bkp comment=NONE Finished Control File and SPFILE Autobackup at 18-MAR-15 RMAN retention policy will be applied to the command RMAN retention policy is set to redundancy 1 using channel ORA_DISK_1 Deleting the following obsolete backups and copies: Type Key Completion Time Filename/Handle -------------------- ------ ------------------ -------------------- Archive Log 3845 18-MAR-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_16_bjkpynv3_.arc Backup Set 3846 18-MAR-15 Backup Piece 3850 18-MAR-15 /u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_nnndf_TAG20150318T095727_bjkpw9xz_.bkp Backup Set 3864 18-MAR-15 Backup Piece 3870 18-MAR-15 /u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T095845_bjkpyqdc_.bkp Archive Log 3913 18-MAR-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_17_bjkqdmto_.arc Backup Set 3880 18-MAR-15 Backup Piece 3882 18-MAR-15 /u01/app/oracle/flash_recovery_area/JY/autobackup/2015_03_18/o1_mf_s_874663128_bjkpytxr_.bkp Backup Set 3925 18-MAR-15 Backup Piece 3928 18-MAR-15 /u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T100613_bjkqdppq_.bkp Do you really want to delete the above objects (enter YES or NO)? yes deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_16_bjkpynv3_.arc recid=24 stamp=874663125 deleted backup piece backup piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_nnndf_TAG20150318T095727_bjkpw9xz_.bkp recid=8 stamp=874663049 deleted backup piece backup piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T095845_bjkpyqdc_.bkp recid=9 stamp=874663127 deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_17_bjkqdmto_.arc recid=25 stamp=874663571 deleted backup piece backup piece handle=/u01/app/oracle/flash_recovery_area/JY/autobackup/2015_03_18/o1_mf_s_874663128_bjkpytxr_.bkp recid=10 stamp=874663130 deleted backup piece backup piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T100613_bjkqdppq_.bkp recid=11 stamp=874663574 Deleted 6 objects RMAN> run 2> { 3> execute script global_full_backup; 4> } executing global script: global_full_backup Starting backup at 18-MAR-15 current log archived using channel ORA_DISK_1 channel ORA_DISK_1: starting archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set input archive log thread=1 sequence=18 recid=26 stamp=874663651 input archive log thread=1 sequence=19 recid=27 stamp=874664008 channel ORA_DISK_1: starting piece 1 at 18-MAR-15 channel ORA_DISK_1: finished piece 1 at 18-MAR-15 piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T101329_bjkqtbtn_.bkp tag=TAG20150318T101329 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02 Finished backup at 18-MAR-15 Starting backup at 18-MAR-15 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset input datafile fno=00001 name=/u01/app/oracle/oradata/jy/system01.dbf input datafile fno=00002 name=/u01/app/oracle/oradata/jy/undotbs01.dbf input datafile fno=00003 name=/u01/app/oracle/oradata/jy/sysaux01.dbf input datafile fno=00005 name=/u01/app/oracle/oradata/jy/example01.dbf input datafile fno=00004 name=/u01/app/oracle/oradata/jy/users01.dbf channel ORA_DISK_1: starting piece 1 at 18-MAR-15 channel ORA_DISK_1: finished piece 1 at 18-MAR-15 piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_nnndf_TAG20150318T101331_bjkqtdoh_.bkp tag=TAG20150318T101331 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:01:05 Finished backup at 18-MAR-15 Starting backup at 18-MAR-15 current log archived using channel ORA_DISK_1 channel ORA_DISK_1: starting archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set input archive log thread=1 sequence=20 recid=28 stamp=874664078 channel ORA_DISK_1: starting piece 1 at 18-MAR-15 channel ORA_DISK_1: finished piece 1 at 18-MAR-15 piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T101439_bjkqwjl4_.bkp tag=TAG20150318T101439 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02 Finished backup at 18-MAR-15 Starting Control File and SPFILE Autobackup at 18-MAR-15 piece handle=/u01/app/oracle/flash_recovery_area/JY/autobackup/2015_03_18/o1_mf_s_874664082_bjkqwmhg_.bkp comment=NONE Finished Control File and SPFILE Autobackup at 18-MAR-15 RMAN retention policy will be applied to the command RMAN retention policy is set to redundancy 1 using channel ORA_DISK_1 Deleting the following obsolete backups and copies: Type Key Completion Time Filename/Handle -------------------- ------ ------------------ -------------------- Archive Log 3944 18-MAR-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_18_bjkqh3ov_.arc Backup Set 3945 18-MAR-15 Backup Piece 3948 18-MAR-15 /u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_nnndf_TAG20150318T100615_bjkqds89_.bkp Backup Set 3967 18-MAR-15 Backup Piece 3973 18-MAR-15 /u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T100732_bjkqh6cv_.bkp Archive Log 4036 18-MAR-15 /u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_19_bjkqt8p5_.arc Backup Set 3988 18-MAR-15 Backup Piece 3990 18-MAR-15 /u01/app/oracle/flash_recovery_area/JY/autobackup/2015_03_18/o1_mf_s_874663655_bjkqh9db_.bkp Backup Set 4053 18-MAR-15 Backup Piece 4056 18-MAR-15 /u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T101329_bjkqtbtn_.bkp Do you really want to delete the above objects (enter YES or NO)? YES deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_18_bjkqh3ov_.arc recid=26 stamp=874663651 deleted backup piece backup piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_nnndf_TAG20150318T100615_bjkqds89_.bkp recid=12 stamp=874663576 deleted backup piece backup piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T100732_bjkqh6cv_.bkp recid=13 stamp=874663654 deleted archive log archive log filename=/u01/app/oracle/flash_recovery_area/JY/archivelog/2015_03_18/o1_mf_1_19_bjkqt8p5_.arc recid=27 stamp=874664008 deleted backup piece backup piece handle=/u01/app/oracle/flash_recovery_area/JY/autobackup/2015_03_18/o1_mf_s_874663655_bjkqh9db_.bkp recid=14 stamp=874663657 deleted backup piece backup piece handle=/u01/app/oracle/flash_recovery_area/JY/backupset/2015_03_18/o1_mf_annnn_TAG20150318T101329_bjkqtbtn_.bkp recid=15 stamp=874664010 Deleted 6 objects
在執行全域性指令碼隻影響RMAN所連線到的目標資料庫;為了跨多個資料庫執行全域性指令碼,必須單獨連線到每一個資料庫並執行全域性儲存指令碼。
在執行指令碼時將會使用配置的自動通道來執行指令碼。如果需要覆蓋配置的自動通道可以在指令碼中使用allocate channel命令來手動分配通道。注意因為使用的是RUN塊,如果指令碼中的一個RMAN命令失敗,指令碼中的後續命令將不會執行。
檢視儲存指令碼內容
print script命令用來檢視儲存指令碼或將指令碼內容寫入到新檔案。使用RMAN連線到目標資料庫和恢復目錄。執行print script:
RMAN> print script full_backup; printing stored script: full_backup {backup as backupset database plus archivelog; delete obsolete; } 顯示全域性指令碼內容: RMAN> print global script global_full_backup; printing stored global script: global_full_backup {backup as backupset database plus archivelog; delete obsolete; }
為將指令碼內容寫入到新檔案中,執行以下命令:
RMAN> print script full_backup to file '/u01/app/oracle/full_backup.txt'; script full_backup written to file /u01/app/oracle/full_backup.txt
將全域性指令碼內容寫入檔案:
RMAN> print global script global_full_backup to file '/u01/app/oracle/global_full_backup.txt'; global script global_full_backup written to file /u01/app/oracle/global_full_backup.txt
檢視恢復目錄中的儲存指令碼:list script names
使用list script names命令來顯示恢復目錄中的儲存指令碼名。這個命令會顯示所有儲存指令碼名。
RMAN> list script names; List of Stored Scripts in Recovery Catalog Scripts of Target Database JY Script Name Description ----------------------------------------------------------------------- full_backup Global Scripts Script Name Description ----------------------------------------------------------------------- global_full_backup use only with archivelog mode database
只顯示全域性儲存指令碼名:
RMAN> list global script names; List of Stored Scripts in Recovery Catalog Global Scripts Script Name Description ----------------------------------------------------------------------- global_full_backup use only with archivelog mode database
為了檢視當前恢復目錄中所有儲存指令碼的名稱,包括在恢復目錄中所有已經註冊的目標資料庫的全域性和區域性指令碼,執行以下命令:
RMAN> list all script names; List of Stored Scripts in Recovery Catalog Global Scripts Script Name Description ----------------------------------------------------------------------- global_full_backup use only with archivelog mode database Scripts of Target Database JY Script Name Description ----------------------------------------------------------------------- full_backup Scripts of Target Database TEST Script Name Description ----------------------------------------------------------------------- test_full_backup
可以看到上面顯示了兩個目標資料庫(jy,test)中的所有儲存指令碼
更新儲存指令碼
為了更新儲存指令碼,連線到目標資料庫和恢復目錄並使用replace script命令來執行更新。如果指令碼不存在,那麼RMAN將會建立一個新儲存指令碼。
下面的命令用來更新指令碼full_backup的內容:
先來檢視恢復目錄中所有儲存指令碼名來檢查是否存在full_backup指令碼
RMAN> list all script names; List of Stored Scripts in Recovery Catalog Global Scripts Script Name Description ----------------------------------------------------------------------- global_full_backup use only with archivelog mode database Scripts of Target Database JY Script Name Description ----------------------------------------------------------------------- full_backup Scripts of Target Database TEST Script Name Description ----------------------------------------------------------------------- test_full_backup
檢視指令碼full_backup的內容
RMAN> print script full_backup; printing stored script: full_backup {backup as backupset database plus archivelog; delete obsolete; } 更新指令碼full_backup RMAN> replace script full_backup 2> { 3> backup as backupset database plus archivelog; 4> } replaced script full_backup
檢查指令碼full_backup是否已經被更新
RMAN> print script full_backup; printing stored script: full_backup {backup as backupset database plus archivelog; }
從指令碼內容可知full_backup內容確實已經被更新.
下面來更新一個不存在的指令碼full_backup_bak
RMAN> replace script full_backup_update 2> { 3> backup as backupset database plus archivelog; 4> } replaced script full_backup_update
從下面的資訊中可以看到當更新一個不存在的指令碼,RMAN確實會建立這個指令碼
RMAN> list all script names; List of Stored Scripts in Recovery Catalog Global Scripts Script Name Description ----------------------------------------------------------------------- global_full_backup use only with archivelog mode database Scripts of Target Database JY Script Name Description ----------------------------------------------------------------------- full_backup full_backup_update Scripts of Target Database TEST Script Name Description ----------------------------------------------------------------------- test_full_backup RMAN> print script full_backup_update; printing stored script: full_backup_update {backup as backupset database plus archivelog; }
全域性儲存指令碼可以使用replace global script命令來進行更新:
檢視更新前global_full_backup指令碼的內容
RMAN> print script global_full_backup; printing stored global script: global_full_backup {backup as backupset database plus archivelog; delete obsolete; }
更新全域性指令碼global_full_backup
RMAN> replace global script global_full_backup 2> { 3> backup as backupset database plus archivelog; 4> } replaced global script global_full_backup
顯示更新後全域性指令碼global_full_backup的內容
RMAN> print global script global_full_backup; printing stored global script: global_full_backup {backup as backupset database plus archivelog; }
與create script命令一樣,可以使用檔案來更新區域性或全域性儲存指令碼。
更新前檢視全域性指令碼global_full_backup的內容
RMAN> print global script global_full_backup; printing stored global script: global_full_backup {backup as backupset database plus archivelog; }
使用global_full_backup.txt檔案來更新全域性指令碼global_full_backup
RMAN> replace global script global_full_backup from file '/u01/app/oracle/global_full_backup.txt'; script commands will be loaded from file /u01/app/oracle/global_full_backup.txt replaced global script global_full_backup
檢視更新後的指令碼內容:
RMAN> print global script global_full_backup; printing stored global script: global_full_backup {backup as backupset database plus archivelog; delete obsolete; }
更新前檢視區域性指令碼full_backup的內容
RMAN> print script full_backup; printing stored script: full_backup {backup as backupset database plus archivelog; }
使用full_backup.txt檔案來更新區域性指令碼full_backup
RMAN> replace script full_backup from file '/u01/app/oracle/full_backup.txt'; script commands will be loaded from file /u01/app/oracle/full_backup.txt replaced script full_backup
檢視更新後的指令碼內容:
RMAN> print script full_backup; printing stored script: full_backup {backup as backupset database plus archivelog; delete obsolete; }
刪除儲存指令碼
為了從恢復目錄中刪除儲存指令碼,連線恢復目錄和目標資料庫後執行delete script命令:
RMAN> list script names; List of Stored Scripts in Recovery Catalog Scripts of Target Database JY Script Name Description ----------------------------------------------------------------------- full_backup full_backup_update Global Scripts Script Name Description ----------------------------------------------------------------------- global_full_backup
為了從恢復目錄中刪除區域性儲存指令碼full_backup
RMAN> delete script 'full_backup'; deleted script: full_backup
為了刪除全域性儲存指令碼global_full_backup,執行delete global script:
RMAN> delete global script 'global_full_backup'; deleted global script: global_full_backup
如果沒有給delete script命令指定global引數,並且目標資料庫中沒有指定名稱的儲存指令碼存在,RMAN將使用指定名稱來查詢全域性儲存指令碼如果找到就將其刪除。因此為了刪除全域性儲存指令碼也可以執行以下的命令:
RMAN> delete script 'global_full_backup'; deleted script: global_full_backup
對於delete script 'global_full_backup'命令,RMAN會在連線到的目標資料庫中查詢指令碼'global_full_backup',如果沒有找到,將會搜尋名為'global_full_backup'的全域性指令碼,如果找到就將其刪除。
啟動RMAN客戶端並執行儲存指令碼
為了執行RMAN客戶端並執行儲存在恢復目錄中的儲存指令碼,可以使用script引數來啟動RMAN客戶端:
[oracle@oracle11g ~]$ rman target sys/zzh_2046@test catalog rman/rman@jy script 'global_full_backup' Recovery Manager: Release 10.2.0.5.0 - Production on Wed Mar 18 11:22:04 2015 Copyright (c) 1982, 2007, Oracle. All rights reserved. connected to target database: TEST (DBID=2168949517) connected to recovery catalog database executing global script: global_full_backup Starting backup at 18-MAR-15 current log archived allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=141 devtype=DISK skipping archive log file /u02/1_49_870806981.dbf; already backed up 1 time(s) skipping archive log file /u02/1_50_870806981.dbf; already backed up 1 time(s) skipping archive log file /u02/1_51_870806981.dbf; already backed up 1 time(s) skipping archive log file /u02/1_52_870806981.dbf; already backed up 1 time(s) skipping archive log file /u02/1_53_870806981.dbf; already backed up 1 time(s) skipping archive log file /u02/1_54_870806981.dbf; already backed up 1 time(s) skipping archive log file /u02/1_55_870806981.dbf; already backed up 1 time(s) skipping archive log file /u02/1_56_870806981.dbf; already backed up 1 time(s) channel ORA_DISK_1: starting archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set input archive log thread=1 sequence=57 recid=64 stamp=874668125 channel ORA_DISK_1: starting piece 1 at 18-MAR-15 channel ORA_DISK_1: finished piece 1 at 18-MAR-15 piece handle=/u02/ora_test874668127_671 tag=TAG20150318T112206 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02 Finished backup at 18-MAR-15 Starting backup at 18-MAR-15 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset input datafile fno=00001 name=/u01/app/oracle/oradata/test/system01.dbf input datafile fno=00003 name=/u01/app/oracle/oradata/test/sysaux01.dbf input datafile fno=00005 name=/u01/app/oracle/oradata/test/example01.dbf input datafile fno=00006 name=/u01/app/oracle/oradata/test/tspitr01.dbf input datafile fno=00002 name=/u01/app/oracle/oradata/test/undotbs01.dbf input datafile fno=00004 name=/u01/app/oracle/oradata/test/users01.dbf channel ORA_DISK_1: starting piece 1 at 18-MAR-15 channel ORA_DISK_1: finished piece 1 at 18-MAR-15 piece handle=/u02/ora_test874668130_681 tag=TAG20150318T112209 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:01:15 Finished backup at 18-MAR-15 Starting backup at 18-MAR-15 current log archived using channel ORA_DISK_1 channel ORA_DISK_1: starting archive log backupset channel ORA_DISK_1: specifying archive log(s) in backup set input archive log thread=1 sequence=58 recid=65 stamp=874668205 channel ORA_DISK_1: starting piece 1 at 18-MAR-15 channel ORA_DISK_1: finished piece 1 at 18-MAR-15 piece handle=/u02/ora_test874668206_691 tag=TAG20150318T112326 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02 Finished backup at 18-MAR-15 Starting Control File and SPFILE Autobackup at 18-MAR-15 piece handle=/u01/app/oracle/flash_recovery_area/TEST/autobackup/2015_03_18/o1_mf_s_874668209_bjkvxl3b_.bkp comment=NONE Finished Control File and SPFILE Autobackup at 18-MAR-15 Recovery Manager complete.
在啟動RMAN客戶端時必須要連線到恢復目錄(儲存指令碼儲存在恢復目錄中)和目標資料庫。
儲存指令碼命名限制
RMAN是如何解決指令碼名稱,尤其是在區域性和全域性指令碼共享相同名稱時存在的一些問題:
.RMAN允許但一般不要求將儲存指令碼名使用引號括起來。然而,儲存指令碼名以數字或RMAN的保留關鍵開頭就需要將儲存指令碼名稱使用引號括起來。對於儲存指令碼名稱要考慮避免使用A-Z之外的字元或RMAN的保留關鍵字作為名稱的開始字元。
.當在命令列中使用script引數來啟動RMAN客戶端,如果存在相同名稱的區域性和全域性儲存指令碼,那麼RMAN將總是執行區域性指令碼。
.對於execute script,delete script和print script命令,如果指令碼名稱作為一個引數被傳遞並且在連線到的目標資料庫中沒有該相同名稱的指令碼存在,RMAN將執行,刪除或顯示相同名稱的全域性指令碼。例如,如果在恢復目錄中存在一個名叫global_full_backup的全域性儲存指令碼,但在目標資料庫中沒有名叫global_full_backup的區域性儲存指令碼,下面的命令將會刪除全域性指令碼:
DELETE SCRIPT global_full_backup;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26015009/viewspace-1465127/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 基於catalog 建立RMAN儲存指令碼指令碼
- catalog備份資料庫及RMAN儲存指令碼資料庫指令碼
- rman指令碼指令碼
- 儲存過程批量生成awr指令碼儲存過程指令碼
- Oracle rman 指令碼Oracle指令碼
- mysql 轉換表的儲存引擎指令碼MySql儲存引擎指令碼
- 【RMAN】RMAN指令碼中使用替換變數--windows 下rman全備指令碼指令碼變數Windows
- rman 備份指令碼指令碼
- rman備份指令碼指令碼
- sqlserver資料庫還原儲存過程指令碼SQLServer資料庫儲存過程指令碼
- 使用儲存指令碼還原恢復資料庫指令碼資料庫
- 用儲存過程封裝awrrpt指令碼(四)儲存過程封裝指令碼
- 用儲存過程封裝awrrpt指令碼(三)儲存過程封裝指令碼
- 用儲存過程封裝awrrpt指令碼(二)儲存過程封裝指令碼
- 用儲存過程封裝awrrpt指令碼(一)儲存過程封裝指令碼
- 用儲存過程封裝awrrpt指令碼(五)儲存過程封裝指令碼
- Mesh-gpt(點處理、儲存指令碼,Transformer)GPT指令碼ORM
- rman 全備份指令碼指令碼
- rman增量備份指令碼指令碼
- rman實用指令碼集指令碼
- 自動化RMAN指令碼指令碼
- windows rman備份指令碼Windows指令碼
- RMAN恢復指令碼案例指令碼
- RMAN常用備份指令碼指令碼
- oracle linux rman 指令碼OracleLinux指令碼
- oracle RMAN備份指令碼Oracle指令碼
- RMAN相容性、控制檔案自動備份、儲存時間、備份策略、備份指令碼(二)指令碼
- Linux/Unix shell 指令碼中呼叫SQL,RMAN指令碼Linux指令碼SQL
- [Oracle] rman備份指令碼(2)Oracle指令碼
- 使用rman備份的指令碼指令碼
- oracle rman備份指令碼收集Oracle指令碼
- Windows下RMAN備份指令碼Windows指令碼
- RMAN全庫備份指令碼指令碼
- RMAN備份Shel指令碼示例指令碼
- oracle 10g rman 指令碼Oracle 10g指令碼
- Rman備份的shell指令碼指令碼
- RAC模式下的rman指令碼模式指令碼
- Rman的映象拷貝指令碼指令碼