假设条件:
Linux用户名:whf
postgresql超级用户:postgres
postgresql版本:9.1
要备份的数据库名:icomplain_desktop
思路:
首先为 whf 添加数据库读写权限,然后将 pg_dump 命令写成shell脚本,最后使用crontab创建定时作业。
步骤:
切换到 postgres 用户:
sudo su postgres
psql
CREATE USER whf WITH PASSWORD ‘whf‘;
ALTER USER whf WITH SUPERUSER;
GRANT ALL PRIVILEGES ON DATABASE icomplain_desktop to whf;
编写备份脚本 backup-db.sh:
#!/bin/bash cur_time=`date +%Y-%m-%d_%T` pg_dump icomplain_desktop > "/home/whf/db-backup/icomplain_desktop-$cur_time.dmp" echo "backup finished"
crontab -e
# backup database at 22:00 every day 0 22 * * * /home/whf/bin/backup-db.sh
Linux下定时备份Postgresql数据库,布布扣,bubuko.com
原文:http://blog.csdn.net/neosmith/article/details/23431651