標籤:
#!/bin/bash
#Oracle 環境變數NLS_LANG=AMERICAN_AMERICA.AL32UTF8ORACLE_SID=zgwORACLE_BASE=/opt/oracleORACLE_HOME=/opt/oracle/11gPATH=$PATH:$ORACLE_HOME/bin:$HOME/binexport ORACLE_SID ORACLE_BASE ORACLE_HOME NLS_LANG PATH#擷取時間戳記export BAKUPTIME=`date +%Y%m%d%H%M%S`
#dump檔案組建目錄export DATA_DIR=/home/oracle/backup/dump
#壓縮檔存放目錄export TAR_DIR=/home/oracle/backup/tarsmkdir -p $DATA_DIRmkdir -p $TAR_DIRcd $DATA_DIR echo "Starting bakup..."echo "Bakup file path $DATA_DIR/scott_expdp_$BAKUPTIME.dmp"
#使用expdp時需要先指定轉儲檔案和記錄檔所在的目錄,可以通過如下命令實現
#SQL>CREATE OR REPLACE DIRECTORY scott_backup as ‘/home/oracle/backup/dump‘;
#SQL>grant read,write on directory scott_backup to SCOTT;
expdp scott/scott directory=scott_backup dumpfile=scott_expdp_$BAKUPTIME.dump logfile=scott_expdp_$BAKUPTIME.log parallel=4
#parallel=4 為並行度,對於備份大資料庫有助於減少備份時間,但會增加CPU負載。
echo "Starting tar..."echo "Tar file path $TAR_DIR/SCOTT_$BAKUPTIME.tar.gz"tar -zcvf $TAR_DIR/scott_expdp_$BAKUPTIME.tar.gz scott_expdp*echo "Bakup job is done!"#曆史dump檔案保留7天find $DATA_DIR -type f -mtime +7 -exec rm -rf {} \;
參考:http://blog.itpub.net/235507/viewspace-704379/
oracle expdp 備份指令碼