ymd=$(date +%Y%m%d)
echo "日期:$ymd"
echo
keepday=5
echo "保留最近天数:$keepday"
echo
dirsync=/package/autosync/sync
echo "同步目录:$dirsync"
echo
dbname="ABC"
echo "数据库:$dbname"
echo
dbconn=system/oracle@orcl
echo "数据库连接字符串:$dbconn"
echo
db_directory_name="DATA_PUMP_DIR"
echo "数据库管理员目录名:$db_directory_name"
echo
db_directory_path="/u01/app/oracle/admin/EE/dpdump/"
echo "数据库管理员目录路径:$db_directory_path"
echo
echo "清理同步目录 $keepday 天前的备分文件"
find ${dirsync} -mtime +$keepday -name "*.zip" | xargs -I {} rm -rf {}
find ${dirsync} -mtime +$keepday -name "*.gz" | xargs -I {} rm -rf {}
echo
echo "开始备份数据库:$dbname"
backcmd="expdp ${dbconn} schemas=${dbname} dumpfile=${dbname}_${ymd}.dmp logfile=${dbname}_${ymd}.log directory=${db_directory_name}"
echo $backcmd
docker exec oracle11 /bin/bash -c "${backcmd}"
echo
echo "完成备份"
echo
echo "开始打包"
zip -r -q -o ${db_directory_path}${dbname}_${ymd}.zip ${db_directory_path}${dbname}_${ymd}.* -P123456789
echo
echo "移动压缩包"
mv ${db_directory_path}${dbname}_${ymd}.zip ${dirsync}
echo
echo "清理备份文件:${db_directory_path}${dbname}_${ymd}.*"
rm -f ${db_directory_path}${dbname}_${ymd}.*
echo
echo "Done"
echo