總結一下 BART 2.0 的功能
- 支援版本:9.5 版以上的 PGSQL 或企業版
- 完整全備份管理
- 解析 WAL,以產生 block-based incremental backup
- 對 全備份 / incremental backup 的時間點之後,複製所需的 WAL,進行指定還原點的 Point-in-Time Recovery 功能
現在,在 CentOS 7 上進行新功能的筆記。。此處環境
資料庫 IP:10.146.0.2,叫做 edbvm
備份主機 IP:10.146.0.4,叫做 bartvm
資料庫 IP:10.146.0.2,叫做 edbvm
備份主機 IP:10.146.0.4,叫做 bartvm
大致上,之前的筆記幾乎能夠適用。比較直接的變動是指定設定檔的參數從 -f 改成 -c,以及每一台資料庫主機也要安裝這個工具,才能進行增量備份 / 還原。在這就直接補充新功能的操作紀錄。
EDB BART 在 CentOS 7.x 的相依套件為
- boost-chrono-1.53.0-26.el7.x86_64 from base
- boost-filesystem-1.53.0-26.el7.x86_64 from base
- boost-serialization-1.53.0-26.el7.x86_64 from base
- boost-timer-1.53.0-26.el7.x86_64 from base
以及 pg_basebackup 和 libpq.so.5。在 CentOS 6.x 的話,Boost 需要從 EPEL 取得 1.48 版的套件;而 libpq.so.5 可以透過以下方式弄到(記得不論什麼方式,都麻煩要訂閱才能用這個工具喔~We play fair.)
- 安裝 PGSQL 社群 YUM Repo 的 lib(例如 postgresql96-lib)還有 postgresql96-server
- EnterpriseDB 訂閱用戶,安裝 EDB YUM Repo 的 lib 套件
- 使用 EDB 的產品安裝檔,可以設定 /etc/ld.so.conf,將 pg_config --libdir 顯示的目錄路徑加到裡面(也可以使用 LD_LIBRARY_PATH 環境變數進行一樣的設定),然後用 rpm -ivh --nodeps 安裝
[root@bartvm ~]# yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm [root@bartvm ~]# sudo yum install edb-bart20-2.0.0-beta2.rhel7.x86_64.rpm [root@bartvm ~]# ls /usr/edb/bart2.0/* /usr/edb/bart2.0/bart_license.txt /usr/edb/bart2.0/bin: bart bart-scanner /usr/edb/bart2.0/etc: bart.cfg /usr/edb/bart2.0/lib: xlogreader_D087.so xlogreader_D093.so [root@bartvm ~]#
如果用 --nodeps 安裝,可以用 ldd 檢查是否安裝正常
[root@bartvm ~]# ldd /usr/edb/bart2.0/bin/bart linux-vdso.so.1 => (0x00007fffbbfbd000) libboost_thread-mt.so.1.53.0 => /lib64/libboost_thread-mt.so.1.53.0 (0x00007f2b77106000) libboost_system-mt.so.1.53.0 => /lib64/libboost_system-mt.so.1.53.0 (0x00007f2b76f01000) libboost_serialization-mt.so.1.53.0 => /lib64/libboost_serialization-mt.so.1.53.0 (0x00007f2b76c95000) libboost_iostreams-mt.so.1.53.0 => /lib64/libboost_iostreams-mt.so.1.53.0 (0x00007f2b76a7b000) libboost_filesystem-mt.so.1.53.0 => /lib64/libboost_filesystem-mt.so.1.53.0 (0x00007f2b76863000) libpq.so.5 => /usr/pgsql-9.6/lib/libpq.so.5 (0x00007f2b76633000) libtar.so.1 => /lib64/libtar.so.1 (0x00007f2b76427000) libz.so.1 => /lib64/libz.so.1 (0x00007f2b76210000) libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x00007f2b75ed9000) libssl.so.10 => /lib64/libssl.so.10 (0x00007f2b75c6b000) libcrypto.so.10 => /lib64/libcrypto.so.10 (0x00007f2b75880000) libboost_timer-mt.so.1.53.0 => /lib64/libboost_timer-mt.so.1.53.0 (0x00007f2b7567b000) libboost_chrono-mt.so.1.53.0 => /lib64/libboost_chrono-mt.so.1.53.0 (0x00007f2b75473000) libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f2b75169000) libm.so.6 => /lib64/libm.so.6 (0x00007f2b74e67000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f2b74c51000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f2b74a34000) libc.so.6 => /lib64/libc.so.6 (0x00007f2b74673000) librt.so.1 => /lib64/librt.so.1 (0x00007f2b7446b000) libbz2.so.1 => /lib64/libbz2.so.1 (0x00007f2b7425a000) libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f2b7400c000) libldap_r-2.4.so.2 => /lib64/libldap_r-2.4.so.2 (0x00007f2b73daf000) libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f2b73ac8000) libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f2b738c4000) libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f2b73691000) libdl.so.2 => /lib64/libdl.so.2 (0x00007f2b7348d000) /lib64/ld-linux-x86-64.so.2 (0x00007f2b77324000) libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f2b7327d000) libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f2b73079000) libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f2b72e5f000) liblber-2.4.so.2 => /lib64/liblber-2.4.so.2 (0x00007f2b72c4f000) libsasl2.so.3 => /lib64/libsasl2.so.3 (0x00007f2b72a32000) libssl3.so => /lib64/libssl3.so (0x00007f2b727e6000) libsmime3.so => /lib64/libsmime3.so (0x00007f2b725be000) libnss3.so => /lib64/libnss3.so (0x00007f2b72294000) libnssutil3.so => /lib64/libnssutil3.so (0x00007f2b72067000) libplds4.so => /lib64/libplds4.so (0x00007f2b71e62000) libplc4.so => /lib64/libplc4.so (0x00007f2b71c5d000) libnspr4.so => /lib64/libnspr4.so (0x00007f2b71a1f000) libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f2b717f7000) libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f2b715c0000) libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f2b7135e000) libfreebl3.so => /lib64/libfreebl3.so (0x00007f2b7115b000)
相比於舊版(v. 1.1),這次多了 bart-scanner 這個程式,用來作為 incremental backup 的背景程序使用。
BART 2.0 的 incremental backup 功能,有以下幾個設定的注意事項
- bart-scanner 涉及讀取資料庫的 WAL 檔案,因此執行 BART 的 OS 帳號要有權限處理這些檔案才行。在這次筆記,由於 WAL 只透過 copy 複製,WAL 上的權限仍在,因此以下紀錄會以 enterprisedb 這個 OS 帳戶進行。
- 進行 incremental backup,是透過 ssh 進行,因此必須設定 ssh 免密碼的金鑰登入
- Incremental Backup 還原過程需要在資料庫主機「也安裝」 BART2.0
[user@bartvm ~]$ sudo sed -e "s@#RSAAuthentication yes@RSAAuthentication yes@g" \ -e "s@#PubkeyAuthentication yes@PubkeyAuthentication yes@g" \ -i /etc/ssh/sshd_config [user@bartvm ~]$ sudo service sshd restart [user@bartvm ~]$ sudo su enterprisedb [enterprisedb@bartvm ~]$ ssh-keygen -t rsa [enterprisedb@bartvm ~]$ sssh-copy-id -i ~/.ssh/id_rsa.pub enterprisedb@10.146.0.2 [enterprisedb@bartvm ~]$ ## 登入確認,順便設定反過來的 ssh 金鑰 [enterprisedb@bartvm ~]$ ssh 10.146.0.2 Last login: Wed May 10 15:01:28 2017 -bash-4.2$ ssh-keygen -t rsa -bash-4.2$ sssh-copy-id -i ~/.ssh/id_rsa.pub enterprisedb@10.146.0.4 -bash-4.2$ exit logout Connection to 10.146.0.2 closed.
以下開始進行 BART 設置。
先設定 Config 檔案。跟舊版的一樣,裡面分成 BART 全域設定以及紀錄資料庫連線資訊的段落(表示如果有人之前有使用,從 v1.x 更新還蠻簡單的)。不過可以看到兩段落有新增一些參數。以下的參數檔,設定對於同一台上安裝的 EDB 企業版 EPAS9.6 進行備份,啟用 incremental backup 功能:
[user@bartvm ~]$ ## 建立遠端備份目錄 [user@bartvm ~]$ sudo mkdir /opt/backup [user@bartvm ~]$ sudo chown enterprisedb:enterprisedb -R /opt/backup/ [user@bartvm ~]$ ## 要使用 enterprisedb 操作 BART! [user@bartvm ~]$ sudo su - enterprisedb [enterprisedb@bartvm ~]$ cp /usr/edb/bart2.0/etc/bart.cfg ~/ [enterprisedb@bartvm ~]$ ## 調整後,省去原本檔案中說明的註解 [enterprisedb@bartvm ~]$ cat ~/bart.cfg [BART] bart_host= enterprisedb@10.146.0.4 backup_path = /opt/backup pg_basebackup_path = /opt/edb/as9.6/bin/pg_basebackup wal_compression= disabled logfile = /tmp/bart.log scanner_logfile = /tmp/bart_scanner.log [EPAS96] host = 10.146.0.2 port = 5444 user = enterprisedb archive_command = "cp %p %a/%f" cluster_owner = enterprisedb allow_incremental_backups = enabled tablespace_path = 21707=/opt/edb/as9.6/restore/my_tblspc description = "EPAS 96 server"
比較明顯的有
- 多一項填寫作業系統帳戶名稱:cluster_owner
- 啟動 incremental backup 的參數(只對 PGSQL 9.5 以上支援):allow_incremental_backups
- 啟用 incremental backup 功能,需要停用 wal_compression
- 有額外的 Tablespace 要列出 OID(此處為 21707)與還原目錄位置的對應
不過 PGSQL 9.6 的參數和先前版本有一點點小差異,以及 pg_hba.conf 條目有順序差異,要注意一下
[enterprisedb@edbvm ~]$ source /opt/edb/as9.6/pgplus_env.sh [enterprisedb@edbvm ~]$ sed -e "s@#wal_level = minimal@wal_level = replica@g" \ -e "s@#archive_mode = off@archive_mode = on@g" \ -e "s@#max_wal_senders = 0@max_wal_senders = 1@g" \ -i $PGDATA/postgresql.conf [enterprisedb@edbvm ~]$ echo "host all all 10.128.0.2/32 trust" >> $PGDATA/pg_hba.conf [enterprisedb@edbvm ~]$ echo "host replication enterprisedb 10.128.0.2/32 trust" >> $PGDATA/pg_hba.conf [enterprisedb@edbvm ~]$ pg_ctl restart
跟前一版操作一樣,先初始化 BART
[enterprisedb@bartvm ~]$ export PATH=$PATH:/usr/edb/bart2.0/bin/ [enterprisedb@bartvm ~]$ bart -c ~/bart.cfg INIT -o -s epas96 INFO: setting archive_command for server 'epas96' WARNING: archive_command is set. server restart is required
查看當前資訊
[enterprisedb@bartvm ~]$ bart -c ~/bart.cfg SHOW-SERVERS -s all SERVER NAME : epas96 HOST NAME : 10.146.0.2 USER NAME : enterprisedb PORT : 5444 REMOTE HOST : enterprisedb@10.146.0.2 RETENTION POLICY : none DISK UTILIZATION : 112.00 MB NUMBER OF ARCHIVES : 0 ARCHIVE PATH : /opt/backup/epas96/archived_wals ARCHIVE COMMAND : scp %p enterprisedb@10.146.0.4:/opt/backup/epas96/archived_wals/%f XLOG METHOD : fetch WAL COMPRESSION : disabled TABLESPACE PATH(s) : INCREMENTAL BACKUP : ENABLED DESCRIPTION : "EPAS 96 server"
接著,開始這次筆記重點~要進行 incremental backup,需要有以下步驟
- 啟動 bart-scanner 背景程序
- 進行全備份:這時 bart-scanner 便會對 WAL 進行後續必要的分析
- 需要指定所依據的全備份,用 --parent 指定進行 incremental backup
[enterprisedb@bartvm ~]$ bart-scanner -c ~/bart.cfg --daemon [enterprisedb@bartvm ~]$ ps aux|grep bart enterpr+ 1518 0.0 0.2 184348 1700 ? Ss 09:23 0:00 bart-scanner -c /opt/edb/as9.6/bart.cfg --daemon enterpr+ 1519 0.0 0.4 186640 2748 ? S 09:23 0:00 bart-scanner -c /opt/edb/as9.6/bart.cfg --daemon enterpr+ 1537 0.0 0.1 112652 940 pts/0 S+ 09:23 0:00 grep bart
接著和之前筆記一樣,進行一個全備份,然後查看一下資訊
[enterprisedb@bartvm ~]$ bart -c ~/bart.cfg BACKUP -s epas96 INFO: creating backup for server 'epas96' INFO: backup identifier: '1499152089807' 226925/226925 kB (100%), 2/2 tablespaces INFO: backup completed successfully INFO: backup checksum: f9bd56657864264d1efcb37d9d75ed74 of 21707.tar INFO: backup checksum: 54d0071a8e50584861779f1f12d8204b of base.tar INFO: BACKUP DETAILS: BACKUP STATUS: active BACKUP IDENTIFIER: 1499152089807 BACKUP NAME: none BACKUP PARENT: none BACKUP LOCATION: /opt/backup/epas96/1499152089807 BACKUP SIZE: 221.61 MB BACKUP FORMAT: tar BACKUP TIMEZONE: UTC XLOG METHOD: fetch BACKUP CHECKSUM(s): 2 ChkSum File f9bd56657864264d1efcb37d9d75ed74 21707.tar 54d0071a8e50584861779f1f12d8204b base.tar TABLESPACE(s): 1 Oid Name Location 21707 my_tblspc /var/lib/ppas/my_tblspc START WAL LOCATION: 00000001000000000000002F BACKUP METHOD: streamed BACKUP FROM: master START TIME: 2017-07-04 07:08:10 UTC STOP TIME: 2017-07-04 07:08:15 UTC TOTAL DURATION: 5 sec(s) [enterprisedb@bartvm ~]$ bart -c ~/bart.cfg show-backups -t SERVER NAME : epas96 BACKUP ID : 1499152089807 BACKUP NAME : none BACKUP PARENT : none BACKUP STATUS : active BACKUP TIME : 2017-07-04 07:08:15 UTC BACKUP SIZE : 221.61 MB WAL(S) SIZE : 16.00 MB NO. OF WALS : 1 FIRST WAL FILE : 00000001000000000000002F CREATION TIME : 2017-07-04 07:08:17 UTC LAST WAL FILE : 00000001000000000000002F CREATION TIME : 2017-07-04 07:08:17 UTC [enterprisedb@bartvm ~]$ ls /opt/backup/epas96/* /opt/backup/epas96/1499152089807: 21707.tar backupinfo base.tar /opt/backup/epas96/archived_wals: 000000010000000000000027 000000010000000000000027.00000028.backup 000000010000000000000028 000000010000000000000029 00000001000000000000002A 00000001000000000000002B 00000001000000000000002B.00000060.backup 00000001000000000000002C 00000001000000000000002D 00000001000000000000002E 00000001000000000000002F 00000001000000000000002F.00000060.backup 0000000100000000270000280000000028000000.mbm 0000000100000000280000280000000029000000.mbm 000000010000000029000028000000002A000000.mbm 00000001000000002A000028000000002B000000.mbm 00000001000000002B000028000000002C000000.mbm 00000001000000002C000028000000002D000000.mbm 00000001000000002D000028000000002E000000.mbm 00000001000000002E000028000000002F000000.mbm 00000001000000002F0000280000000030000000.mbm
上面藍字的部份,表示 bart-scanner 有處理,所產生 MBM(Modified Block Map)檔。
然後產生一點資料,讓 WAL 產生一些新內容;並且強制切換一個新的 WAL 以確保 WAL 檔案有產生
CREATE TABLE test_tab(id INT, descr TEXT); INSERT INTO test_tab(id, descr) VALUES ( generate_series(1,10000), md5(random()::text) ); SELECT pg_switch_xlog();
然後,進行 incremental backup。目前 beta2 的 bart 程式好像抓不到自己的同伴 bart-scanner 在哪,需要在資料庫端設定 $PATH 才行(剛剛上面設定一次了~)
[enterprisedb@bartvm ~]$ export PATH=$PATH:/usr/edb/bart2.0/bin/
[enterprisedb@bartvm ~]$ bart -c ~/bart.cfg backup -s epas96 -F p --parent 1499152089807
INFO: creating incremental backup for server 'epas96'
INFO: checking mbm files /opt/backup/epas96/archived_wals
INFO: new backup identifier generated 1499152313190
INFO: reading directory /opt/backup/epas96/archived_wals
INFO: all files processed
NOTICE: pg_stop_backup complete, all required WAL segments have been archived
INFO: incremental backup completed successfully
INFO:
BACKUP DETAILS:
BACKUP STATUS: active
BACKUP IDENTIFIER: 1499152313190
BACKUP NAME: none
BACKUP PARENT: 1499152089807
BACKUP LOCATION: /opt/backup/epas96/1499152313190
BACKUP SIZE: 132.10 MB
BACKUP FORMAT: plain
BACKUP TIMEZONE: UTC
XLOG METHOD: fetch
BACKUP CHECKSUM(s): 0
TABLESPACE(s): 1
Oid Name Location
21707 my_tblspc /var/lib/ppas/my_tblspc
START WAL LOCATION: 000000010000000000000032
STOP WAL LOCATION: 000000010000000000000033
BACKUP METHOD: pg_start_backup
BACKUP FROM: master
START TIME: 2017-07-04 07:12:04 UTC
STOP TIME: 2017-07-04 07:12:11 UTC
TOTAL DURATION: 7 sec(s)
總算是備份完畢~再來查看備份檔狀況
[enterprisedb@bartvm ~]$ bart -c ~/bart.cfg show-backups -t SERVER NAME : epas96 BACKUP ID : 1499152313190 BACKUP NAME : none BACKUP PARENT : 1499152089807 BACKUP STATUS : active BACKUP TIME : 2017-07-04 07:12:10 UTC BACKUP SIZE : 132.10 MB WAL(S) SIZE : NO. OF WALS : FIRST WAL FILE : 000000010000000000000032 CREATION TIME : 2017-07-04 07:12:05 UTC SERVER NAME : epas96 BACKUP ID : 1499152089807 BACKUP NAME : none BACKUP PARENT : none BACKUP STATUS : active BACKUP TIME : 2017-07-04 07:08:15 UTC BACKUP SIZE : 221.61 MB WAL(S) SIZE : 80.00 MB NO. OF WALS : 5 FIRST WAL FILE : 00000001000000000000002F CREATION TIME : 2017-07-04 07:08:17 UTC LAST WAL FILE : 000000010000000000000033 CREATION TIME : 2017-07-04 07:12:12 UTC [enterprisedb@bartvm ~]$ ls /opt/backup/epas96/* /opt/backup/epas96/1499152089807: 21707.tar backupinfo base.tar /opt/backup/epas96/1499152313190: 1499152313190.cbm 21707 backupinfo base /opt/backup/epas96/archived_wals: 000000010000000000000027 000000010000000000000027.00000028.backup 000000010000000000000028 000000010000000000000029 00000001000000000000002A 00000001000000000000002B 00000001000000000000002B.00000060.backup 00000001000000000000002C 00000001000000000000002D 00000001000000000000002E 00000001000000000000002F 00000001000000000000002F.00000060.backup 000000010000000000000030 000000010000000000000031 000000010000000000000032 000000010000000000000032.00000028.backup 000000010000000000000033 0000000100000000270000280000000028000000.mbm 0000000100000000280000280000000029000000.mbm 000000010000000029000028000000002A000000.mbm 00000001000000002A000028000000002B000000.mbm 00000001000000002B000028000000002C000000.mbm 00000001000000002C000028000000002D000000.mbm 00000001000000002D000028000000002E000000.mbm 00000001000000002E000028000000002F000000.mbm 00000001000000002F0000280000000030000000.mbm 0000000100000000300000280000000031000000.mbm 0000000100000000310000280000000032000000.mbm 0000000100000000320000280000000033000000.mbm 0000000100000000330000280000000034000000.mbm [enterprisedb@bartvm ~]$ du -sh /opt/backup/epas96/1499152089807/ 222M /opt/backup/epas96/1499152089807/ [enterprisedb@bartvm ~]$ du -sh /opt/backup/epas96/1499152313190/ 133M /opt/backup/epas96/1499152313190/ [enterprisedb@bartvm ~]$ ls /opt/backup/epas96/1499152313190/* /opt/backup/epas96/1499152313190/1499152313190.cbm /opt/backup/epas96/1499152313190/backupinfo /opt/backup/epas96/1499152313190/21707: PG_9.6_201608131 /opt/backup/epas96/1499152313190/base: backup_label pg_dynshmem pg_replslot pg_twophase base pg_hba.conf pg_serial PG_VERSION dbms_pipe pg_ident.conf pg_snapshots pg_xlog edb_audit pg_log pg_stat postgresql.auto.conf global pg_logical pg_stat_tmp postgresql.conf pg_clog pg_multixact pg_subtrans tablespace_map pg_commit_ts pg_notify pg_tblspc [enterprisedb@bartvm ~]$ ## 看一下原資料庫大小 [enterprisedb@bartvm ~]$ ssh enterprisedb@edbvm Last login: Tue Jul 4 08:45:19 2017 [enterprisedb@edbvm ~]$ du $PGDATA -sh 958M /var/lib/ppas/as9.6/data
從備份資訊,可以觀察到,BART 的 Incremental Backup 和普通 Point-in-Time Recovery 的 WAL Log-based Backup/Recovery 不同:
- BART 使用類似 pg_rewind 的概念,針對 WAL 解析後,對照上一個備份(--parent 所指定的備份點),將 Block-Level 資料變動備份起來
- 單純操作 Point-in-Time Recovery,是將 WAL 中的交易紀錄,在全備份的資料上重演一次交易
[enterprisedb@edbvm ~]$ mkdir -p /opt/edb/as9.6/restore/epas96 [enterprisedb@edbvm ~]$ mkdir -p /opt/edb/as9.6/restore/my_tblspc [enterprisedb@bartvm ~]$ bart -c ~/bart.cfg restore -s epas96 -i 1499152089807 -p /opt/edb/as9.6/restore/epas96 -r enterprisedb@10.146.0.2 INFO: restoring backup '1499152089807' of server 'epas96' INFO: base backup restored INFO: archiving is disabled INFO: tablespace(s) restored INFO: permissions set on $PGDATA INFO: restore completed successfully
啟動它吧(先把原本的關掉)
[enterprisedb@edbvm ~]$ pg_ctl -D $PGDATA stop waiting for server to shut down.... done server stopped [enterprisedb@edbvm ~]$ pg_ctl -D /opt/edb/as9.6/restore/epas96 start
進資料庫看看剛剛新增的表有沒有在
[enterprisedb@edbvm ~]$ psql psql.bin (9.6.2.7) Type "help" for help. edb=# \d List of relations Schema | Name | Type | Owner --------------+------------+----------+-------------- enterprisedb | test_tab | table | enterprisedb public | dept | table | enterprisedb public | emp | table | enterprisedb public | jobhist | table | enterprisedb public | next_empno | sequence | enterprisedb public | salesemp | view | enterprisedb (6 rows) edb=# \q [enterprisedb@bartvm ~]$ pg_ctl -D /opt/edb/as9.6/restore/epas96 stop
上面進行的都是某個固定時間點的資料還原。那麼 Point-in-Time Recovery 功能呢?
原本在 BART 1.1 需要手動複製 WAL 進行 Point-in-Time Recovery;但是 到了BART 2.0 真的能自動指定時間點進行 Point-in-Time Recovery 還原了:只要指定目前選取的 Backup ID 的備份檔時間點之後的時間,就可以進行還原。而且不論是全備份還是增量備份都能夠使用。
以下在另外產生一些 WAL 後,使用同一份 incremental backup 進行的 BART 還原,並且指定了備份之後的時間點。以下以還原到最新時間為例:
[enterprisedb@bartvm ~]$ ls -lt /opt/backup/epas96/archived_wals/ total 245836 -rw-r--r--. 1 enterprisedb enterprisedb 1601 Jul 4 08:06 0000000100000000350000280000000036000000.mbm -rw-------. 1 enterprisedb enterprisedb 16777216 Jul 4 08:06 000000010000000000000035 -rw-r--r--. 1 enterprisedb enterprisedb 546 Jul 4 08:02 0000000100000000340000280000000035000000.mbm -rw-------. 1 enterprisedb enterprisedb 16777216 Jul 4 08:02 000000010000000000000034 -rw-r--r--. 1 enterprisedb enterprisedb 159 Jul 4 07:12 0000000100000000330000280000000034000000.mbm -rw-------. 1 enterprisedb enterprisedb 16777216 Jul 4 07:12 000000010000000000000033 -rw-------. 1 enterprisedb enterprisedb 292 Jul 4 07:12 000000010000000000000032.00000028.backup -rw-r--r--. 1 enterprisedb enterprisedb 159 Jul 4 07:12 0000000100000000320000280000000033000000.mbm -rw-------. 1 enterprisedb enterprisedb 16777216 Jul 4 07:12 000000010000000000000032 -rw-r--r--. 1 enterprisedb enterprisedb 159 Jul 4 07:11 0000000100000000310000280000000032000000.mbm -rw-------. 1 enterprisedb enterprisedb 16777216 Jul 4 07:11 000000010000000000000031 -rw-r--r--. 1 enterprisedb enterprisedb 1601 Jul 4 07:11 0000000100000000300000280000000031000000.mbm -rw-------. 1 enterprisedb enterprisedb 16777216 Jul 4 07:11 000000010000000000000030 -rw-r--r--. 1 enterprisedb enterprisedb 159 Jul 4 07:08 00000001000000002F0000280000000030000000.mbm -rw-------. 1 enterprisedb enterprisedb 16777216 Jul 4 07:08 00000001000000000000002F -rw-------. 1 enterprisedb enterprisedb 305 Jul 4 07:08 00000001000000000000002F.00000060.backup -rw-r--r--. 1 enterprisedb enterprisedb 159 Jul 4 07:08 00000001000000002E000028000000002F000000.mbm -rw-------. 1 enterprisedb enterprisedb 16777216 Jul 4 07:08 00000001000000000000002E -rw-r--r--. 1 enterprisedb enterprisedb 1602 Jul 4 07:07 000000010000000029000028000000002A000000.mbm -rw-r--r--. 1 enterprisedb enterprisedb 159 Jul 4 07:07 00000001000000002A000028000000002B000000.mbm -rw-r--r--. 1 enterprisedb enterprisedb 159 Jul 4 07:07 00000001000000002B000028000000002C000000.mbm -rw-r--r--. 1 enterprisedb enterprisedb 159 Jul 4 07:07 00000001000000002C000028000000002D000000.mbm -rw-r--r--. 1 enterprisedb enterprisedb 545 Jul 4 07:07 00000001000000002D000028000000002E000000.mbm -rw-rw-r--. 1 enterprisedb enterprisedb 159 Jul 4 07:07 0000000100000000270000280000000028000000.mbm -rw-r--r--. 1 enterprisedb enterprisedb 159 Jul 4 07:07 0000000100000000280000280000000029000000.mbm -rw-------. 1 enterprisedb enterprisedb 16777216 Jul 4 07:05 00000001000000000000002D -rw-------. 1 enterprisedb enterprisedb 16777216 Jul 4 07:05 00000001000000000000002C -rw-------. 1 enterprisedb enterprisedb 16777216 Jul 4 07:05 00000001000000000000002B -rw-------. 1 enterprisedb enterprisedb 292 Jul 4 07:05 00000001000000000000002B.00000060.backup -rw-------. 1 enterprisedb enterprisedb 16777216 Jul 4 07:05 00000001000000000000002A -rw-------. 1 enterprisedb enterprisedb 16777216 Jul 4 07:05 000000010000000000000029 -rw-------. 1 enterprisedb enterprisedb 16777216 Jul 4 07:05 000000010000000000000028 -rw-------. 1 enterprisedb enterprisedb 16777216 Jul 4 06:26 000000010000000000000027 -rw-------. 1 enterprisedb enterprisedb 305 Jul 4 06:26 000000010000000000000027.00000028.backup [enterprisedb@bartvm ~]$ bart -c ~/bart.cfg restore -s epas96 -i 1499152089807 -p /var/lib/ppas/as9.6/restore/epas96 -r enterprisedb@edbvm -t 'latest' INFO: restoring backup '1499152089807' of server 'epas96' INFO: base backup restored INFO: creating recovery.conf file INFO: WAL file(s) will be streamed from the BART host INFO: archiving is disabled INFO: permissions set on $PGDATA INFO: restore completed successfully
注意,這裡的最新時間,只限於已經送到遠端的 WAL 為限;一般在舊資料庫的 pg_xlog/ 裡面還會有一些 WAL 在,因此必要的話,要把舊的 pg_xlog/ 裡面的東西複製到還原的資料目錄的 pg_xlog/
接著,到資料庫目錄裡面看一下由 BART 自動產生的 recovery.conf
[enterprisedb@bartvm ~]$ pg_ctl -D $PGDATA stop waiting for server to shut down.... done server stopped [enterprisedb@bartvm ~]$ cat /opt/edb/as9.6/restore/epas96/recovery.conf restore_command = 'scp -o BatchMode=yes -o PasswordAuthentication=no enterprisedb@10.146.0.4:/opt/backup/epas96/archived_wals/%f %p' recovery_target_timeline = latest [enterprisedb@bartvm ~]$ cp -r $PGDATA/pg_xlog/* /opt/edb/as9.6/restore/epas96/pg_xlog/ [enterprisedb@bartvm ~]$ pg_ctl -D /opt/edb/as9.6/restore/epas96 start
啟動之後,看一下 Log
[enterprisedb@bartvm ~]$ tail -15 ~/as9.6/restore/epas96/pg_log/ enterprisedb-2017-07-04_081335.log 2017-07-04 08:13:39 UTC LOG: restored log file "000000010000000000000034" from archive 2017-07-04 08:13:40 UTC LOG: restored log file "000000010000000000000035" from archive 2017-07-04 08:13:41 UTC LOG: restored log file "000000010000000000000036" from archive scp: /opt/backup/epas96/archived_wals/000000010000000000000037: No such file or directory 2017-07-04 08:13:41 UTC LOG: redo done at 0/36003F70 2017-07-04 08:13:41 UTC LOG: last completed transaction was at log time 2017-07-04 08:06:52.486901+00 2017-07-04 08:13:42 UTC LOG: restored log file "000000010000000000000036" from archive scp: /opt/backup/epas96/archived_wals/00000002.history: No such file or directory 2017-07-04 08:13:42 UTC LOG: selected new timeline ID: 2 scp: /opt/backup/epas96/archived_wals/00000001.history: No such file or directory 2017-07-04 08:13:42 UTC LOG: archive recovery complete 2017-07-04 08:13:42 UTC LOG: MultiXact member wraparound protections are now enabled 2017-07-04 08:13:42 UTC LOG: database system is ready to accept connections 2017-07-04 08:13:42 UTC LOG: autovacuum launcher started 2017-07-04 08:13:42 UTC LOG: dbms_aq launcher started
成功啟動!
操作紀錄結束~
截至今日,比較目前能取得的 PostgreSQL 備份工具,不論是開源專案還是商業產品,BART 2.0 的 Incremental Backup 備份功能,都還沒有在其他工具上看到。
不論如何,使用 PostgreSQL 時,利用工具作備份(不論開源專案或商業產品),比起自己安排 Script 配置,還要花力氣調整 Script,以及處理交易日誌管理,測試 Script 有沒有筆誤發生等等的麻煩事,要容易多了~
參考資料:
沒有留言:
張貼留言