oracle expdp 备份脚本

#!/bin/bash
#Oracle 环境变量 NLS_LANG
=AMERICAN_AMERICA.AL32UTF8 ORACLE_SID=zgw ORACLE_BASE=/opt/oracle ORACLE_HOME=/opt/oracle/11g PATH=$PATH:$ORACLE_HOME/bin:$HOME/bin export 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/tars mkdir -p $DATA_DIRmkdir -p $TAR_DIR cd $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/

posted @ 2015-05-27 17:17  艾阳君  阅读(913)  评论(0编辑  收藏  举报