PostgreSQL備份之pg_rman

來源:互聯網
上載者:User

標籤:

一、 安裝

PostgreSQL版本是9.4.4

# git clone -b REL9_4_STABLE https://github.com/ossc-db/pg_rman.gitInitialized empty Git repository in /opt/pg_rman/.git/remote: Counting objects: 1939, done.remote: Total 1939 (delta 0), reused 0 (delta 0), pack-reused 1939Receiving objects: 100% (1939/1939), 702.67 KiB | 311 KiB/s, done.Resolving deltas: 100% (1393/1393), done.# yum install -y pam-devel readline-devel zlib-devel# make# make install/bin/mkdir -p ‘/opt/pg94/bin‘/usr/bin/install -c  pg_rman ‘/opt/pg94/bin‘# pg_rman --versionpg_rman 1.3.1

二、使用

首先需要初始化備份目錄

# mkdir -p /data/pg_backup# mkdir -p /data/test_xlog_94/fulltime# pg_rman  init --backup-path=/data/pg_backup/WARNING: ARCLOG_PATH is not set yetDETAIL: The archive_command is not set in postgresql.conf.HINT: Please set ARCLOG_PATH in pg_rman.ini or environmental variable.# vim /data/pg_backup/pg_rman.iniARCLOG_PATH=‘/data/test_xlog_94/fulltime‘

在master節點上製作一個全備,在從庫上需要指定--host, --standby-host=172.17.5.47 --standby-port=5432

#  pg_rman backup --backup-mode=full --backup-path=/data/pg_backup/ --pgdata=/data/test_pgdata_94/ -U postgres -d postgres                                             INFO: copying database filesNOTICE:  pg_stop_backup complete, all required WAL segments have been archivedINFO: copying archived WAL filesINFO: backup completeHINT: Please execute ‘pg_rman validate‘ to verify the files are correctly copied.# pg_rman show detail --backup-path=/data/pg_backup/============================================================================================================ StartTime           Mode  Duration    Data  ArcLog  SrvLog   Total  Compressed  CurTLI  ParentTLI  Status  ============================================================================================================2015-09-07 02:52:22  FULL        0m   422MB   106kB    ----   394MB       false       1          0  OK

使用備份進行恢複

# mkdir restore_test# pg_rman restore --backup-path=/data/pg_backup/ --pgdata=/data/restore_test/WARNING: could not open pg_controldata file "/data/restore_test//global/pg_control": No such file or directoryWARNING: could not open pg_controldata file "/data/restore_test//global/pg_control": No such file or directoryINFO: backup "2015-09-07 02:52:22" is validINFO: the recovery target timeline ID is not givenINFO: use timeline ID of latest full backup as recovery target: 1INFO: calculating timeline branches to be used to recovery target pointINFO: searching latest full backup which can be used as restore start pointINFO: found the full backup can be used as base in recovery: "2015-09-07 02:52:22"INFO: copying online WAL files and server log filesINFO: clearing restore destinationINFO: validate: "2015-09-07 02:52:22" backup and archive log files by SIZEINFO: backup "2015-09-07 02:52:22" is validINFO: restoring database files from the full mode backup "2015-09-07 02:52:22"INFO: searching incremental backup to be restoredINFO: searching backup which contained archived WAL files to be restoredINFO: backup "2015-09-07 02:52:22" is validINFO: restoring WAL files from backup "2015-09-07 02:52:22"INFO: restoring online WAL files and server log filesINFO: generating recovery.confINFO: restore completeHINT: Recovery will start automatically when the PostgreSQL server is started.

由於是用root使用者進行備份和恢複的,目錄許可權也是root,需要修改為postgres

# ls -ld /data/restore_test/drwxr-xr-x. 18 root root 4096 Sep  7 03:00 restore_test/# cat /data/restore_test/recovery.conf # recovery.conf generated by pg_rman 1.3.1restore_command = ‘cp /data/test_pgdata_94/pg_xlog/%f %p‘recovery_target_timeline = ‘1‘# chown -R postgres:postgres /data/restore_test/# chmod 0700 /data/restore_test/# ls -ld /data/restore_test/drwx------. 18 postgres postgres 4096 Sep  7 03:05 /data/restore_test/

將連接埠修改為5433,並啟動恢複的資料庫

$ pg_ctl -D /data/restore_test/ startserver starting[[email protected] data]$ [    2015-09-07 07:05:40.291 UTC 31889 55ed3744.7c91 1 0]LOG:  redirecting log output to logging collector process[    2015-09-07 07:05:40.291 UTC 31889 55ed3744.7c91 2 0]HINT:  Future log output will appear in directory "pg_log".$ psql -p 5433psql (9.4.4)Type "help" for help.

恢複到指定時間點的話,執行restore的時候使用如下參數:

  --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

會將相應的參數寫到recovery.conf裡面


參考:http://ossc-db.github.io/pg_rman/index.html

PostgreSQL備份之pg_rman

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.