您的位置:首页 > 数据库

postgresql归档备份

2015-06-26 16:11 435 查看
主库配置

修改pg_hba.conf

local   replication     postgres                                trust
host    replication     postgres        127.0.0.1/32            trust
host    replication     postgres        ::1/128                 trust


修改postgresql.conf

wal_level = hot_standby    --WAL记录级别
--or wal_level = archive
max_wal_senders = 1        --允许几个链接读取WAL记录


执行
pg_basebackup -D basegd/ -R   --备份至目录basegb  -R生成recovery.conf文件
显示为

NOTICE:  WAL archiving is not enabled; you must ensure that all required WAL segments are copied through other means to complete the backup


继续编辑postgresql.conf

archive_mode = on
archive_command = 'cp %p /home/postgre/archivedir/%f'    --WAL归档目录
archive_timeout = 60    --强制60秒生成了一个归档文件


重新执行

pg_basebackup -D basegd/ -R
这次没有一些异常提示。

归档后如何恢复呢?

备库配置

编辑recovery.conf

restore_command='cp /home/postgres/archivedir/%f %p'                        --从WAL归档目录接受文件
archive_cleanup_command='pg_archivecleanup /home/postgres/archivedir %r'    --归档后可清理的不需要的WAL文件
recovery_end_command='touch /home/postgres/gd.tim'                          --完成后执行的shell命令


修改端口后启动。

tip:归档的好处,相当于时刻进行了增量备份。意味着

archive_timeout =60
秒备份了主库一次。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: