标签:http pre 描述 数据库文件 postgre ali end done count
postgres数据库之前没有备份机制,现在加上以防万一。每周末备份1次,只保留最新的3个sql文件
#config begin
meta_host="*.*.*.*"
mete_user="mete_user"
mete_databse="mete_databse"
mete_password="mete_password"
meta_port="meta_port"
back_path="/home/soft/psql/backup/"
back_count=3
#config end
echo $(date +%Y-%m-%d\ %H:%M:%S)" pg_dump begin"
#备份数据库文件
date=$(date +%Y-%m-%d)
PGPASSWORD=${mete_password} /opt/PostgreSQL/9.5/bin/pg_dump -U ${mete_user} -d ${mete_databse} > ${back_path}sjck_${date}.sql
echo $(date +%Y-%m-%d\ %H:%M:%S)" pg_dump end"
#只保留最新的3个文件,删除旧的
c=0
for file in `ls ${back_path}`
do
filelist[$c]=$file
((c++))
done
size=${#filelist[*]}
echo "文件数组长度:" ${size}
for value in ${filelist[@]}
do
echo $value
done
if [ ${size} -gt ${back_count} ]
then
echo "size>" ${back_count}
for ((i=0; i<${size}-${back_count}; i++))
do
echo "要删除的过期excel文件夹:" ${filelist[$i]}
rm -rf ${back_path}${filelist[$i]}
done
else
echo "size<=" ${back_count}
fi
echo $(date +%Y-%m-%d\ %H:%M:%S)" task end"
标签:http pre 描述 数据库文件 postgre ali end done count
原文地址:https://www.cnblogs.com/wanli002/p/11174034.html