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退出后,程序會被退出,兩者結合起來可以實現后台執行