1.下载对应数据库版本及操作系统的pg_rman源码
https://github.com/ossc-db/pg_rman/releases
本例使用的是centos6.9+pg10,因此下载的是pg_rman-1.3.7-pg10.tar.gz
源码是与操作系统无关的,在编译安装的时候会适配对应的操作系统
2.上传安装包并解压安装
# tar vxf pg_rman-1.3.7-pg10.tar.gz
# cd pg_rman-1.3.7-pg10
# export PATH=$PATH:/usr/local/pgsql/bin
# make
make时出现以下错误,提示找不到connect.h
pgut/pgut.c:11:30: error: fe_utils/connect.h: No such file or directory
pgut/pgut.c: In function ‘pgut_connect’:
pgut/pgut.c:949: error: ‘ALWAYS_SECURE_SEARCH_PATH_SQL’ undeclared (first use in this function)
pgut/pgut.c:949: error: (Each undeclared identifier is reported only once
pgut/pgut.c:949: error: for each function it appears in.)
make: *** [pgut/pgut.o] Error 1
解决方法,从其他版本copy一个connect.h过来
# cp /usr/local/pgsql-12.0/include/server/fe_utils/connect.h /usr/local/pgsql/include/server/fe_utils/
之后执行make
# make
# make install
验证rman,使用make installcheck验证
# chown -R postgres.postgres pg_rman-1.3.7-pg10
# su - postgres
$ cd /data/software/pg_rman-1.3.7-pg10
$ make installcheck
3.开启数据库归档
# su - postgres
$ cd /archlog
$ mkdir pg-10.0
$ cd $PGDATA
$ vi postgresql.conf
修改如下部分
# - Archiving -archive_mode = on # enables archiving; off, on, or always
# (change requires restart)
archive_command = 'test ! -f /archlog/pg-10.0/%f && cp %p /archlog/pg-10.0/%f' # command to use to archive a logfile segment
# placeholders: %p = path of file to archive
# %f = file name only
# e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f'
archive_timeout = 1800 # force a logfile segment switch after this
# number of seconds; 0 disables
修改后,需要重启数据库
$ pg_ctl restart
$ psql
#切换以下redo,测试归档设置是否OK
select pg_switch_wal();
4.配置环境变量
# su - postgres
$ vi .bash_profile
添加如下环境变量
export BACKUP_PATH=/pgdata/pg_rman_backup
5.初始化pg_rman,并全备测试
$ pg_rman init
$ pg_rman backup --backup-mode=full -C -P
$ pg_rman show
6.删除归档的脚本和后台执行全备的脚本
$ pg_archivecleanup -d /archlog/archivedir 000000010000EEF700000060
$ nohup pg_rman backup --backup-mode=full -C -P > /archlog/pg_rman_backup/full_backup.log 2>&1 &
第二个nohub,意思是no hung up,在每一个ssh断开的时候,会向其所有子进程发送hung up信号,子程序会停止,使用nohub后,在ssh退出时,程序会继续执行
&是后台执行的意思,会让这个命令在后台执行,但是在ssh退出后,程序会被退出,两者结合起来可以实现后台执行