pg_rman是一款专门为postgresql设计的在线备份恢复的工具。其支持在线(热备份)和基于时间点备份方式。
pg_rman的安装
yum install -y bison flex readline-devel zlib-deve1 zlib zlib-devel gcc
tar xf pg_rman-1.3.14-pg14.tar.gz
make && make install
mkdir /pg_rman_backup/{fullbackup,walbackup,pg_srvlog} -p
chown -R postgres:postgres /pg_rman_backup
vim /etc/profile
export BACKUP_PATH=/pg_rman_backup/fullbackup
export ARCLOG_PATH=/pg_rman_backup/walbackup
export SRVLOG_PATH=/pg_rman_backup/pg_srvlog
vim postgresql.conf
archive_mode = on
archive_command = DATE=`date +%Y%m%d`; DIR="/pg_rman_backup/walbackup/"; (test -d $DIR || mkdir -p $DIR) && cp %p $DIR/%f
pg_rman init
pg_rman -B /pg_rman_backup/fullbackup -D /postgres/data -A /pg_rman_backup/walbackup init
# 归档目录
# 数据库错误日志目录
# 压缩数据
# 保存归档文件个数
# 保存归档的天数
# 备份冗余度
# 保存备份集时间
# 保存日志文件个数
# 保存日志文件天数
KEEP_SRVLOG_DAYS = 10
1)Usage
2)Common Options
-c, --check
-P, --progress
-b, --backup-mode=full, incremental, or archive
-s, --with-serverlog
-Z, --compress-data
-C, --smooth-checkpoint
-F, --full-backup-on-error
--keep-data-generations=NUM
--keep-data-days=NUM
--keep-arclog-files=NUM
--keep-arclog-days=DAY
--keep-srvlog-files=NUM
--keep-srvlog-days=DAY
--standby-host=HOSTNAME
--recovery-target-time
--recovery-target-xid
--recovery-target-inclusive
--recovery-target-timeline
--hard-copy
-a, --show-all
-d, --dbname=DBNAME
-h, --host=HOSTNAME
-p, --port=PORT
-U, --username=USERNAME
-w, --no-password
-q, --quiet
--debug
--help
--version
pg_rman全量备份
create database test;
create table t1 (id int);
insert into t1 values (1);
pg_rman backup --backup-mode=full --with-serverlog –progress
pg_rman --backup-path /pg_rman_backup/fullbackup --pgdata
/postgres/data --arclog-path /pg_rman_backup/walbackup
backup -b full -s --srvlog-path=/pg_rman_backup/pg_srvlog -U
postgres -d postgres -h 127.0.0.1 -p 5432
pg_rman -B /pg_rman_backup/fullbackup -A
/pg_rman_backup/walbackup -D /postgres/data backup -b full -
s -S /pg_rman_backup/pg_srvlog -U postgres -d postgres -h
10.0.0.10 -p 5432 --standby-host=10.0.0.11 --standby-
port=5432
pg_rman validate
pg_rman show
增量备份
insert into t1 values (2);
pg_rman backup --backup-mode incremental --progress --compress-data
pg_rman --backup-path /pg_rman_backup/fullbackup --pgdata
/postgres/data --arclog-path /pg_rman_backup/walbackup
backup --backup-mode incremental --progress --compress-data
-U postgres -d postgres -h 127.0.0.1 -p 5432
pg_rman -B /pg_rman_backup/fullbackup -D /postgres/data -A
/pg_rman_backup/walbackup backup --backup-mode incremental -
-progress --compress-data -U postgres -d postgres -h
10.0.0.10 -p 5432 --standby-host=10.0.0.11 --standby-
port=5432
pg_rman validate
删除备份
pg_rman delete -f 2022-08-16 20:28:21
pg_rman purge
pg_rman delete 2022-08-16 20:28:21
pg_rman purge
数据恢复
drop database test;
pg_ctl stop
pg_rman restore -B /pg_rman_backup/fullbackup/ --recovery-target-time "2022-08-16 20:14:58" --hard-copy
提示:
drop database test;
pg_ctl stop
pg_rman restore -B /pg_rman_backup/fullbackup/ --recovery-target-time "2022-08-16 20:15:01" --hard-copy
备份策略演练
说明:
以上我们演练了全量增量的备份,以及全量增量的恢复,除次之外pg_rman还可以指定备份的策略进行备份,例如备份以及归档备份的备份冗余度,备份以及归档备份保留的天数等,以下我们就以备份冗余度保存的份数进行演练:
vi pg_rman.ini
KEEP_DATA_GENERATIONS = 3
pg_rman -B /pg_rman_backup/fullbackup -A
/pg_rman_backup/walbackup -D /postgres/data backup -b full -
s -S /pg_rman_backup/pg_srvlog -U postgres -d postgres -h
10.0.0.10 -p 5432 --standby-host=10.0.0.11 --standby-
port=5432
pg_rman validate
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/129265.html
pg_rman备份工具(下) img{ display:block; margin:0 auto !important; width:100%; } body{ width:75%; marg...
阅读 1346·2023-01-11 13:20
阅读 1684·2023-01-11 13:20
阅读 1132·2023-01-11 13:20
阅读 1858·2023-01-11 13:20
阅读 4100·2023-01-11 13:20
阅读 2704·2023-01-11 13:20
阅读 1385·2023-01-11 13:20
阅读 3597·2023-01-11 13:20