0

私は決してデータベース管理者ではないので、完全に間違っている場合は撃たないでください...

生産的なpostgresデータベース(dockerコンテナの最新バージョン)にアーカイブを追加し、WALで使用するスクリプトをいくつか構築しようとする必要があります。

アイデアは、新しいディレクトリへの完全バックアップを実行し、WAL スクリプトがログを書き込むために使用するこの新しいディレクトリへのシンボリック リンクを作成するスクリプトを毎週作成することです。また、週次スクリプトは、30 日より古い古いバックアップを削除します。

これについて何かコメントがあればとても嬉しいです...

デシベル設定

wal_level = replica
archive_mode = on
archive_command = '/archive/archive_wal.sh "%p" "%f"'
archive_timeout = 300

毎週のスクリプト:

#!/bin/bash

#create base archive dir
#base_arch_dir=/tmp/archive/
base_arch_dir=/archive/
if [ ! -d "$base_arch_dir" ]; then
  mkdir "$base_arch_dir"
  chown -R postgres:postgres "$base_arch_dir"
fi

#create dir for week
dir="$base_arch_dir"$(date '+%Y_%m_%d__%H_%M_%S')
if [ ! -d "$dir" ]; then
  mkdir "$dir"
  chown -R postgres:postgres "$dir"
fi

#change/create the symlink
newdir="$base_arch_dir"wals
ln -fsn "$dir" "$newdir"
chown -R postgres:postgres "$newdir"

#do the base backup to the wals dir
if pg_basebackup -D "$newdir" -F tar -R -X fetch -z -Z 9 -U postgres; then
  find "$base_arch_dir"* -type d -mtime +31|xargs rm -rf
fi

アーカイブ スクリプト:

#!/bin/bash

set -e

arch_dir=/archive/wals
arch_log="$arch_dir/arch.log"

if [ ! -d "$arch_dir" ]; then
  echo arch_dir '"$arch_dir"' does not exist >> "$arch_log"
  exit -1
fi

#get the variables from postgres
p=$1
f=$2

if [ -f "$arch_dir"/$f.xz ]; then 
  echo wal file '"$arch_dir"/$f.xz' already exists
  exit -1
fi

pxz -2 -z --keep -c $p > "$arch_dir"/$f.xz

前もって感謝します

4

1 に答える 1