pg_rman是一款專門為postgresql設(shè)計的在線備份恢復(fù)的工具。其支持在線(熱備份)和基于時間點備份方式。
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
# 歸檔目錄
# 數(shù)據(jù)庫錯誤日志目錄
# 壓縮數(shù)據(jù)
# 保存歸檔文件個數(shù)
# 保存歸檔的天數(shù)
# 備份冗余度
# 保存?zhèn)浞菁瘯r間
# 保存日志文件個數(shù)
# 保存日志文件天數(shù)
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
數(shù)據(jù)恢復(fù)
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
備份策略演練
說明:
以上我們演練了全量增量的備份,以及全量增量的恢復(fù),除次之外pg_rman還可以指定備份的策略進行備份,例如備份以及歸檔備份的備份冗余度,備份以及歸檔備份保留的天數(shù)等,以下我們就以備份冗余度保存的份數(shù)進行演練:
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
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://specialneedsforspecialkids.com/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