oracle备份脚本
oracle9i备份脚本:
全备(level 0):
bash-3.00$ more ora9i_rman_bak.sh | grep -v #
cuser=`id |cut -d( -f2 | cut -d ) -f1`
rman_log_file=${0}.out
if [ -f $rman_log_file ]
then
rm -f $rman_log_file
fi
echo >> $rman_log_file
chmod 666 $rman_log_file
echo script $0 >> $rman_log_file
echo ==== started on `date` ==== >> $rman_log_file
echo >> $rman_log_file
oracle_home=/orahome/oracle/product/9.2.0
export oracle_home
oracle_sid=bims
export oracle_sid
oracle_user=oracle
target_connect_str=/
rman=$oracle_home/bin/rman
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
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
echo >> $rman_log_file
if [ $nb_ora_full = 1 ]
then
echo full backup requested >> $rman_log_file
backup_type=incremental level=0
elif [ $nb_ora_incr = 1 ]
then
echo differential incremental backup requested >> $rman_log_file
backup_type=incremental level=1
elif [ $nb_ora_cinc = 1 ]
then
echo cumulative incremental backup requested >> $rman_log_file
backup_type=incremental level=1 cumulative
elif [ $backup_type = ]
then
echo default - full backup requested >> $rman_log_file
backup_type=incremental level=0
fi
cmd_str=
oracle_home=$oracle_home
export oracle_home
oracle_sid=$oracle_sid
export oracle_sid
nls_date_format='yyyy-mm-dd hh24:mi:ss'
export nls_date_format
$rman target $target_connect_str nocatalog msglog $rman_log_file append crosscheck archivelog all;
delete noprompt expired archivelog all;
run {
allocate channel ch00 type disk;
allocate channel ch01 type disk;
allocate channel ch02 type disk;
allocate channel ch03 type disk;
backup
$backup_type
skip inaccessible
tag hot_db_bk_level0
filesperset 5
format '/orahomebak/backup/database/bk_%s_%p_%t'
database;
sql 'alter system archive log current';
release channel ch00;
release channel ch01;
release channel ch02;
release channel ch03;
allocate channel ch00 type disk;
allocate channel ch01 type disk;
backup
filesperset 20
format '/orahomebak/backup/arch/al_%s_%p_%t'
archivelog all delete input;
release channel ch00;
release channel ch01;
allocate channel ch00 type disk;
backup
format '/orahomebak/backup/database/cntrl_%s_%p_%t'
current controlfile;
release channel ch00;
}
eof
if [ $cuser = root ]
then
su - $oracle_user -c $cmd_str >> $rman_log_file
rstat=$?
else
/usr/bin/sh -c $cmd_str >> $rman_log_file
rstat=$?
fi
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
differential incremental backup(level 1):
bash-3.00$ more ora9i_rman_bak.sh | grep -v #
cuser=`id |cut -d( -f2 | cut -d ) -f1`
rman_log_file=${0}.out
if [ -f $rman_log_file ]
then
rm -f $rman_log_file
fi
echo >> $rman_log_file
chmod 666 $rman_log_file
echo script $0 >> $rman_log_file
echo ==== started on `date` ==== >> $rman_log_file
echo >> $rman_log_file
oracle_home=/orahome/oracle/product/9.2.0
export oracle_home
oracle_sid=bims
export oracle_sid
oracle_user=oracle
target_connect_str=/
rman=$oracle_home/bin/rman
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
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
echo >> $rman_log_file
echo differential incremental backup requested >> $rman_log_file
cmd_str=
oracle_home=$oracle_home
export oracle_home
oracle_sid=$oracle_sid
export oracle_sid
nls_date_format='yyyy-mm-dd hh24:mi:ss'
export nls_date_format
$rman target $target_connect_str nocatalog msglog $rman_log_file append crosscheck archivelog all;
delete noprompt expired archivelog all;
run {
allocate channel ch00 type disk;
allocate channel ch01 type disk;
allocate channel ch02 type disk;
allocate channel ch03 type disk;
backup
incremental level 1
skip inaccessible
tag hot_db_bk_level1
filesperset 5
format '/orahomebak/backup/database/bk_%s_%p_%t'
database;
sql 'alter system archive log current';
release channel ch00;
release channel ch01;
release channel ch02;
release channel ch03;
allocate channel ch00 type disk;
allocate channel ch01 type disk;
backup
filesperset 20
format '/orahomebak/backup/arch/al_%s_%p_%t'
archivelog all delete input;
release channel ch00;
release channel ch01;
allocate channel ch00 type disk;
backup
format '/orahomebak/backup/database/cntrl_%s_%p_%t'
current controlfile;
release channel ch00;
}
eof
if [ $cuser = root ]
then
su - $oracle_user -c $cmd_str >> $rman_log_file
rstat=$?
else
/usr/bin/sh -c $cmd_str >> $rman_log_file
rstat=$?
fi
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
http://www.bkjia.com/phpjc/1067488.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/1067488.htmltecharticleoracle备份脚本 oracle9i备份脚本: 全备(level 0): bash-3.00$ more ora9i_rman_bak.sh | grep -v # cuser=`id |cut -d( -f2 | cut -d ) -f1` rman_log_file=${0}.out...