pgsql定时备份脚本

脚本如下

#!/bin/bash
cur_time=$(date '+%Y-%m-%d')
sevendays_time=$(date -d -7days '+%Y-%m-%d')
export PGPASSWORD=yishi!123
echo "Starting Backup PostgreSQL ..."
rm -rf pgsql-backup.$sevendays_time.tar
/usr/local/pgsql/bin/pg_dump -Ft -U yishi -p port -h host > "pgsql-backup.$cur_time.tar"
# tar zcvf "/root/dump_sql/pgsql-backup.$cur_time.tar.gz" *.sql
echo "Remove temp file ..."
# rm -rf pgsql-backup.*.tar
echo "Finish Backup ..."

删除7天前备份的脚本
恢复命令

pg_restore –d restored pgsql-backup.$cur_time.tar

你可能感兴趣的:(pgsql定时备份脚本)