2

不传输这些 WAL 文件的恢复命令有什么问题?

barman recover --target-time "2017-05-16 16:39:02.235780+00:00" \
--remote-ssh-command "ssh postgres@52.212.62.91" \
main-db latest /var/lib/postgresql/9.4/main

这是我的过程...

主数据库已关闭(模拟故障),但最近有一个备份,并且 WAL 文件已从 main-db 服务器传送。

barman@ip-172-30-2-77:~/main-db$ barman check main-db
Server main-db:
    PostgreSQL: FAILED
    directories: OK
    retention policy settings: OK
    backup maximum age: OK (interval provided: 1 day, latest backup age: 1 hour, 3 minutes, 46 seconds)
    compression settings: OK
    failed backups: OK (there are 0 failed backups)
    minimum redundancy requirements: OK (have 1 backups, expected at least 0)
    ssh: OK (PostgreSQL server)
    not in recovery: OK
    archiver errors: OK

在 Barman 服务器上,我们可以看到自上次 barman backup main-db运行以来归档了 6 个 WAL 文件。

barman@ip-172-30-2-77:~/main-db$ ls -lah
total 22M
drwxrwxr-x 2 barman barman 4.0K May 16 17:08 .
drwxrwxr-x 3 barman barman 4.0K May 16 17:08 ..
-rw------- 1 barman barman  28K May 16 16:39 0000000100000001000000E2
-rw------- 1 barman barman  204 May 16 16:39 0000000100000001000000E2.00000090.backup
-rw------- 1 barman barman  84K May 16 16:44 0000000100000001000000E3
-rw------- 1 barman barman  37K May 16 16:49 0000000100000001000000E4
-rw------- 1 barman barman  30K May 16 16:54 0000000100000001000000E5
-rw------- 1 barman barman 8.9M May 16 16:58 0000000100000001000000E6
-rw------- 1 barman barman 9.1M May 16 16:59 0000000100000001000000E7
-rw------- 1 barman barman 2.6M May 16 17:04 0000000100000001000000E8
-rw------- 1 barman barman 543K May 16 17:07 0000000100000001000000E9

现在我将运行recover命令,使用最新的备份+WAL文件来恢复备用数据库服务器,如下:

barman@ip-172-30-2-77:~/main-db$ barman list-server
main-db - Main DB Server
standby-db - Standby DB Server

barman@ip-172-30-2-77:~/main-db$ barman list-backup main-db
main-db 20170516T163617 - Tue May 16 16:39:02 2017 - Size: 4.0 GiB - WAL Size: 21.1 MiB

barman@ip-172-30-2-77:~/main-db$ barman show-backup main-db 20170516T163617
Backup 20170516T163617:
  Server Name            : main-db
  Status                 : DONE
  PostgreSQL Version     : 90411
  PGDATA directory       : /var/lib/postgresql/9.4/main

  Base backup information:
    Disk usage           : 4.0 GiB (4.0 GiB with WALs)
    Incremental size     : 4.0 GiB (-0.00%)
    Timeline             : 1
    Begin WAL            : 0000000100000001000000E2
    End WAL              : 0000000100000001000000E2
    WAL number           : 1
    WAL compression ratio: 99.83%
    Begin time           : 2017-05-16 16:36:17.369993+00:00
    End time             : 2017-05-16 16:39:02.235780+00:00
    Begin Offset         : 144
    End Offset           : 4912
    Begin XLOG           : 1/E2000090
    End XLOG             : 1/E2001330

  WAL information:
    No of files          : 7
    Disk usage           : 21.1 MiB
    WAL rate             : 16.91/hour
    Compression ratio    : 81.21%
    Last available       : 0000000100000001000000E9

  Catalog information:
    Retention Policy     : VALID
    Previous Backup      : - (this is the oldest base backup)
    Next Backup          : - (this is the latest base backup)

barman@ip-172-30-2-77:~/main-db$ barman recover --target-time "2017-05-16 16:39:02.235780+00:00" \
--remote-ssh-command "ssh postgres@52.212.62.91" \
main-db latest /var/lib/postgresql/9.4/main

