#!/bin/bash
export LANG=en_US
export ORACLE_HOME=/u01/app/product/10.2.0/db_1
export RMAN=$ORACLE_HOME/bin/rman
export ORACLE_SID=dbs1
export ORACLE_USER=oracle
export DAY=`date +%Y%m%d`
export WEEKS=`date +%U`
export BACKUP_DIR=/u01/rman
export RMAN_LOG_FILE=$BACKUP_DIR/rman_"$ORACLE_SID"_$DAY.log
TODAY=`date`
USER=`id|cut -d "(" -f2|cut -d ")" -f1`
echo "=================$TODAY===================">$RMAN_LOG_FILE
echo "ORACLE_SID: $ORACLE_SID">>$RMAN_LOG_FILE
echo "ORACLE_HOME: $ORACLE_HOME">>$RMAN_LOG_FILE
echo "ORACLE_USER: $ORACLE_USER">>$RMAN_LOG_FILE
echo "================================================================">>$RMAN_LOG_FILE
echo " ">>$RMAN_LOG_FILE
echo "BACKUP DATABASE BEGIN......">>$RMAN_LOG_FILE
echo " ">>$RMAN_LOG_FILE
chmod 666 $RMAN_LOG_FILE
BAK_LEVEL=0
#export BAK_LEVEL=$BAK_LEVEL
echo "Today is : `date +%A` incremental level $BAK_LEVEL">>$RMAN_LOG_FILE
echo " ">>$RMAN_LOG_FILE
RUN_STR="
export BAK_LEVEL=$BAK_LEVEL
export ORACLE_HOME=$ORACLE_HOME
export ORACLE_SID=$ORACLE_SID
$RMAN nocatalog TARGET / msglog $RMAN_LOG_FILE append <<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
allocate channel c5 device type disk;
allocate channel c6 device type disk;
allocate channel c7 device type disk;
allocate channel c8 device type disk;
allocate channel c9 device type disk;
allocate channel c10 device type disk;
backup tag 'tstpcc' format '/u01/rman/tpcc_0_%d_%u' tablespace tpcc100;
sql 'alter system archive log current' ;
backup format '/u01/rman/archivelog_%d_%u' (archivelog all);
release channel c10;
release channel c9;
release channel c8;
release channel c7;
release channel c6;
release channel c5;
release channel c4;
release channel c3;
release channel c2;
release channel c1;
}
allocate channel for maintenance device type disk;
report obsolete;
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete;
list backup summary;
release channel;
EOF
"
# Initiate the command string
if [ "$CUSER" = "root" ]
then
echo "Root Command String: $RUN_STR" >> $RMAN_LOG_FILE
su - $ORACLE_USER -c "$RUN_STR" >> $RMAN_LOG_FILE
RSTAT=$?
else
echo "User Command String: $RUN_STR" >> $RMAN_LOG_FILE
/bin/sh -c "$RUN_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 $0 >> $RMAN_LOG_FILE
echo ==== $LOGMSG on `date` ==== >> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE
exit $RSTAT
rman多进程并发备份一个数据表空间脚本
最新推荐文章于 2021-06-08 11:41:09 发布