ORACLE常用定時備份指令碼
[oracle@rac1 ~]$ crontab -l
0 13 * * * /home/oracle/dumpfile/datapump_exp.sh
0 6 * * * /home/oracle/auto_clear_archivelog/auto_clear_archivelog.sh
0 */3 * * * /home/oracle/auto_clear_archivelog/ auto_purge_recyclebin.sh
30 2 * * * /home/oracle/rman_backup/scripts/backup.sh
50 7 * * * /home/oracle/rman_backup/scripts/backup_archivelog.sh
1、資料庫全庫匯出指令碼
[oracle@rac1 dumpfile]$ cat datapump_exp.sh
#!/bin/sh export MYDIR=/home/oracle/dumpfile export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK export ORACLE_SID=prod1 export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 export PATH=$PATH:$ORACLE_HOME/bin export TNS_ADMIN=$ORACLE_HOME/network/admin export DAY_FORMAT=`date +'%Y%m%d%H%M'` ( cd $MYDIR echo "###################################################################################" echo "`date` removing old files..." 2>&1; find . -mtime +5 -name "prod_*.dmp" -exec rm -rf {} \; find . -mtime +5 -name "prod_*.log" -exec rm -rf {} \; echo "`date` removed" 2>&1 echo "`date` exporting fully ..." 2>&1 expdp \'sys/oracle@prod1 as sysdba\' DIRECTORY=MYDIR DUMPFILE=prod_${DAY_FORMAT}_%U.dmp LOGFILE=budget_${DAY_FORMAT}.log FULL=Y PARALLEL=8 COMPRESSION=ALL CLUSTER=N JOB_NAME=prod_exp_${DAY_FORMAT} 1>/dev/null 2>&1 echo "`date` export done" 2>&1 )>>$MYDIR/expdp.log
注意前提:
新建邏輯目錄,並在作業系統層面oracle使用者建立對應的資料夾
[oracle@rac1:/home/oracle]$sqlplus / as sysdba SQL> create directory MYDIR AS '/home/oracle/dumpfile';
針對sys/oracle@prod1 as sysdba中的prod1 tnsping測試ok 我這裡是rac環境,在tnsnames.ora配置了prod1
2、資料庫備份指令碼
[oracle@rac1:/home/oracle/rman_backup/scripts]$cat backup_sh
#!/bin/bash RMAN_BACKUP_DIR=/home/oracle/rman_backup export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK export ORACLE_SID=prod1 export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 export PATH=$PATH:$ORACLE_HOME/bin export TNS_ADMIN=$ORACLE_HOME/network/admin export MAXPIECESIZE=32G export INCR_LEVEL=$((0)) export day=`date +%w` export DAY_DATE=`date +'%Y%m%d'` export DAY_FORMAT=`date +'%Y%m%d%H%M%S'` export TAG_NAME=TAG_Incr${INCR_LEVEL}_${DAY_FORMAT} echo "-----doing!!-----" >> $RMAN_BACKUP_DIR/rman_backup_log.log rman log=$RMAN_BACKUP_DIR/rman_backup_log.log <<EOF connect target / run { allocate channel 'ch1' TYPE DISK maxpiecesize=${MAXPIECESIZE}; allocate channel 'ch2' TYPE DISK maxpiecesize=${MAXPIECESIZE}; backup incremental level ${INCR_LEVEL} database tag ${TAG_NAME} format '${RMAN_BACKUP_DIR}/${ORACLE_SID}_${DAY_DATE}_db_%U'; sql 'alter system archive log current'; backup archivelog all format '${RMAN_BACKUP_DIR}/${ORACLE_SID}_${DAY_DATE}_arc_%U'; backup current controlfile format '${RMAN_BACKUP_DIR}/${ORACLE_SID}_${DAY_DATE}_ctl_%U'; release channel ch1; release channel ch2; } exit; EOF echo `date '+%Y-%m-%d %H:%M:%S'` >> $RMAN_BACKUP_DIR/rman_backup_log.log echo "-----done!!-----" >> $RMAN_BACKUP_DIR/rman_backup_log.log cat $RMAN_BACKUP_DIR/rman_backup_log.log >> $RMAN_BACKUP_DIR/rman_backup_history.log cd $RMAN_BACKUP_DIR find . -mtime +7 -name "prod1_*" -exec rm -rf {} \;
3、歸檔日誌備份指令碼
[oracle@rac1:/home/oracle/auto_clear_archivelog]$cat auto_clear_archivelog.sh
#!/bin/sh LOG_DIR=/home/oracle/auto_clear_archivelog export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK export ORACLE_SID=prod1 export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 export PATH=$PATH:$ORACLE_HOME/bin export TNS_ADMIN=$ORACLE_HOME/network/admin echo "-----doing!!-----" >> $LOG_DIR/rman_delete_archivelog.log rman log=$LOG_DIR/rman_delete_archivelog.log target / <<EOF delete force noprompt archivelog all completed before 'sysdate-2'; crosscheck archivelog all; delete noprompt expired archivelog all; exit; EOF echo `date '+%Y-%m-%d %H:%M:%S'` >> $LOG_DIR/rman_delete_archivelog.log echo "-----done!!-----" >> $LOG_DIR/rman_delete_archivelog.log cat $LOG_DIR/rman_delete_archivelog.log >> $LOG_DIR/delete_history.log
4、歸檔清理指令碼
[oracle@rac1:/home/oracle/auto_clear_archivelog]$cat auto_clear_archivelog.sh
#!/bin/sh LOG_DIR=/home/oracle/auto_clear_archivelog export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK export ORACLE_SID=prod1 export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 export PATH=$PATH:$ORACLE_HOME/bin export TNS_ADMIN=$ORACLE_HOME/network/admin echo "-----doing!!-----" >> $LOG_DIR/rman_delete_archivelog.log rman log=$LOG_DIR/rman_delete_archivelog.log target / <<EOF delete force noprompt archivelog all completed before 'sysdate-2'; crosscheck archivelog all; delete noprompt expired archivelog all; exit; EOF echo `date '+%Y-%m-%d %H:%M:%S'` >> $LOG_DIR/rman_delete_archivelog.log echo "-----done!!-----" >> $LOG_DIR/rman_delete_archivelog.log cat $LOG_DIR/rman_delete_archivelog.log >> $LOG_DIR/delete_history.log
5、 參考指令碼,可根據需要更改
cat backup.sh_bak
#!/bin/bash RMAN_BACKUP_DIR=/home/oracle/rman_backup export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK export ORACLE_SID=prod1 export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 export PATH=$PATH:$ORACLE_HOME/bin export TNS_ADMIN=$ORACLE_HOME/network/admin export MAXPIECESIZE=32G export INCR_LEVEL=$((0)) export day=`date +%w` if [ $day -eq 0 ] ; then INCR_LEVEL=$((0)) fi if [ $day -eq 1 ] ; then INCR_LEVEL=$((2)) fi if [ $day -eq 2 ] ; then INCR_LEVEL=$((2)) fi if [ $day -eq 3 ] ; then INCR_LEVEL=$((1)) fi if [ $day -eq 4 ] ; then INCR_LEVEL=$((2)) fi if [ $day -eq 5 ] ; then INCR_LEVEL=$((2)) fi if [ $day -eq 6 ] ; then INCR_LEVEL=$((1)) fi export DAY_DATE=`date +'%Y%m%d'` export DAY_FORMAT=`date +'%Y%m%d%H%M%S'` export TAG_NAME=TAG_Incr${INCR_LEVEL}_${DAY_FORMAT} echo "-----doing!!-----" >> $RMAN_BACKUP_DIR/rman_backup_log.log rman log=$RMAN_BACKUP_DIR/rman_backup_log.log <<EOF connect target / run { allocate channel 'ch1' TYPE DISK maxpiecesize=${MAXPIECESIZE}; allocate channel 'ch2' TYPE DISK maxpiecesize=${MAXPIECESIZE}; backup incremental level ${INCR_LEVEL} database tag ${TAG_NAME} format '${RMAN_BACKUP_DIR}/${ORACLE_SID}_${DAY_DATE}_db_%U'; sql 'alter system archive log current'; backup archivelog all format '${RMAN_BACKUP_DIR}/${ORACLE_SID}_${DAY_DATE}_arc_%U' delete input; backup current controlfile format '${RMAN_BACKUP_DIR}/${ORACLE_SID}_${DAY_DATE}_ctl_%U'; release channel ch1; release channel ch2; } exit; EOF echo `date '+%Y-%m-%d %H:%M:%S'` >> $RMAN_BACKUP_DIR/rman_backup_log.log echo "-----done!!-----" >> $RMAN_BACKUP_DIR/rman_backup_log.log cat $RMAN_BACKUP_DIR/rman_backup_log.log >> $RMAN_BACKUP_DIR/rman_backup_history.log cd $RMAN_BACKUP_DIR find . -mtime +7 -name "prod1_*" -exec rm -rf {} \;
6、清空oracle表空間回收站
cat auto_purge_recyclebin.sh
#!/bin/bash source ~/.bash_profile sqlplus -S /nolog > result.log<<EOF #set heading off feedback off pagesize 0 verify off echo off conn / as sysdba PURGE tablespace tbs_cc user cc; exit EOF
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/70004783/viewspace-2792540/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle rman 定時備份指令碼Oracle指令碼
- Oracle用指令碼定時執行備份Oracle指令碼
- mysql每天定時備份指令碼MySql指令碼
- mysql定時備份shell指令碼MySql指令碼
- RMAN定時全備份指令碼指令碼
- Mysql定時備份資料指令碼MySql指令碼
- 【DATAPUMP】Oracle資料泵定時備份刪除指令碼Oracle指令碼
- RMAN常用備份指令碼指令碼
- ORACLE備份指令碼Oracle指令碼
- oracle 備份指令碼Oracle指令碼
- Oracle使用資料泵定時備份多個schema的指令碼Oracle指令碼
- linux mysql定時備份指令碼記錄LinuxMySql指令碼
- ORACLE日常備份指令碼Oracle指令碼
- Oracle 集中備份指令碼Oracle指令碼
- oracle RMAN備份指令碼Oracle指令碼
- oracle_備份指令碼Oracle指令碼
- Oracle冷備份(一致備份)指令碼Oracle指令碼
- [Oracle] rman備份指令碼(2)Oracle指令碼
- oracle for linux 備份指令碼OracleLinux指令碼
- Oracle邏輯備份指令碼Oracle指令碼
- oracle rman備份指令碼收集Oracle指令碼
- Oracle物理冷備份指令碼Oracle指令碼
- Linux定時備份資料庫與指令碼加密Linux資料庫指令碼加密
- MySQL自動備份指令碼及異地定時FTPMySql指令碼FTP
- 分享Oracle Rman的備份指令碼Oracle指令碼
- oracle自動冷備份指令碼Oracle指令碼
- ORACLE自動備份shell指令碼Oracle指令碼
- Oracle用指令碼執行備份Oracle指令碼
- [Oracle] rman備份的指令碼(1)Oracle指令碼
- ORACLE RMAN備份的指令碼配置Oracle指令碼
- Oracle物理熱備份指令碼(ZT)Oracle指令碼
- oracle備份指令碼_user_passwordOracle指令碼
- 自動定時備份 mysql 資料庫 的 shell 指令碼MySql資料庫指令碼
- 備份指令碼指令碼
- oracle11g Rman 備份指令碼Oracle指令碼
- linux下oracle熱備份指令碼LinuxOracle指令碼
- windows 下的Oracle 冷備份指令碼WindowsOracle指令碼
- oracle 自動冷備份指令碼(轉)Oracle指令碼