#!/bin/bash
#使用数据泵备份,暂未备份到其它存储。自动清理本地过期备份,清理其它服务器备份到本地的过期备份
#配置文件路径:
BACKUP_DIR=/home/yz/bak #备份文件存储路径
DATE=`date '+%Y%m%d-%H%M'` #日期格式(作为文件名)
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export ORACLE_SID=rdt1
export ORACLE_TERM=xterm
#判断备份文件存储目录是否存在,否则创建该目录
if [ ! -d $BACKUP_DIR ] ;
mkdir -p "$BACKUP_DIR"
fi
cd $BACKUP_DIR
mkdir bak_expdp_$DATE
#expdp_dir_ora_user为directories路径,需先设定好导出路径
$ORACLE_HOME/bin/expdp ora_user/ora_user dumpfile=expdp_ora_user$DATE.dmp directory=expdp_dir_ora_user
mv $BACKUP_DIR/*.dmp $BACKUP_DIR/bak_expdp_$DATE
echo "开始压缩备份..............................."
gzip $BACKUP_DIR/bak_expdp_$DATE/*.dmp
echo "压缩完毕!"
find $BACKUP_DIR/* -mtime +10 -delete;
ls -lrt $BACKUP_DIR
ls -lrt $BACKUP_DIR/bak_expdp_$DATE
##将文件拷贝到异地存储,且删除异地存储拷贝到本地的过期备份文件
##$BACKUP_DIR/scp.sh $BACKUP_DIR/bak_expdp_$DATE/*.dmp.gz 10.1.11.25:/u02/DWDB_BACKUP/
#find $BACKUP_DIR/bak_expdp_* -atime +3 -exec rm -rf {} ;