oracle數據庫自動備份腳本

1、rman備份 

rman備份腳本:

#!/bin/sh
. ~/.bash_profile

log_file='oracle-rman-export.log'
function log(){
 cur_dateTime=`date +%Y-%m-%d,%H:%M:%S`
 echo $cur_dateTime'-->'$1
 echo $cur_dateTime'-->'$1 >>$log_file 2>&1
}

rman_base_dir=/home/oracle/rmanbak
baK_dir=`date +%Y%m%d`
cd $rman_base_dir
mkdir $baK_dir
log "--->begin run bak oracle ,date dir:$baK_dir"
/home/u01/app/oracle/product/11.2.0/db_1/bin/rman target / << EOF
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
sql 'alter system switch logfile';
backup as compressed backupset filesperset 10 incremental level 0 database format "$rman_base_dir/$baK_dir/db_full_bk_%d_%T_%t_%s_%p";
sql 'alter system switch logfile';
release  channel c1 ;
release  channel c2 ;
release  channel c3 ;
release  channel c4 ;

}
EOF

 

rman定時備份結果:

 

2、expdp

expdp 備份腳本:

#!/bin/sh
. ~/.bash_profile

log_file='oracle-export.log'
function log(){
 cur_dateTime=`date +%Y-%m-%d,%H:%M:%S`
 echo $cur_dateTime'-->'$1
 echo $cur_dateTime'-->'$1 >>$log_file 2>&1
}


data=`date +%Y%m%d`
log "begin export  db ,file[$DPDIR/${data}.dmp]"
expdp system/123456 schemas=HTOrder directory=DPDIR dumpfile=erp-${data}.dmp >> $log_file 2>&1
log "end export db"
archive_file_count=`find /home/oracle/dump -name *dmp|wc -l` #自動刪除歷史,保留最後的4天有效文件
if [ $archive_file_count -gt 4 ]; then
  log "begin delete oracle data archive file"$archive_file_count
  find /home/oracle/dump -mtime +3 -type f -name "*dmp" |xargs rm -f
fi

 

定時備份效果:

 

定時器:

41 2 * * *  /home/oracle/rmanbak.sh

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章