Starting remote restore for server main-db using backup 20170516T163617
Destination directory: /var/lib/postgresql/9.4/main/
Doing PITR. Recovery target time: '2017-05-16 16:39:02.235780+00:00'
Copying the base backup.
Copying required WAL segments.
Generating recovery.conf
Your PostgreSQL server has been successfully prepared for recovery!

现在关注备用数据库服务器上的 Postgresql 数据目录(/var/lib/postgresql/9.4/main)。

postgres@ip-172-30-0-66:~/9.4/main$ pwd
/var/lib/postgresql/9.4/main
postgres@ip-172-30-0-66:~/9.4/main$ ls
backup_label  pg_hba.conf    pg_replslot   pg_tblspc            postgresql.conf
barman_xlog   pg_ident.conf  pg_serial     pg_twophase          postgresql.conf.origin
base          pg_log         pg_snapshots  PG_VERSION           recovery.conf
global        pg_logical     pg_stat       pg_xlog
pg_clog       pg_multixact   pg_stat_tmp   postgresql.auto.conf
pg_dynshmem   pg_notify      pg_subtrans   postgresql.auto.conf.origin
postgres@ip-172-30-0-66:~/9.4/main$ ls barman_xlog/
0000000100000001000000E2  0000000100000001000000E2.00000090.backup

我们可以看到以下 WAL 文件都没有使用恢复命令传输。

  • 0000000100000001000000E3
  • 0000000100000001000000E4
  • 0000000100000001000000E5
  • 0000000100000001000000E6
  • 0000000100000001000000E7
  • 0000000100000001000000E8
  • 0000000100000001000000E9

但是,我可以使用 barman-cli 的barman-restore-wal命令来拉动它们。所以这告诉我他们在酒保服务器上是明确可用的。这是我用来恢复 WAL 文件的 recovery.conf 文件。

root@ip-172-30-0-66:/var/lib/postgresql/9.4/maincat recovery.conf
The 'barman-wal-restore' command is provided in the 'barman-cli' package
standby_mode = 'on'
trigger_file = '/var/lib/postgresql/9.4/trigger'
restore_command = 'barman-wal-restore 52.51.36.41 main-db %f %p'

现在我们可以看到所有的 WAL 文件都是从酒保服务器中提取的。

root@ip-172-30-0-66:/var/lib/postgresql/9.4/mainls -lah pg_xlog/
total 129M
drwx------  3 postgres postgres 4.0K May 16 17:59 .
drwx------ 19 postgres postgres 4.0K May 16 17:58 ..
-rw-------  1 postgres postgres  16M May 16 17:56 0000000100000001000000E2
-rw-rw-r--  1 postgres postgres  324 May 16 17:54 0000000100000001000000E2.00000090.backup
-rw-------  1 postgres postgres  16M May 16 17:56 0000000100000001000000E3
-rw-------  1 postgres postgres  16M May 16 17:56 0000000100000001000000E4
-rw-------  1 postgres postgres  16M May 16 17:56 0000000100000001000000E5
-rw-------  1 postgres postgres  16M May 16 17:56 0000000100000001000000E6
-rw-------  1 postgres postgres  16M May 16 17:56 0000000100000001000000E7
-rw-------  1 postgres postgres  16M May 16 17:56 0000000100000001000000E8
-rw-------  1 postgres postgres  16M May 16 17:56 0000000100000001000000E9
drwxrwxr-x  2 postgres postgres 4.0K May 16 17:56 archive_status
-rw-------  1 postgres postgres    0 May 16 17:59 RECOVERYXLOG
4

1 回答 1

3

您的 --target-time 应该是“2017-05-16 17:08”(从您的 ls 命令接收到的最后一个 Wal 文件的时间),而不是在 restore 命令中恢复 wal 文件之后的最新备份的结束时间已备份。目标时间在备份结束时间之后。如果要恢复备份的开始时间和结束时间之间的任何时间,则应使用以前的备份。Barman 仅恢复到您在恢复命令中指定的时间。

于 2018-04-17T04:27:47.523 回答