oracle for linux 備份指令碼

selectshen發表於2014-10-13
1.oracle賬號的contab中加入以下,包含dp備份,rman備份和備份刪除
########### delete archivelog and database backup #############################
00 07 * * * sh /exp/backup/delete.sh > /exp/backup/delete.log
########### rman backup ##############################################
00 23 * * 0 sh /exp/backup/incr0.sh > /exp/backup/incr0.log
30 23 * * 1,2,3,4,5,6 sh /exp/backup/incr1.sh > /exp/backup/incr1.log
30 11 * * * sh /exp/backup/export.sh > /exp/backup/export.log 2>&1
2.以下檔案內容
###########/exp/backup/export.sh
#!/bin/sh
#function:using data pump backup database
export ORACLE_SID=$SID   #$SID 為oracle sid
export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
export PATH=.:$ORACLE_HOME/bin:$PATH:.
action_time=`date +%Y_%m_%d`
del_time=`date -d "10 day ago"  +%Y_%m_%d`
echo action time:$action_time
filename=$SID_$action_time.dmp    #$SID 為oracle sid
logname=$SID_$action_time.log     #$SID 為oracle sid
#filedir=/u10/dump
expdp system/password content=all full=y  directory=dump dumpfile=$filename logfile=$logname
cd /u10/dump
mv *.gz *.log /u09/hisdp
tar -czvf $SID_$action_time.tar.gz $filename $logname        #$SID 為oracle sid
rm $filename
chmod 755 $SID_$action_time.tar.gz $logname            #$SID 為oracle sid

#del dump data
path="/u09/hisdp"
echo "delete dump data 10 day ago"
rm -rf $path/$SID_$del_time.tar.gz        #$SID 為oracle sid
rm -rf $path/$SID_$del_time.log           #$SID 為oracle sid
echo "delete 10 dump data OK!"


###############/exp/backup/incr0.sh
# RMAN level o backup
#!/bin/sh
export ORACLE_SID=$SID        #$SID 為oracle sid
export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
export PATH=.:$ORACLE_HOME/bin:$PATH:.

rman target / << EOF
run
{
allocate channel d1 type disk maxpiecesize 4000m;
allocate channel d2 type disk maxpiecesize 4000m;
allocate channel d3 type disk maxpiecesize 4000m;
allocate channel d4 type disk maxpiecesize 4000m;
backup current controlfile format '/u09/orabackup/$SID/full/control/full_1_%d_%s_%p_%c.ctl';
backup incremental level 0 database format '/u09/orabackup/$SID/full/full_db_%d_%s_%p_%c.dbfbk'
plus archivelog delete input format '/u09/orabackup/$SID/full/full_log_%d_%s_%p_%c.dbfbk';
backup current controlfile format '/u09/orabackup/$SID/full/control/full_2_%d_%s_%p_%c.ctl';
release channel d4;
release channel d3;
release channel d2;
release channel d1;
}
exit
EOF


#################/exp/backup/incr1.sh
# RMAN level 1 backup
#!/bin/sh
export ORACLE_SID=$SID        #$SID 為oracle sid
export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
export PATH=.:$ORACLE_HOME/bin:$PATH:.
rman target / << EOF
run
{
allocate channel d1 type disk maxpiecesize 4000m;
allocate channel d2 type disk maxpiecesize 4000m;
allocate channel d3 type disk maxpiecesize 4000m;
allocate channel d4 type disk maxpiecesize 4000m;
backup current controlfile format '/u09/orabackup/$SID/control/%d_%s_%p_%c.ctl';             #$SID 為oracle sid
sql 'alter system switch logfile';
backup incremental level 1 database FORMAT   '/u09/orabackup/$SID/db_%d_%s_%p_%c.dbfbk'      #$SID 為oracle sid
plus archivelog delete input  FORMAT   '/u09/orabackup/$SID/log_%d_%s_%p_%c.dbfbk';          #$SID 為oracle sid
release channel d4;
release channel d3;
release channel d2;
release channel d1;
}
exit
EOF


##################/exp/backup/delete.sh
#!/bin/bash
export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
export PATH=.:$ORACLE_HOME/bin:PATH:.
#delete archivelog and database backup on primary database completed before 7 days
rman target sys/password@$SID  << EOF              #$SID 為oracle sid
delete force noprompt backup completed before 'sysdate-7';
delete force noprompt archivelog all completed before 'sysdate-7';
exit;
EOF

#delete archivelog on standby database completed  before 7 days
rman target sys/password@$SB_SID << EOF         #$SB_SID 為standby oracle sid
delete force noprompt archivelog all completed before 'sysdate-7';
exit;
EOF

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28539951/viewspace-1296700/,如需轉載,請註明出處,否則將追究法律責任。

相關文章