簡單的備份資料庫指令碼

db_wjw發表於2014-05-06
以oracle使用者登入系統:

1、建立資料庫備份檔案存放目錄和日誌存放目錄
mkdir -p /workdb/oracle_backup
mkdir -p /workdb/oracle_backup_logs

2、建立備份指令碼:
該指令碼為每週日進行資料庫全備,然後每天進行增量備份
vi /home/oracle/scripts/backuporacle.sh
內容如下:
#!/bin/sh
. $HOME/.bash_profile
backup_dir=/workdb/oracle_backup
backup_log_dir=/workdb/oracle_backup_logs
backup_date=`date +"%Y%m%d"`
backup_week=`date +"%w"`
ps -ef | grep dbw0_$ORACLE_SID | grep -v grep > /dev/null
if [ $? -eq 0 ]; then
    if [ "$backup_week" = "0" ]; then
rman target=/ log=$backup_log_dir/fulldbbackup$backup_date.log < run {
backup database format '$backup_dir/fullbackup_%d_%T_%U';
sql 'alter system archive log current';
backup archivelog all delete all input format '$backup_dir/archbackup_%d_%T_%U';
backup current controlfile format '$backup_dir/ctlbackup_%d_%T_%U';
delete noprompt obsolete;}
exit;
EOF
    else
rman target=/ log=$backup_log_dir/archbackup$backup_date.log < run {
backup archivelog all
format '$backup_dir/archbackup_%d_%T_%U' delete all input;}
exit;
EOF
    fi
fi

3、修改指令碼屬性為可以執行:
chmod u+x /home/oracle/scripts/backuporacle.sh

4、修改備份引數:
rman target /
RMAN> configure controlfile autobackup on;
RMAN> configure controlfile autobackup format for device type disk to '/workdb/oracle_backup/controlfile_www_%F';

5、讓指令碼在晚上自動執行:
crontab -e
00 02 * * * /home/oracle/scripts/backuporacle.sh > /dev/null 2>&1

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

相關文章