备份恢复:backup database format plus archivelog归档备份集路径与数据库format指定不一致
今天朋友发来脚本让我帮忙看一下,为什么plus archivelog时,归档路径的备份集与数据文件的备份不在同一个目录下面(归档的备份集的路径在FRA目录)
脚本内容如下:
#!/bin/ksh
###################################################################################################
#Set Environment Variables
#export ORACLE_SID=ora750ab
#export ORACLE_BASE=/oradb/u01/oracle
#export ORACLE_HOME=$ORACLE_BASE/product/11.2.0.3
#export PATH=/oradb/u01/oracle/product/11.2.0.3/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java5/jre/bin:/usr/java5/bin:/usr/bin:/bin:/usr/bin/X11:/usr/local/bin:
source .~/.1124
#Set Database Backup Directory
BACKUP_DIR=/soft/rman
#Set Shell Runtime Log Directory And LogFile Nme
BACKUP_LOGDIR=/soft/rman/rman_logs
today=`date +"%Y%m%d"`
RMAN_LOG_FILE=rman_ora750ab_$today.log
#Set Archive Log Name
ARCHIVENAME=archive_log_%d_%T_%t
#Set Controlflile Name
CTLNAME=control_log_%d_%T_%t
#Set Backup DataFile Name
BAKFILENAME=bak_data_%d_%T_%t
#Set Timestamp
datetime=`date +"%Y%m%d%H%M"`
mkdir -p $BACKUP_DIR/$datetime
echo "——- Startup Rman Backup Database For incremental Level 0 ——-";date
#Login Target Database
rman <<EOF >>$BACKUP_LOGDIR/$RMAN_LOG_FILE
connect target /
run{
CONFIGURE CONTROLFILE AUTOBACKUP OFF;
CONFIGURE RETENTION POLICY TO REDUNDANCY 1;
crosscheck backup;
crosscheck archivelog all;
delete noprompt backup completed before ‘sysdate-8’;
delete archivelog all completed before ‘sysdate-8’;
#delete noprompt obsolete;
#delete noprompt expired backup;
#delete noprompt expired archivelog all;
allocate channel c1 device type disk;
backup as compressed backupset incremental level=0 database FORMAT ‘$BACKUP_DIR/$datetime/$BAKFILENAME’ plus archivelog delete input;
backup current controlfile format ‘$BACKUP_DIR/$datetime/$CTLNAME’;
release channel c1;
}
list backup;
exit;
EOF
if [ $? -eq 0 ]
then
echo " !!!!!!!!!!!!Backup Database Successful!!!!!!!!!!!!"
fi
#find $BACKUP_DIR -name "rman_ora750ab_*.log" -mtime +7 -type f -exec rm -rf {} \;
#du $BACKUP_DIR/*|awk ‘{if($1==0) print "rm -R "$2}’|sh;
echo "——- Rman Backup Database For incremental Level 0 End ———–";date
##########################################################################下面是我们成功运行的日志记录
Starting backup at 29-MAY-14
current log archived
channel c1: starting compressed archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=135 RECID=139 STAMP=847681218
input archived log thread=1 sequence=136 RECID=140 STAMP=848105533
input archived log thread=1 sequence=137 RECID=141 STAMP=848105770
input archived log thread=1 sequence=138 RECID=142 STAMP=848236620
input archived log thread=1 sequence=139 RECID=143 STAMP=848237483
input archived log thread=1 sequence=140 RECID=144 STAMP=848238423
input archived log thread=1 sequence=141 RECID=145 STAMP=848268355
input archived log thread=1 sequence=142 RECID=146 STAMP=848268550
input archived log thread=1 sequence=143 RECID=147 STAMP=848338667
input archived log thread=1 sequence=144 RECID=148 STAMP=848397541
input archived log thread=1 sequence=145 RECID=149 STAMP=848422818
input archived log thread=1 sequence=146 RECID=150 STAMP=848448037
input archived log thread=1 sequence=147 RECID=151 STAMP=848847970
input archived log thread=1 sequence=148 RECID=152 STAMP=848848076
input archived log thread=1 sequence=149 RECID=153 STAMP=848848077
input archived log thread=1 sequence=150 RECID=154 STAMP=848862259
input archived log thread=1 sequence=151 RECID=155 STAMP=848862335
input archived log thread=1 sequence=152 RECID=156 STAMP=848862683
input archived log thread=1 sequence=153 RECID=157 STAMP=848862776
input archived log thread=1 sequence=154 RECID=158 STAMP=848862873
input archived log thread=1 sequence=155 RECID=159 STAMP=848863055
input archived log thread=1 sequence=156 RECID=160 STAMP=848865089
input archived log thread=1 sequence=157 RECID=161 STAMP=848865135
input archived log thread=1 sequence=158 RECID=162 STAMP=848865366
input archived log thread=1 sequence=159 RECID=164 STAMP=848865944
input archived log thread=1 sequence=160 RECID=163 STAMP=848865944
channel c1: starting piece 1 at 29-MAY-14
channel c1: finished piece 1 at 29-MAY-14
piece handle=/oracle/app/oracle/fast_recovery_area/ORCL1124/backupset/2014_05_29/o1_mf_annnn_TAG20140529T231950_9rgn0q2y_.bkp tag=TAG20140529T231950 comment=NONE
RMAN>
List of Backup Sets
===================
BS Key Size Device Type Elapsed Time Completion Time
——- ———- ———– ———— —————
7 161.50K DISK 00:00:00 29-MAY-14
BP Key: 7 Status: AVAILABLE Compressed: YES Tag: TAG20140529T233130
Piece Name: /soft/rman/201405292331/bak_data_ORCL1124_20140529_848878290
List of Archived Logs in backup set 7
Thrd Seq Low SCN Low Time Next SCN Next Time
—- ——- ———- ——— ———- ———
1 17 2633331 29-MAY-14 2633815 29-MAY-14
BS Key Type LV Size Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— —————
8 Incr 0 290.23M DISK 00:01:13 29-MAY-14
BP Key: 8 Status: AVAILABLE Compressed: YES Tag: TAG20140529T233131
Piece Name: /soft/rman/201405292331/bak_data_ORCL1124_20140529_848878291
List of Datafiles in backup set 8
File LV Type Ckp SCN Ckp Time Name
—- — —- ———- ——— —-
1 0 Incr 2633823 29-MAY-14 /oracle/app/oracle/oradata/orcl1124/system01.dbf
2 0 Incr 2633823 29-MAY-14 /oracle/app/oracle/oradata/orcl1124/sysaux01.dbf
3 0 Incr 2633823 29-MAY-14 /oracle/app/oracle/oradata/orcl1124/undotbs01.dbf
4 0 Incr 2633823 29-MAY-14 /oracle/app/oracle/oradata/orcl1124/users01.dbf
5 0 Incr 2633823 29-MAY-14 /oracle/app/oracle/oradata/orcl1124/htz01.dbf
6 0 Incr 2633823 29-MAY-14 /oracle/app/oracle/oradata/orcl1124/undotbs02.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— —————
—- ——- ———- ——— ———- ———
1 20 2635163 29-MAY-14 2635286 29-MAY-14
BS Key Type LV Size Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— —————
14 Incr 0 285.23M DISK 00:01:00 29-MAY-14
BP Key: 14 Status: AVAILABLE Compressed: YES Tag: TAG20140529T235608
Piece Name: /soft/rman/201405292356/bak_data_ORCL1124_20140529_848879768
List of Datafiles in backup set 14
File LV Type Ckp SCN Ckp Time Name
—- — —- ———- ——— —-
1 0 Incr 2635294 29-MAY-14 /oracle/app/oracle/oradata/orcl1124/system01.dbf
2 0 Incr 2635294 29-MAY-14 /oracle/app/oracle/oradata/orcl1124/sysaux01.dbf
3 0 Incr 2635294 29-MAY-14 /oracle/app/oracle/oradata/orcl1124/undotbs01.dbf
4 0 Incr 2635294 29-MAY-14 /oracle/app/oracle/oradata/orcl1124/users01.dbf
5 0 Incr 2635294 29-MAY-14 /oracle/app/oracle/oradata/orcl1124/htz01.dbf
6 0 Incr 2635294 29-MAY-14 /oracle/app/oracle/oradata/orcl1124/undotbs02.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— —————
15 Incr 0 1.06M DISK 00:00:01 29-MAY-14
BP Key: 15 Status: AVAILABLE Compressed: YES Tag: TAG20140529T235608
Piece Name: /soft/rman/201405292356/bak_data_ORCL1124_20140529_848879834
SPFILE Included: Modification time: 29-MAY-14
SPFILE db_unique_name: ORCL1124
Control File Included: Ckp SCN: 2635315 Ckp time: 29-MAY-14
BS Key Size Device Type Elapsed Time Completion Time
——- ———- ———– ———— —————
16 3.00K DISK 00:00:00 29-MAY-14
BP Key: 16 Status: AVAILABLE Compressed: YES Tag: TAG20140529T235716
Piece Name: /oracle/app/oracle/fast_recovery_area/ORCL1124/backupset/2014_05_29/o1_mf_annnn_TAG20140529T235716_9rgp6wf7_.bkp
List of Archived Logs in backup set 16
Thrd Seq Low SCN Low Time Next SCN Next Time
—- ——- ———- ——— ———- ———
1 21 2635286 29-MAY-14 2635320 29-MAY-14
BS Key Type LV Size Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— —————
17 Full 9.64M DISK 00:00:02 29-MAY-14
BP Key: 17 Status: AVAILABLE Compressed: NO Tag: TAG20140529T235717
Piece Name: /soft/rman/201405292356/control_log_ORCL1124_20140529_848879837
Control File Included: Ckp SCN: 2635331 Ckp time: 29-MAY-14
RMAN>
Recovery Manager complete.这里我们看到归档的备份集的路径在FRA中
报错的原因:其实这里报错的原因很简单,下面我们来看看BACKUP命令的语法
BACKUP [ {backupOperand}…] backupSpec [backupSpec]… [PLUS ARCHIVELOG [ {backupSpecOperand}…]]看看backupsetcoperand选择
CHANNEL [‘] channel_id [‘] | DELETE [ALL] INPUT | DISKRATIO integer | FILESPERSET integer | FORCE | {AUXILIARY FORMAT { formatSpec [,formatSpec]… | NEW} | FORMAT formatSpec [, formatSpec]… | TO DESTINATION toDestSpec [, toDestSpec]…} | FROM TAG [‘] tag_name [‘] | INCLUDECURRENT CONTROLFILE | keepOption | MAXSETSIZE sizeSpec | notBackedUpSpec | NOEXCLUDE | POOL integer | REUSE | SECTION SIZE sizeSpec | skipSpec |TAG [‘] tag_name [‘]注意这里我们再次看到了FORMAT,说明plus archivelog的格式是在这里的FORMAT来指定的
下面我们在plus archivelog中增加上format再次测试一把
RMAN> delete backup;
using channel ORA_DISK_1
List of Backup Pieces
BP Key BS Key Pc# Cp# Status Device Type Piece Name
——- ——- — — ———– ———– ———-
7 7 1 1 AVAILABLE DISK /soft/rman/201405292331/bak_data_ORCL1124_20140529_848878290
8 8 1 1 AVAILABLE DISK /soft/rman/201405292331/bak_data_ORCL1124_20140529_848878291
9 9 1 1 AVAILABLE DISK /soft/rman/201405292331/bak_data_ORCL1124_20140529_848878366
10 10 1 1 AVAILABLE DISK /soft/rman/201405292331/bak_data_ORCL1124_20140529_848878369
11 11 1 1 AVAILABLE DISK /soft/rman/201405292331/control_log_ORCL1124_20140529_848878370
12 12 1 1 AVAILABLE DISK /oracle/app/oracle/fast_recovery_area/ORCL1124/backupset/2014_05_29/o1_mf_annnn_TAG20140529T235544_9rgp40gt_.bkp
13 13 1 1 AVAILABLE DISK /oracle/app/oracle/fast_recovery_area/ORCL1124/backupset/2014_05_29/o1_mf_annnn_TAG20140529T235607_9rgp4ql0_.bkp
14 14 1 1 AVAILABLE DISK /soft/rman/201405292356/bak_data_ORCL1124_20140529_848879768
15 15 1 1 AVAILABLE DISK /soft/rman/201405292356/bak_data_ORCL1124_20140529_848879834
16 16 1 1 AVAILABLE DISK /oracle/app/oracle/fast_recovery_area/ORCL1124/backupset/2014_05_29/o1_mf_annnn_TAG20140529T235716_9rgp6wf7_.bkp
17 17 1 1 AVAILABLE DISK /soft/rman/201405292356/control_log_ORCL1124_20140529_848879837
Do you really want to delete the above objects (enter YES or NO)? yes
deleted backup piece
backup piece handle=/soft/rman/201405292331/bak_data_ORCL1124_20140529_848878290 RECID=7 STAMP=848878290
deleted backup piece
backup piece handle=/soft/rman/201405292331/bak_data_ORCL1124_20140529_848878291 RECID=8 STAMP=848878291
deleted backup piece
backup piece handle=/soft/rman/201405292331/bak_data_ORCL1124_20140529_848878366 RECID=9 STAMP=848878367
deleted backup piece
backup piece handle=/soft/rman/201405292331/bak_data_ORCL1124_20140529_848878369 RECID=10 STAMP=848878369
deleted backup piece
backup piece handle=/soft/rman/201405292331/control_log_ORCL1124_20140529_848878370 RECID=11 STAMP=848878371
deleted backup piece
backup piece handle=/oracle/app/oracle/fast_recovery_area/ORCL1124/backupset/2014_05_29/o1_mf_annnn_TAG20140529T235544_9rgp40gt_.bkp RECID=12 STAMP=848879744
deleted backup piece
backup piece handle=/oracle/app/oracle/fast_recovery_area/ORCL1124/backupset/2014_05_29/o1_mf_annnn_TAG20140529T235607_9rgp4ql0_.bkp RECID=13 STAMP=848879767
deleted backup piece
backup piece handle=/soft/rman/201405292356/bak_data_ORCL1124_20140529_848879768 RECID=14 STAMP=848879769
deleted backup piece
backup piece handle=/soft/rman/201405292356/bak_data_ORCL1124_20140529_848879834 RECID=15 STAMP=848879835
deleted backup piece
backup piece handle=/oracle/app/oracle/fast_recovery_area/ORCL1124/backupset/2014_05_29/o1_mf_annnn_TAG20140529T235716_9rgp6wf7_.bkp RECID=16 STAMP=848879836
deleted backup piece
backup piece handle=/soft/rman/201405292356/control_log_ORCL1124_20140529_848879837 RECID=17 STAMP=848879838
Deleted 11 objects将脚本更改为:
backup as compressed backupset incremental level=0 database FORMAT ‘$BACKUP_DIR/$datetime/$BAKFILENAME’ plus archivelog FORMAT ‘$BACKUP_DIR/$datetime/$BAKFILENAME’ delete input;
backup current controlfile format ‘$BACKUP_DIR/$datetime/$CTLNAME’;下面来看看备份的日志
Starting backup at 30-MAY-14
current log archived
channel c1: starting compressed archived log backup set
channel c1: specifying archived log(s) in backup set
input archived log thread=1 sequence=22 RECID=186 STAMP=848880647
channel c1: starting piece 1 at 30-MAY-14
channel c1: finished piece 1 at 30-MAY-14
piece handle=/soft/rman/201405300010/bak_data_ORCL1124_20140530_848880648 tag=TAG20140530T001047 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:01
channel c1: deleting archived log(s)
archived log file name=/oracle/app/oracle/fast_recovery_area/ORCL1124/archivelog/2014_05_30/o1_mf_1_22_9rgq07t3_.arc RECID=186 STAMP=848880647
Finished backup at 30-MAY-14
List of Backup Sets
===================
BS Key Size Device Type Elapsed Time Completion Time
——- ———- ———– ———— —————
18 1.15M DISK 00:00:00 30-MAY-14
BP Key: 18 Status: AVAILABLE Compressed: YES Tag: TAG20140530T001047
Piece Name: /soft/rman/201405300010/bak_data_ORCL1124_20140530_848880648
List of Archived Logs in backup set 18
Thrd Seq Low SCN Low Time Next SCN Next Time
—- ——- ———- ——— ———- ———
1 22 2635320 29-MAY-14 2635884 30-MAY-14
BS Key Type LV Size Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— —————
19 Incr 0 284.96M DISK 00:01:05 30-MAY-14
BP Key: 19 Status: AVAILABLE Compressed: YES Tag: TAG20140530T001049
Piece Name: /soft/rman/201405300010/bak_data_ORCL1124_20140530_848880649
List of Datafiles in backup set 19
File LV Type Ckp SCN Ckp Time Name
—- — —- ———- ——— —-
1 0 Incr 2635895 30-MAY-14 /oracle/app/oracle/oradata/orcl1124/system01.dbf
2 0 Incr 2635895 30-MAY-14 /oracle/app/oracle/oradata/orcl1124/sysaux01.dbf
3 0 Incr 2635895 30-MAY-14 /oracle/app/oracle/oradata/orcl1124/undotbs01.dbf
4 0 Incr 2635895 30-MAY-14 /oracle/app/oracle/oradata/orcl1124/users01.dbf
5 0 Incr 2635895 30-MAY-14 /oracle/app/oracle/oradata/orcl1124/htz01.dbf
6 0 Incr 2635895 30-MAY-14 /oracle/app/oracle/oradata/orcl1124/undotbs02.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— —————
20 Incr 0 1.06M DISK 00:00:01 30-MAY-14
BP Key: 20 Status: AVAILABLE Compressed: YES Tag: TAG20140530T001049
Piece Name: /soft/rman/201405300010/bak_data_ORCL1124_20140530_848880724
SPFILE Included: Modification time: 30-MAY-14
SPFILE db_unique_name: ORCL1124
Control File Included: Ckp SCN: 2635919 Ckp time: 30-MAY-14
BS Key Size Device Type Elapsed Time Completion Time
——- ———- ———– ———— —————
21 3.00K DISK 00:00:01 30-MAY-14
BP Key: 21 Status: AVAILABLE Compressed: YES Tag: TAG20140530T001206
Piece Name: /soft/rman/201405300010/bak_data_ORCL1124_20140530_848880726
List of Archived Logs in backup set 21
Thrd Seq Low SCN Low Time Next SCN Next Time
—- ——- ———- ——— ———- ———
1 23 2635884 30-MAY-14 2635925 30-MAY-14
BS Key Type LV Size Device Type Elapsed Time Completion Time
——- —- — ———- ———– ———— —————
22 Full 9.64M DISK 00:00:01 30-MAY-14
BP Key: 22 Status: AVAILABLE Compressed: NO Tag: TAG20140530T001208
Piece Name: /soft/rman/201405300010/control_log_ORCL1124_20140530_848880728
Control File Included: Ckp SCN: 2635936 Ckp time: 30-MAY-14
RMAN>
Recovery Manager complete.
RMAN> list backup of archivelog all;
List of Backup Sets
===================
BS Key Size Device Type Elapsed Time Completion Time
——- ———- ———– ———— —————
18 1.15M DISK 00:00:00 30-MAY-14
BP Key: 18 Status: AVAILABLE Compressed: YES Tag: TAG20140530T001047
Piece Name: /soft/rman/201405300010/bak_data_ORCL1124_20140530_848880648
List of Archived Logs in backup set 18
Thrd Seq Low SCN Low Time Next SCN Next Time
—- ——- ———- ——— ———- ———
1 22 2635320 29-MAY-14 2635884 30-MAY-14
BS Key Size Device Type Elapsed Time Completion Time
——- ———- ———– ———— —————
21 3.00K DISK 00:00:01 30-MAY-14
BP Key: 21 Status: AVAILABLE Compressed: YES Tag: TAG20140530T001206
Piece Name: /soft/rman/201405300010/bak_data_ORCL1124_20140530_848880726
List of Archived Logs in backup set 21
Thrd Seq Low SCN Low Time Next SCN Next Time
—- ——- ———- ——— ———- ———
1 23 2635884 30-MAY-14 2635925 30-MAY-14这里可以看到归档日志的备份集已经存放到FORMAT指定的路径下面。其实还有另一个更简单的解决方案就是在分配通宵的时候就可以指定FORMAT。
------------------作者介绍-----------------------
姓名:黄廷忠
















