Oracle Study之案例--RMAN备份配置参数
1、PARALLELISM我们还可以通过parallelism参数来指定同时"自动"创建多少个通道:RMAN > configure device type disk parallelism 3 ;表示启动三个通道,可以加快备份恢复的速度。
案例分析:RMAN> show all;
using target database control file instead of recovery catalog
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
......
RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 3;
RMAN> show default device type;
RMAN configuration parameters for database with db_unique_name TEST1 are:
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
RMAN> backup datafile 4;
Starting backup at 30-DEC-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=36 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=34 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=38 device type=DISK
---rman启动了三个channel来做备份
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/test1/users01.dbf
channel ORA_DISK_1: starting piece 1 at 30-DEC-14
channel ORA_DISK_1: finished piece 1 at 30-DEC-14
piece handle=/dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T135425_bb4hjmod_.bkp tag=TAG20141230T135425 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
Finished backup at 30-DEC-14
默认情况下,自动分配通道的并行度为1,如果你通过设置PARALLELISM设置了并行通道为2,那么在run块中,如果你没有单独通过ALLOCATE CHANNEL命令指定通道,它会默认使用2条并行通道,如果你在run命令块中指定了数个ALLOCATE CHANNEL,那么rman在执行备份命令时会以你设置的channel为准,而不管configure中配置了多少个并行通道。
案例分析:RMAN> run {
2> allocate channel c1 type disk;
3> backup datafile 4;
4> }
released channel: ORA_DISK_1
released channel: ORA_DISK_2
released channel: ORA_DISK_3
allocated channel: c1
channel c1: SID=36 device type=DISK
Starting backup at 30-DEC-14
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/test1/users01.dbf
channel c1: starting piece 1 at 30-DEC-14
channel c1: finished piece 1 at 30-DEC-14
piece handle=/dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T135628_bb4hngl2_.bkp tag=TAG20141230T135628 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:07
Finished backup at 30-DEC-14
released channel: c1
---rman只启用了一个channel,忽略了PARALLELISM参数设置
2、FILESPERSET
FILESPERSET = integer
Specifies the maximum number of input files in each backup set. If you set FILESPERSET = n, then RMAN never includes more than n files in a backup set. The default for
FILESPERSET is the lesser of these two values: 64, number of input files divided by the number of channels. For example, if you back up 100 datafiles by using two channels, RMANsets FILESPERSET to 50.
RMAN always attempts to create enough backup sets so that all allocated channels have work to do. An exception to the rule occurs when there are more channels than files to back up. For example, if RMAN backs up two datafiles when three channels are allocated and FILESPERSET = 1, then one channel is necessarily idle.
需要注意的一点是,在backup命令中有一个FILESPERSET参数,该参数是指rman建立的每个备份集中所能包含的数据文件的最大数(注意: 不是指备份片,也就是备份出来的文件),该参数默认值为64,如果在执行backup命令时没有指定该参数值,那么rman会仅使用第一个通道来执行备份,其它通道将处于空闲状态。关于通道数与FILESPERSET值之间也有一个大小关系,逻辑稍显复杂。比如, datafiles 的个数为25 , FILESPERSET = 8 ,那么备份数据库的时候生成4个backupset (25/8=3.125), 每个备份集包含8个数据文件。----- 并行定义通道个数, 通道定义了通道属性。allocate channel 提供备份并发度,若平均文件数
案例分析:(1)RMAN> run {
2> allocate channel c1 type disk;
3> allocate channel c2 type disk;
4> backup datafile 3,4,5,6 filesperset 3;
5> }
allocated channel: c1
channel c1: SID=36 device type=DISK
allocated channel: c2
channel c2: SID=34 device type=DISK
Starting backup at 30-DEC-14
channel c1: starting full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00005 name=/u01/app/oracle/oradata/test1/perfs.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/test1/test1.dbf
channel c1: starting piece 1 at 30-DEC-14
channel c2: starting full datafile backup set
channel c2: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/test1/users01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/test1/dict1.dbf
channel c2: starting piece 1 at 30-DEC-14
channel c1: finished piece 1 at 30-DEC-14
piece handle=/dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T140541_bb4j5tcl_.bkp tag=TAG20141230T140541 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:27
channel c2: finished piece 1 at 30-DEC-14
piece handle=/dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T140541_bb4j5sk4_.bkp tag=TAG20141230T140541 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:26
Finished backup at 30-DEC-14
released channel: c1
released channel: c2
RMAN> list backup of datafile 3,4,5,6;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
355 Full 91.77M DISK 00:00:19 30-DEC-14
BP Key: 355 Status: AVAILABLE Compressed: NO Tag: TAG20141230T140541
Piece Name: /dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T140541_bb4j5sk4_.bkp
List of Datafiles in backup set 355
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
4 Full 11327185 30-DEC-14 /u01/app/oracle/oradata/test1/users01.dbf
6 Full 11327185 30-DEC-14 /u01/app/oracle/oradata/test1/dict1.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
356 Full 19.44M DISK 00:00:22 30-DEC-14
BP Key: 356 Status: AVAILABLE Compressed: NO Tag: TAG20141230T140541
Piece Name: /dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T140541_bb4j5tcl_.bkp
List of Datafiles in backup set 356
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
3 Full 11327183 30-DEC-14 /u01/app/oracle/oradata/test1/test1.dbf
5 Full 11327183 30-DEC-14 /u01/app/oracle/oradata/test1/perfs.dbf
---平均数是 4(文件数)/2(channel数) = 2 ,小于filesperset 3,则生成2个备份集,每个备份集包含2个数据文件案例分析:(2)RMAN> run {
2> allocate channel ch1 type disk;
3> allocate channel ch2 type disk;
4> backup datafile 3,4,5,6 filesperset 1;
5> release channel ch1;
6> release channel ch2;
7> }
allocated channel: ch1
channel ch1: SID=36 device type=DISK
allocated channel: ch2
channel ch2: SID=34 device type=DISK
Starting backup at 30-DEC-14
channel ch1: starting full datafile backup set
channel ch1: specifying datafile(s) in backup set
input datafile file number=00005 name=/u01/app/oracle/oradata/test1/perfs.dbf
channel ch1: starting piece 1 at 30-DEC-14
channel ch2: starting full datafile backup set
channel ch2: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/test1/users01.dbf
channel ch2: starting piece 1 at 30-DEC-14
channel ch1: finished piece 1 at 30-DEC-14
piece handle=/dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T141001_bb4jfvks_.bkp tag=TAG20141230T141001 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:17
channel ch1: starting full datafile backup set
channel ch1: specifying datafile(s) in backup set
input datafile file number=00006 name=/u01/app/oracle/oradata/test1/dict1.dbf
channel ch1: starting piece 1 at 30-DEC-14
channel ch2: finished piece 1 at 30-DEC-14
piece handle=/dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T141001_bb4jfxp0_.bkp tag=TAG20141230T141001 comment=NONE
channel ch2: backup set complete, elapsed time: 00:00:17
channel ch2: starting full datafile backup set
channel ch2: specifying datafile(s) in backup set
input datafile file number=00003 name=/u01/app/oracle/oradata/test1/test1.dbf
channel ch2: starting piece 1 at 30-DEC-14
channel ch2: finished piece 1 at 30-DEC-14
piece handle=/dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T141001_bb4jghg2_.bkp tag=TAG20141230T141001 comment=NONE
channel ch2: backup set complete, elapsed time: 00:00:08
channel ch1: finished piece 1 at 30-DEC-14
piece handle=/dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T141001_bb4jgffw_.bkp tag=TAG20141230T141001 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:19
Finished backup at 30-DEC-14
released channel: ch1
released channel: ch2
RMAN> list backup of datafile 3,4,5,6;
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
357 Full 18.48M DISK 00:00:07 30-DEC-14
BP Key: 357 Status: AVAILABLE Compressed: NO Tag: TAG20141230T141001
Piece Name: /dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T141001_bb4jfxp0_.bkp
List of Datafiles in backup set 357
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
4 Full 11327316 30-DEC-14 /u01/app/oracle/oradata/test1/users01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
358 Full 18.43M DISK 00:00:10 30-DEC-14
BP Key: 358 Status: AVAILABLE Compressed: NO Tag: TAG20141230T141001
Piece Name: /dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T141001_bb4jfvks_.bkp
List of Datafiles in backup set 358
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
5 Full 11327314 30-DEC-14 /u01/app/oracle/oradata/test1/perfs.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
359 Full 1.03M DISK 00:00:05 30-DEC-14
BP Key: 359 Status: AVAILABLE Compressed: NO Tag: TAG20141230T141001
Piece Name: /dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T141001_bb4jghg2_.bkp
List of Datafiles in backup set 359
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
3 Full 11327326 30-DEC-14 /u01/app/oracle/oradata/test1/test1.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
360 Full 73.31M DISK 00:00:15 30-DEC-14
BP Key: 360 Status: AVAILABLE Compressed: NO Tag: TAG20141230T141001
Piece Name: /dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T141001_bb4jgffw_.bkp
List of Datafiles in backup set 360
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
6 Full 11327324 30-DEC-14 /u01/app/oracle/oradata/test1/dict1.dbf
---则生成4个备份集,每个包含一个数据文件例子1 :
RMAN> configure device type disk parallelism 4;
RMAN> configure channel 1 device type disk;
RMAN> configure channel 2 device type disk;
注意: 在上面的配置中,将开启四个通道, 通道1,2采用用户的配置,3,4采用默认配置 。
例子2 :
RMAN> configure device type disk parallelism 3;
RMAN> configure channel 1 device type disk;
RMAN> configure channel 2 device type disk;
RMAN> configure channel 3 device type disk;
RMAN> configure channel 4 device type disk;
注意: 这时,RMAN将忽略parallelism 的设置,而以用户设置的通道为准。
3、SKIP 选项Excludes datafiles or archived redo logs from the backup set according to the criteria specified by the following keywords.Note: You can also specify this option in the backupSpec clause.
4、OFFLINESpecifies that offline datafiles should be excluded from the backup set.
5、READONLYSpecifies that read-only datafiles should be excluded from the backup set.
6、INACCESSIBLESpecifies that datafiles or archived redo logs that cannot be read due to I/O errors should be excluded from the backup set.
A datafile is only considered inaccessible if it cannot be read. Some offline datafiles can still be read because they still exist on disk. Others have been deleted or moved and
so cannot be read, making them inaccessible.
案例分析14:35:25 SYS@ test1 >select file#,name ,status from v$datafile;
FILE# NAME STATUS
---------- -------------------------------------------------- -------
1 /u01/app/oracle/oradata/test1/system01.dbf SYSTEM
2 /u01/app/oracle/oradata/test1/sysaux01.dbf ONLINE
3 /u01/app/oracle/oradata/test1/test1.dbf ONLINE
4 /u01/app/oracle/oradata/test1/users01.dbf ONLINE
5 /u01/app/oracle/oradata/test1/perfs.dbf ONLINE
6 /u01/app/oracle/oradata/test1/dict1.dbf ONLINE
7 /u01/app/oracle/oradata/test1/undotbs2.dbf ONLINE
8 /u01/app/oracle/oradata/test1/test2.dbf OFFLINE
10 /u01/app/oracle/oradata/test1/index01.dbf ONLINE
13 /u01/app/oracle/oradata/test1/tbs_16.dbf ONLINE
10 rows selected.
RMAN> backup database skip offline ;
Starting backup at 30-DEC-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=36 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=17 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=16 device type=DISK
skipping offline file 8
RMAN-06060: WARNING: skipping datafile compromises tablespace TEST2 recoverability
RMAN-06060: WARNING: skipping datafile compromises tablespace TEST2 recoverability
RMAN-06060: WARNING: skipping datafile compromises tablespace TEST2 recoverability
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=/u01/app/oracle/oradata/test1/system01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/test1/test1.dbf
channel ORA_DISK_1: starting piece 1 at 30-DEC-14
channel ORA_DISK_2: starting full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/test1/sysaux01.dbf
input datafile file number=00010 name=/u01/app/oracle/oradata/test1/index01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/test1/dict1.dbf
channel ORA_DISK_2: starting piece 1 at 30-DEC-14
channel ORA_DISK_3: starting full datafile backup set
channel ORA_DISK_3: specifying datafile(s) in backup set
input datafile file number=00005 name=/u01/app/oracle/oradata/test1/perfs.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/test1/undotbs2.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/test1/users01.dbf
channel ORA_DISK_3: starting piece 1 at 30-DEC-14
channel ORA_DISK_3: finished piece 1 at 30-DEC-14
piece handle=/dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T143554_bb4kymxb_.bkp tag=TAG20141230T143554 comment=NONE
channel ORA_DISK_3: backup set complete, elapsed time: 00:00:48
channel ORA_DISK_3: starting full datafile backup set
channel ORA_DISK_3: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_3: starting piece 1 at 30-DEC-14
channel ORA_DISK_2: finished piece 1 at 30-DEC-14
piece handle=/dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T143554_bb4kykmm_.bkp tag=TAG20141230T143554 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:01:24
channel ORA_DISK_2: starting full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
input datafile file number=00013 name=/u01/app/oracle/oradata/test1/tbs_16.dbf
channel ORA_DISK_2: starting piece 1 at 30-DEC-14
channel ORA_DISK_3: finished piece 1 at 30-DEC-14
piece handle=/dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_ncnnf_TAG20141230T143554_bb4l0mbo_.bkp tag=TAG20141230T143554 comment=NONE
channel ORA_DISK_3: backup set complete, elapsed time: 00:00:23
channel ORA_DISK_3: starting full datafile backup set
channel ORA_DISK_3: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_3: starting piece 1 at 30-DEC-14
channel ORA_DISK_2: finished piece 1 at 30-DEC-14
piece handle=/dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T143554_bb4l19n6_.bkp tag=TAG20141230T143554 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:24
channel ORA_DISK_3: finished piece 1 at 30-DEC-14
piece handle=/dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnsnf_TAG20141230T143554_bb4l1c9g_.bkp tag=TAG20141230T143554 comment=NONE
channel ORA_DISK_3: backup set complete, elapsed time: 00:00:18
channel ORA_DISK_1: finished piece 1 at 30-DEC-14
piece handle=/dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T143554_bb4kylnm_.bkp tag=TAG20141230T143554 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:22
Finished backup at 30-DEC-14
RMAN> list backup of database;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
361 Full 39.30M DISK 00:00:39 30-DEC-14
BP Key: 361 Status: AVAILABLE Compressed: NO Tag: TAG20141230T143554
Piece Name: /dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T143554_bb4kymxb_.bkp
List of Datafiles in backup set 361
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
4 Full 11328151 30-DEC-14 /u01/app/oracle/oradata/test1/users01.dbf
5 Full 11328151 30-DEC-14 /u01/app/oracle/oradata/test1/perfs.dbf
7 Full 11328151 30-DEC-14 /u01/app/oracle/oradata/test1/undotbs2.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
362 Full 199.24M DISK 00:01:18 30-DEC-14
BP Key: 362 Status: AVAILABLE Compressed: NO Tag: TAG20141230T143554
Piece Name: /dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T143554_bb4kykmm_.bkp
List of Datafiles in backup set 362
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
2 Full 11328149 30-DEC-14 /u01/app/oracle/oradata/test1/sysaux01.dbf
6 Full 11328149 30-DEC-14 /u01/app/oracle/oradata/test1/dict1.dbf
10 Full 11328149 30-DEC-14 /u01/app/oracle/oradata/test1/index01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
364 Full 1.06M DISK 00:00:14 30-DEC-14
BP Key: 364 Status: AVAILABLE Compressed: NO Tag: TAG20141230T143554
Piece Name: /dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T143554_bb4l19n6_.bkp
List of Datafiles in backup set 364
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
13 Full 11328183 30-DEC-14 /u01/app/oracle/oradata/test1/tbs_16.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
366 Full 535.42M DISK 00:02:12 30-DEC-14
BP Key: 366 Status: AVAILABLE Compressed: NO Tag: TAG20141230T143554
Piece Name: /dsk4/backup/TEST1/backupset/2014_12_30/o1_mf_nnndf_TAG20141230T143554_bb4kylnm_.bkp
List of Datafiles in backup set 366
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 11328147 30-DEC-14 /u01/app/oracle/oradata/test1/system01.dbf
3 Full 11328147 30-DEC-14 /u01/app/oracle/oradata/test1/test1.dbf
备份脚本:#########################################################################
## t_database_backup.sh ##
## created by Tianlesoftware ##
## 2010-7-16 ##
#########################################################################
#!/bin/bash
# ---------------------------------------------------------------------------
# Determine the user which is executing this script.
# ---------------------------------------------------------------------------
CUSER=`id |cut -d"(" -f2 | cut -d ")" -f1`
# ---------------------------------------------------------------------------
# Put output in .out. Change as desired.
# Note: output directory requires write permission.
# ---------------------------------------------------------------------------
RMAN_LOG_FILE=${0}.out
# ---------------------------------------------------------------------------
# You may want to delete the output file so that backup information does
# not accumulate. If not, delete the following lines.
# ---------------------------------------------------------------------------
if [ -f "$RMAN_LOG_FILE" ]
then
rm -f "$RMAN_LOG_FILE"
fi
# -----------------------------------------------------------------
# Initialize the log file.
# -----------------------------------------------------------------
echo >> $RMAN_LOG_FILE
chmod 666 $RMAN_LOG_FILE
# ---------------------------------------------------------------------------
# Log the start of this script.
# ---------------------------------------------------------------------------
echo Script {1} >> $RMAN_LOG_FILE
echo ==== started on `date` ==== >> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE
# ---------------------------------------------------------------------------
# Oracle home path.
# ---------------------------------------------------------------------------
ORACLE_HOME=/home/oracle/product/10.2.0/db_1
export ORACLE_HOME
# ---------------------------------------------------------------------------
# the Oracle SID of the target database.
# ---------------------------------------------------------------------------
ORACLE_SID=oralife
export ORACLE_SID
# ---------------------------------------------------------------------------
# The Oracle DBA user id (account).
# ---------------------------------------------------------------------------
ORACLE_USER=oracle
export ORACLE_USER
# ---------------------------------------------------------------------------
# Set the Oracle Recovery Manager name.
# ---------------------------------------------------------------------------
RMAN=$ORACLE_HOME/bin/rman
# ---------------------------------------------------------------------------
# Print out the value of the variables set by this script.
# ---------------------------------------------------------------------------
echo >> $RMAN_LOG_FILE
echo "RMAN: $RMAN" >> $RMAN_LOG_FILE
echo "ORACLE_SID: $ORACLE_SID" >> $RMAN_LOG_FILE
echo "ORACLE_USER: $ORACLE_USER" >> $RMAN_LOG_FILE
echo "ORACLE_HOME: $ORACLE_HOME" >> $RMAN_LOG_FILE
# ---------------------------------------------------------------------------
# Print out the value of the variables set by bphdb.
# ---------------------------------------------------------------------------
#echo >> $RMAN_LOG_FILE
#echo "NB_ORA_FULL: $NB_ORA_FULL" >> $RMAN_LOG_FILE
#echo "NB_ORA_INCR: $NB_ORA_INCR" >> $RMAN_LOG_FILE
#echo "NB_ORA_CINC: $NB_ORA_CINC" >> $RMAN_LOG_FILE
#echo "NB_ORA_SERV: $NB_ORA_SERV" >> $RMAN_LOG_FILE
#echo "NB_ORA_POLICY: $NB_ORA_POLICY" >> $RMAN_LOG_FILE
# ---------------------------------------------------------------------------
# NOTE: This script assumes that the database is properly opened. If desired,
# this would be the place to verify that.
# ---------------------------------------------------------------------------
echo >> $RMAN_LOG_FILE
# ---------------------------------------------------------------------------
# ---------------------------------------------------------------------------
# Call Recovery Manager to initiate the backup.
# ---------------------------------------------------------------------------
CMD_STR="
ORACLE_HOME=$ORACLE_HOME
export ORACLE_HOME
ORACLE_SID=$ORACLE_SID
export ORACLE_SID
$RMAN nocatalog target sys/admin msglog $RMAN_LOG_FILE append <
RUN {
allocate channel c1 type disk;
allocate channel c2 type disk;
BACKUP FORMAT '/home/oracle/backup/oralife_%U_%T' skip inaccessible filesperset 5 DATABASE TAG oralife_hot_db_bk;
sql 'alter system archive log current';
BACKUP FORMAT '/home/oracle/backup/arch_%U_%T' skip inaccessible filesperset 5 ARCHIVELOG ALL DELETE INPUT;
backup current controlfile tag='bak_ctlfile' format='/home/oracle/backup/ctl_file_%U_%T';
backup spfile tag='spfile' format='/home/oracle/backup/oralife_spfile_%U_%T';
release channel c2;
release channel c1;
}
report obsolete;
delete noprompt obsolete;
crosscheck backup;
delete noprompt expired backup;
list backup summary;
#EOF
"
# Initiate the command string
if [ "$CUSER" = "root" ]
then
echo "Root Command String: $CMD_STR" >> $RMAN_LOG_FILE
su - $ORACLE_USER -c "$CMD_STR" >> $RMAN_LOG_FILE
RSTAT=$?
else
echo "User Command String: $CMD_STR" >> $RMAN_LOG_FILE
/bin/sh -c "$CMD_STR" >> $RMAN_LOG_FILE
RSTAT=$?
fi
# ---------------------------------------------------------------------------
# Log the completion of this script.
# ---------------------------------------------------------------------------
if [ "$RSTAT" = "0" ]
then
LOGMSG="ended successfully"
else
LOGMSG="ended in error"
fi
echo >> $RMAN_LOG_FILE
echo Script {1} >> $RMAN_LOG_FILE
echo ==== $LOGMSG on `date` ==== >> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE
#/bin/mailx -s "RMAN Backup SID " daimm@sf-express.com
exit $RSTAT