postgresql 物理备份 pg_rman 之一 setup

os: centos 7.4
postgresql: 9.6.9
pg_rman: REL9_6_STABLE

pg_rman 是一款优秀的postgresql 在线备份和恢复的工具,在github上可以找到该软件。
下面是pg_rman主页面的描述:

pg_rman is an online backup and restore tool for PostgreSQL.

The goal of the pg_rman project is to provide a method for online backup and PITR that is as easy as pg_dump. Also, it maintains a backup catalog per database cluster. Users can maintain old backups including archive logs with one command.

下载

https://github.com/ossc-db/pg_rman

由于本次的postgresql 版本为 9.6.9,所以需要下载相应的pg_rman REL9_6_STABLE : branch for PostgreSQL 9.6

# su - postgres
$ cd /tmp
$ git clone https://github.com/ossc-db/pg_rman.git
$ cd pg_rman/
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/REL9_2_STABLE
  remotes/origin/REL9_3_STABLE
  remotes/origin/REL9_4_STABLE
  remotes/origin/REL9_5_STABLE
  remotes/origin/REL9_6_STABLE
  remotes/origin/REL_10_STABLE
  remotes/origin/master
  remotes/origin/pre-9.2
$ git checkout REL9_6_STABLE
Already on 'REL9_6_STABLE'
$ git status
$ On branch REL9_6_STABLE
nothing to commit, working directory clean

安装

前提是postgresl 9.6 已经安装好了。

# su - postgres
$ cd /tmp/pg_rman
$ make
$ make install
$ make installcheck
$ ls -l /usr/pgsql-9.6/bin | grep -i rman
-rwxr-xr-x. 1 root root  633680 Jun 11 23:08 pg_rman

使用 yum 安装的需要在root下执行 make install,使用源码编译安装的在postgres用户下执行即可。

pg_rman --help

$ which pg_rman
/usr/pgsql-9.6/bin/pg_rman
$ pg_rman --help
pg_rman manage backup/recovery of PostgreSQL database.

Usage:
  pg_rman OPTION init
  pg_rman OPTION backup
  pg_rman OPTION restore
  pg_rman OPTION show [DATE]
  pg_rman OPTION show detail [DATE]
  pg_rman OPTION validate [DATE]
  pg_rman OPTION delete DATE
  pg_rman OPTION purge

Common Options:
  -D, --pgdata=PATH         location of the database storage area
  -A, --arclog-path=PATH    location of archive WAL storage area
  -S, --srvlog-path=PATH    location of server log storage area
  -B, --backup-path=PATH    location of the backup storage area
  -c, --check               show what would have been done
  -v, --verbose             show what detail messages
  -P, --progress            show progress of processed files

Backup options:
  -b, --backup-mode=MODE    full, incremental, or archive
  -s, --with-serverlog      also backup server log files
  -Z, --compress-data       compress data backup with zlib
  -C, --smooth-checkpoint   do smooth checkpoint before backup
  -F, --full-backup-on-error   switch to full backup mode
                               if pg_rman cannot find validate full backup
                               on current timeline
      NOTE: this option is only used in --backup-mode=incremental or archive.
  --keep-data-generations=NUM keep NUM generations of full data backup
  --keep-data-days=NUM        keep enough data backup to recover to N days ago
  --keep-arclog-files=NUM   keep NUM of archived WAL
  --keep-arclog-days=DAY    keep archived WAL modified in DAY days
  --keep-srvlog-files=NUM   keep NUM of serverlogs
  --keep-srvlog-days=DAY    keep serverlog modified in DAY days
  --standby-host=HOSTNAME   standby host when taking backup from standby
  --standby-port=PORT       standby port when taking backup from standby

Restore options:
  --recovery-target-time    time stamp up to which recovery will proceed
  --recovery-target-xid     transaction ID up to which recovery will proceed
  --recovery-target-inclusive whether we stop just after the recovery target
  --recovery-target-timeline  recovering into a particular timeline
  --hard-copy                 copying archivelog not symbolic link

Catalog options:
  -a, --show-all            show deleted backup too

Delete options:
  -f, --force               forcibly delete backup older than given DATE

Connection options:
  -d, --dbname=DBNAME       database to connect
  -h, --host=HOSTNAME       database server host or socket directory
  -p, --port=PORT           database server port
  -U, --username=USERNAME   user name to connect as
  -w, --no-password         never prompt for password
  -W, --password            force password prompt

Generic options:
  -q, --quiet               don't show any INFO or DEBUG messages
  --debug                   show DEBUG messages
  --help                    show this help, then exit
  --version                 output version information, then exit

Read the website for details. 
Report bugs to .

pg_rman init

pg_rman 需要一个备份目录

# mkdir -p /mnt/walbackup
# mkdir -p /mnt/pg_rman_backupset
# chown -R postgres:postgres /mnt
$ ls -l
total 0
drwxr-xr-x. 2 postgres postgres 6 Jun 11 23:24 pg_rman_backupset
drwxr-xr-x. 2 postgres postgres 6 Jun 11 23:05 walbackup

pg_rman 需要这几个变量

$ vi ~/.bash_profile
export PGHOME=/usr/pgsql-9.6
export PGDATA=/var/lib/pgsql/9.6/data

export SRVLOG_PATH=/var/lib/pgsql/9.6/data/pg_log
export ARCLOG_PATH=/mnt/walbackup
export BACKUP_PATH=/mnt/pg_rman_backupset

pg_rman init 初始化

$ pg_rman init -B /mnt/pg_rman_backupset
INFO: ARCLOG_PATH is set to '/mnt/walbackup'
INFO: SRVLOG_PATH is set to '/var/lib/pgsql/9.6/data/pg_log'

安装挺简单的。

参考:
https://github.com/ossc-db/pg_rman/tree/master
http://ossc-db.github.io/pg_rman/index.html
https://travis-ci.org/ossc-db/pg_rman

你可能感兴趣的:(#,postgresql,backup,recovery)