LoginSignup
0
0

More than 3 years have passed since last update.

barman tips DBバックアップが上手く行かないとき

Last updated at Posted at 2020-08-15

Barman(PostgreSQLのバックアップツール)

やったこと

  • DBサーバからslaveよりバックアップを取得
    • CentOS 7系
    • postgresql 11.4
    • PG-REX 11
    • barman 2.8

参考サイト

大体この4つのサイトを見れば分かる

ハマったこと

  • レプリケーションスロットの作成or削除が上手くいかない
  • ステータス諸々の確認方法
  • 夜間のバックアップが上手くいかない
  • 1分置きのwalの取得諸々

レプリケーションスロットの作成or削除の確認

前提条件

プロファイル名:streaming-server-002
※フェールオーバーを想定して「streaming-server-001」も作成。その際は手動でレプリケーションスロットの再作成&削除が必要。行わない場合アーカイブログでディスクが溢れる。。。
DBサーバ名:db-001,bk-002
バックアップサーバ名:bk-001

正常時

作成 ※barmanユーザで実施

-bash-4.2$ barman receive-wal --create-slot streaming-server-002
Creating physical replication slot 'barman_slot' on server 'streaming-server-002'
Replication slot 'barman_slot' created

上手くいくと、少々経った後にチェックが通り「replication slot: OK」となる

-bash-4.2$ barman check streaming-server-002
Server streaming-server-002:
        PostgreSQL: OK
        is_superuser: OK
        PostgreSQL streaming: OK
        wal_level: OK
        replication slot: OK
        directories: OK
        retention policy settings: OK
        backup maximum age: OK (no last_backup_maximum_age provided)
        compression settings: OK
        failed backups: OK (there are 0 failed backups)
        minimum redundancy requirements: OK (have 0 backups, expected at least 0)
        pg_basebackup: OK
        pg_basebackup compatible: OK
        pg_basebackup supports tablespaces mapping: OK
        pg_receivexlog: OK
        pg_receivexlog compatible: OK
        receive-wal running: OK
        archiver errors: OK
[uesr@streaming-server-002 ~]$ netstat | grep postgres
tcp        0      0 nws-dbg-302:postgres    nws-nfs-301:60730       ESTABLISHED
[nwcsadm@nws-dbg-202 ~]$ ps -ef | grep wal
postgres  7148  7121  0  8月23 ?      00:01:52 postgres: walreceiver   streaming 1C/53000000
postgres 24596  7121  0 10:55 ?        00:00:00 postgres: walsender barman 10.250.73.23(60730) idle
nwcsadm  26360 23784  0 10:56 pts/0    00:00:00 grep --color=auto wal
-bash-4.2$ psql -x -p 5432 -c "SELECT * FROM pg_stat_replication"
-[ RECORD 1 ]----+-----------------------------
pid              | 24596
usesysid         | 24579
usename          | barman
application_name | barman_receive_wal
client_addr      | 10.250.73.23
client_hostname  |
client_port      | 60730
backend_start    | 2019-08-26 10:55:23.77812+09
backend_xmin     |
state            | streaming
sent_lsn         | 1C/53000000
write_lsn        | 1C/53000000
flush_lsn        | 1C/53000000
replay_lsn       |
write_lag        | 00:00:00.000171
flush_lag        | 00:00:00.000171
replay_lag       | 00:02:20.071599
sync_priority    | 0
sync_state       | async
[root@nws-nfs-201 log]# ps -ef | grep wal
barman    5508     1  0  8月23 ?      00:00:02 /usr/bin/python2 /usr/bin/barman -c /etc/barman.conf -q receive-wal streaming-nws-dbz-301
barman    5522  5508  0  8月23 ?      00:01:18 /usr/pgsql-11/bin/pg_receivewal --dbname=dbname=replication host=nws-dbz-301 options=-cdatestyle=iso replication=true user=barman application_name=barman_receive_wal --verbose --no-loop --no-password --directory=/backup/dbbackup/streaming-nws-dbz-301/streaming --slot=barman_slot
barman    6049     1  0 10:55 ?        00:00:00 /usr/bin/python2 /usr/bin/barman -c /etc/barman.conf -q receive-wal streaming-nws-dbg-302
barman    6063  6049  0 10:55 ?        00:00:00 /usr/pgsql-11/bin/pg_receivewal --dbname=dbname=replication host=nws-dbg-302 options=-cdatestyle=iso replication=true user=barman application_name=barman_receive_wal --verbose --no-loop --no-password --directory=/backup/dbbackup/streaming-nws-dbg-302/streaming --slot=barman_slot
root      6224  5057  0 11:01 pts/0    00:00:00 grep --color=auto wal

cronの設定

-bash-4.2$ crontab -l
00 02  * * *  /nw_home/sh/dbbackup.sh streaming-server-002 > /dev/null  2>&1

対処法

  • レプリケーションスロットの削除
    • barman receive-wal --drop-slot streaming-server-002
  • レプリケーションスロットのリセット
    • barman receive-wal --reset streaming-server-002
  • レプリケーションスロットの作成
    • barman receive-wal --create-slot streaming-server-002
  • ベースバックアップを取得する(DBが動いていないと失敗する)
    • barman backup --immediate-checkpoint streaming-server-002
  • 夜間バックアップを手動で実行
    • /home/sh/dbbackup.sh streaming-server-002
  • 結果確認
    • barman list-backup streaming-server-002
    • DBが動いていないと失敗することもあるが、接続ができていればOK
  • それでもだめな場合は保存先フォルダを削除する
    • 中途半端なwalがあると失敗するケースがある

この記事は個人ブログからの移植になります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0