postgresql定时备份
需求:
每天凌晨4点按日期执行自动备份,生产.dump文件。备份文件保存15天。
#vim /var/lib/pgsql/backup.sh
#!/bin/bash
cur_time=$(date ‘+%Y-%m-%d‘)
ifteendays_time=$(date -d -15days ‘+%Y-%m-%d‘)
rm -rf /var/lib/pgsql/pgsql-backup.$fifteendays_time.dump
echo "Starting Backup PostgreSQL ..."
/usr/local/postgresql/bin/pg_dumpall -U postgres -p 3433 > /var/lib/pgsql/"pgsql-backup.$cur_time.dump"
echo "Finish Backup ..."
#chmod 755 /var/lib/pgsql/back.up
#su - postgres
$crontab -e
00 4 * * * /var/lib/pgsql/backup.sh
原文地址:http://blog.51cto.com/13889476/2174249
时间: 2024-10-31 10:33:13