このブログの最初の部分で、ジョナサンはbarman-wal-archiveコマンドがどのように機能するかを説明しました。これらの手順に従ったと仮定すると、適切に構成されたPostgreSQLインスタンスが稼働しています。この第2部では、barman-cloud-backupの方法を紹介します。 コマンドは機能します。
コマンド名自体から推測できるように、barman-cloud-backup このコマンドを使用すると、PostgreSQLサーバーから直接バックアップを実行し、クラウド内のS3互換オブジェクトストアを宛先として使用できます。
example@sqldat.com:~ $ barman-cloud-backup --help
usage: barman-cloud-backup [-V] [--help] [-v | -q] [-P PROFILE] [-z | -j]
[-e {AES256,aws:kms}] [-t] [-h HOST] [-p PORT]
[-U USER] [--immediate-checkpoint] [-J JOBS]
[-S MAX_ARCHIVE_SIZE] [--endpoint-url ENDPOINT_URL]
destination_url server_name
This script can be used to perform a backup of a local PostgreSQL instance and
ship the resulting tarball(s) to the Cloud. Currently only AWS S3 is supported.
positional arguments:
destination_url URL of the cloud destination, such as a bucket in AWS
S3. For example: `s3://bucket/path/to/folder`.
server_name the name of the server as configured in Barman.
optional arguments:
-V, --version show program's version number and exit
--help show this help message and exit
-v, --verbose increase output verbosity (e.g., -vv is more than -v)
-q, --quiet decrease output verbosity (e.g., -qq is less than -q)
-P PROFILE, --profile PROFILE
profile name (e.g. INI section in AWS credentials
file)
-z, --gzip gzip-compress the WAL while uploading to the cloud
-j, --bzip2 bzip2-compress the WAL while uploading to the cloud
-e {AES256,aws:kms}, --encryption {AES256,aws:kms}
Enable server-side encryption for the transfer.
Allowed values: 'AES256'|'aws:kms'.
-t, --test Test cloud connectivity and exit
-h HOST, --host HOST host or Unix socket for PostgreSQL connection
(default: libpq settings)
-p PORT, --port PORT port for PostgreSQL connection (default: libpq
settings)
-U USER, --user USER user name for PostgreSQL connection (default: libpq
settings)
--immediate-checkpoint
forces the initial checkpoint to be done as quickly as
possible
-J JOBS, --jobs JOBS number of subprocesses to upload data to S3 (default:
2)
-S MAX_ARCHIVE_SIZE, --max-archive-size MAX_ARCHIVE_SIZE
maximum size of an archive when uploading to S3
(default: 100GB)
--endpoint-url ENDPOINT_URL
Override default S3 endpoint URL with the given one
> コマンドとそのオプションについて明確に理解できたので、最初のクラウドバックアップを実行する準備が整いました。
example@sqldat.com:~ $ barman-cloud-backup -P barman-cloud \ -e AES256 -j --immediate-checkpoint -J 4 \ s3://barman-s3-test/ pg12>
バックアップが正常に完了すると、base バックアップを含むディレクトリはS3バケットにあります。サーバー名とbaseを使用して宛先パスを作成し、確認してみましょう。 ディレクトリ:
example@sqldat.com:~ $ aws s3 --profile barman-cloud ls s3://barman-s3-test/pg12/base/
PRE 20200713T120856/
または、barman-cloud-backup-listを使用することもできます 、しかしこの記事では、その背後にあるメカニズムに焦点を当てたいと思います。
20200711T092548 ディレクトリには、実行したばかりのバックアップに関連するすべてのファイルが含まれています。その内容を見てみましょう:
example@sqldat.com:~ $ aws s3 --profile barman-cloud ls s3://barman-s3-test/pg12/base/20200713T120856/ 2020-07-13 12:09:08 1138 backup.info 2020-07-13 12:09:07 9263096 data.tar.bz2
ご覧のとおり、バックアップを含む圧縮および暗号化されたファイル(data.tar.bz2 )およびbackup.infoというファイル バックアップに関連する情報が含まれています。 data.tar.bz2をコピーして解凍すると、バックアップを復元できます。 以下に示すように、ローカルサーバー上のファイル:
example@sqldat.com:~ $ aws s3 --profile barman-cloud cp s3://barman-s3-test/pg12/base/20200713T120856/data.tar.bz2 restore-dir download: s3://barman-s3-test/pg12/base/20200713T120856/data.tar.bz2 to restore-dir/data.tar.bz2 example@sqldat.com:~ $ cd restore-dir example@sqldat.com:~/restore-dir $ tar xjvf data.tar.bz2 example@sqldat.com:~/restore-dir $ ls PG_VERSION conf.d pg_commit_ts pg_ident.conf pg_notify pg_snapshots pg_subtrans pg_wal postgresql.conf backup_label data.tar.bz2 pg_dynshmem pg_logical pg_replslot pg_stat pg_tblspc pg_xact base global pg_hba.conf pg_multixact pg_serial pg_stat_tmp pg_twophase postgresql.auto.conf
素晴らしい!ご覧のとおり、構成ファイルを含め、バックアップしたPostgreSQLインスタンスのDATADIR内のすべてのファイルが正しくリストされています。
結論
barman-cloud-backupを使用 コマンドBarmanは、わずか数ステップで、ローカルPostgreSQLサーバーからAWSS3と互換性のあるクラウドオブジェクトストレージサービスにベースバックアップを実行して直接送信できる重要な機能を導入しています。暗号化、並列アップロード、圧縮をサポートし、ローカルサーバーのディスク領域を節約し、バックアップをクラウドに安全に転送できるようにします。
Barman 2.11のリリースに伴い 、数日前に発生しましたが、barman-cloud-wal-restoreなどの重要な新機能が導入されました。 およびbarman-cloud-restore コマンド。AWSS3などのオブジェクトストアからバックアップファイルとWALファイルを取得できます。その点で、これらのコマンドを使用してPostgreSQLインスタンスのリカバリを準備する方法を説明する新しいブログ記事をまもなく公開します。しばらくお待ちください。