From 6d461531b71301177f698da5266e2492ed6e84d9 Mon Sep 17 00:00:00 2001 From: Stefan Fercot Date: Tue, 28 Jul 2020 10:55:08 +0200 Subject: [PATCH] New enable-internal-pgbr-cmds argument --- CHANGELOG.md | 5 ++ INSTALL.md | 8 ++- README | 8 ++- README.pod | 8 ++- check_pgbackrest | 21 +++++-- test/VALIDATION.md | 22 +++++++ test/Vagrantfile | 7 ++- test/provision/pgbackrest_local.bash | 16 ++--- test/provision/pgbackrest_minio.bash | 10 +++- test/provision/pgbackrest_remote_primary.bash | 2 +- test/provision/pgbackrest_remote_standby.bash | 13 ++-- test/provision/pgsql.bash | 6 +- test/regress/test-s1.bash | 59 ++++++++++++++----- test/regress/test-s2-from-primary.bash | 59 ++++++++++++++----- test/regress/test-s3.bash | 59 ++++++++++++++----- 15 files changed, 230 insertions(+), 73 deletions(-) create mode 100644 test/VALIDATION.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 55a3a70..7ce08b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,11 @@ Changelog Instead, a WARNING message "max WAL is not the latest archive" will be displayed (suggested by blogh). - Fix S3 archives detection (reported by khadijahvf). + - New enable-internal-pgbr-cmds argument, for pgBackRest >= 2.28. Internal + pgBackRest commands will then be used to list and get the content of files + in the repository instead of Perl specific drivers. This is, for instance, + needed to access encrypted repositories. This should become the default and + only access method in the next release, removing some Perl dependencies. 2020-03-16 v1.8: diff --git a/INSTALL.md b/INSTALL.md index 80a1c4e..ddd78a6 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -47,4 +47,10 @@ only be found in the Open Fusion repositories. To install it on CentOS 7, use: ``` yum install -y http://repo.openfusion.net/centos7-x86_64/\ openfusion-release-0.7-1.of.el7.noarch.rpm -``` \ No newline at end of file +``` + +## Unneeded Perl dependencies with pgBackRest >= 2.28 + +Using the `--enable-internal-pgbr-cmds` argument will use pgBackRest internal +commands. SFTP or Amazon S3 specific Perl dependencies are then not needed +anymore. \ No newline at end of file diff --git a/README b/README index 18afae6..83e7bd5 100644 --- a/README +++ b/README @@ -104,9 +104,9 @@ DESCRIPTION unit per given value. If not set, the last unit is in seconds. Eg. "1h 55m 6" = "1h55m6s". - All the missing archives are only shown in the `--debug` mode. + All the missing archives are only shown in the "--debug" mode. - Use `--list-archives` in addition with `--debug` to print the list + Use "--list-archives" in addition with "--debug" to print the list of all the archived WAL segments. By default, all the archives older than the oldest backup start @@ -116,6 +116,10 @@ DESCRIPTION Use the "--extended-check" argument to force a full check of the found archives and raise warnings in case of inconsistencies. + After pgBackRest 2.28, it is possible to use the "repo-ls" and + "repo-get" internal commands with the "--enable-internal-pgbr-cmds" + argument to list and get the content of files in the repository. + check_pgb_version Check if this script is running a given version. diff --git a/README.pod b/README.pod index a3b62cd..af145a5 100644 --- a/README.pod +++ b/README.pod @@ -124,9 +124,9 @@ s (second), m (minute), h (hour), d (day). You can use more than one unit per given value. If not set, the last unit is in seconds. Eg. "1h 55m 6" = "1h55m6s". -All the missing archives are only shown in the `--debug` mode. +All the missing archives are only shown in the C<--debug> mode. -Use `--list-archives` in addition with `--debug` to print the list of all the +Use C<--list-archives> in addition with C<--debug> to print the list of all the archived WAL segments. By default, all the archives older than the oldest backup start archive @@ -136,6 +136,10 @@ are ignored. Use the C<--extended-check> argument to force a full check of the found archives and raise warnings in case of inconsistencies. +After pgBackRest 2.28, it is possible to use the C and C +internal commands with the C<--enable-internal-pgbr-cmds> argument to list and +get the content of files in the repository. + =item B Check if this script is running a given version. diff --git a/check_pgbackrest b/check_pgbackrest index a54e114..4fc6b02 100755 --- a/check_pgbackrest +++ b/check_pgbackrest @@ -449,6 +449,7 @@ sub pgbackrest_get { my %args = %{ $args_ref }; my $filename = shift; my $getcmd = $args{'command'}." repo-get"; + $getcmd .= " --stanza=".$args{'stanza'}; $getcmd .= " ".$args{'archives_dir'}."/".$filename; $getcmd .= " --log-level-console=error"; @@ -472,6 +473,7 @@ sub pgbackrest_ls { my $args_ref = shift; my %args = %{ $args_ref }; my $lscmd = $args{'command'}." repo-ls"; + $lscmd .= " --stanza=".$args{'stanza'}; $lscmd .= " ".$args{'archives_dir'}; $lscmd .= " --recurse --output=json --log-level-console=error"; @@ -645,9 +647,9 @@ s (second), m (minute), h (hour), d (day). You can use more than one unit per given value. If not set, the last unit is in seconds. Eg. "1h 55m 6" = "1h55m6s". -All the missing archives are only shown in the `--debug` mode. +All the missing archives are only shown in the C<--debug> mode. -Use C<--list-archives> in addition with `--debug` to print the list of all the +Use C<--list-archives> in addition with C<--debug> to print the list of all the archived WAL segments. By default, all the archives older than the oldest backup start archive @@ -657,6 +659,10 @@ are ignored. Use the C<--extended-check> argument to force a full check of the found archives and raise warnings in case of inconsistencies. +After pgBackRest 2.28, it is possible to use the C and C +internal commands with the C<--enable-internal-pgbr-cmds> argument to list and +get the content of files in the repository. + =cut sub get_archived_wal_list { @@ -677,9 +683,7 @@ sub get_archived_wal_list { my $history_re_full = qr/$end_tl.history$/; my $pgbackrest_version=pgbackrest_version(\%args); - my $activate_pgbackrest_ls_command=0; - if($pgbackrest_version >= '2.28' && $activate_pgbackrest_ls_command){ - # pgBackRest ls command + if($pgbackrest_version >= '2.28' && $args{'enable-internal-pgbr-cmds'}){ my $list = pgbackrest_ls(\%args); foreach my $key (keys %{$list}) { @@ -1225,6 +1229,7 @@ GetOptions( 'command|C=s', 'config|c=s', 'debug!', + 'enable-internal-pgbr-cmds!', 'extended-check!', 'help|?!', 'ignore-archived-after=s', @@ -1289,6 +1294,12 @@ pod2usage( ) if ( $args{'extended-check'} or $args{'ignore-archived-after'} or $args{'ignore-archived-before'} or $args{'latest-archive-age-alert'} ) and $args{'service'} ne 'archives'; +# Check "archives" specific arg --enable-internal-pgbr-cmds +pod2usage( + -message => 'FATAL: "enable-internal-pgbr-cmds" is only allowed with "archives" service.', + -exitval => 127 +) if $args{'enable-internal-pgbr-cmds'} and $args{'service'} ne 'archives'; + # Check "archives" specific arg --list-archives pod2usage( -message => 'FATAL: "list-archives" is only allowed with "archives" service and "debug" option.', diff --git a/test/VALIDATION.md b/test/VALIDATION.md new file mode 100644 index 0000000..f0b791b --- /dev/null +++ b/test/VALIDATION.md @@ -0,0 +1,22 @@ +# Validation process + +```bash +time sudo make s1_light +time sudo vagrant ssh pgsql-srv -c "sudo /check_pgbackrest/test/regress/simulate-extended-activity.bash -s 10 -a 10 -p local" +time sudo vagrant ssh pgsql-srv -c "sudo /check_pgbackrest/test/regress/test-s1.bash -s -p /check_pgbackrest" +time sudo vagrant ssh pgsql-srv -c "sudo /check_pgbackrest/test/regress/test-s1.bash -s -p /check_pgbackrest -a '--enable-internal-pgbr-cmds'" +``` + +```bash +time sudo make s2_light +time sudo vagrant ssh pgsql-srv -c "sudo /check_pgbackrest/test/regress/simulate-extended-activity.bash -s 10 -a 10 -p remote" +time sudo vagrant ssh pgsql-srv -c "sudo /check_pgbackrest/test/regress/test-s2-from-primary.bash -s -p /check_pgbackrest" +time sudo vagrant ssh pgsql-srv -c "sudo /check_pgbackrest/test/regress/test-s2-from-primary.bash -s -p /check_pgbackrest -a '--enable-internal-pgbr-cmds'" +``` + +```bash +time sudo make s3_light +time sudo vagrant ssh pgsql-srv -c "sudo /check_pgbackrest/test/regress/simulate-extended-activity.bash -s 10 -a 10 -p local" +time sudo vagrant ssh pgsql-srv -c "sudo /check_pgbackrest/test/regress/test-s3.bash -s -p /check_pgbackrest" +time sudo vagrant ssh pgsql-srv -c "sudo /check_pgbackrest/test/regress/test-s3.bash -s -p /check_pgbackrest -a '--enable-internal-pgbr-cmds'" +``` \ No newline at end of file diff --git a/test/Vagrantfile b/test/Vagrantfile index 8ec0ce4..0ad685d 100644 --- a/test/Vagrantfile +++ b/test/Vagrantfile @@ -1,5 +1,6 @@ pgver = '12' # pg version to use vm_prefix = 'c_pgbr_c7' +encrypted_repo = 'false' Vagrant.configure(2) do |config| @@ -66,7 +67,7 @@ Vagrant.configure(2) do |config| # pgbackrest local setup. Use "vagrant up --provision-with=pgbackrest_local" pgsql.vm.provision 'pgbackrest_local', type: 'shell', path: 'provision/pgbackrest_local.bash', - args: [ pgver, pgdata ], + args: [ pgver, pgdata, encrypted_repo ], run: 'never' # pgbackrest remote setup. Use "vagrant up --provision-with=pgbackrest_remote_primary" @@ -78,7 +79,7 @@ Vagrant.configure(2) do |config| # pgbackrest minio setup. Use "vagrant up --provision-with=pgbackrest_minio" pgsql.vm.provision 'pgbackrest_minio', type: 'shell', path: 'provision/pgbackrest_minio.bash', - args: [ pgver, pgdata ], + args: [ pgver, pgdata, encrypted_repo ], run: 'never' end @@ -92,7 +93,7 @@ Vagrant.configure(2) do |config| # pgbackrest remote setup. Use "vagrant up --provision-with=pgbackrest_remote_standby" backup.vm.provision 'pgbackrest_remote_standby', type: 'shell', path: 'provision/pgbackrest_remote_standby.bash', - args: [ pgver, pgdata ], + args: [ pgver, pgdata, encrypted_repo ], run: 'never' # minio local setup. Use "vagrant up --provision-with=minio" diff --git a/test/provision/pgbackrest_local.bash b/test/provision/pgbackrest_local.bash index ddf0b42..269e2bf 100644 --- a/test/provision/pgbackrest_local.bash +++ b/test/provision/pgbackrest_local.bash @@ -6,6 +6,7 @@ set -o pipefail PGVER="$1" PGDATA="$2" +ENCRYPTED="$3" PACKAGES=( pgbackrest @@ -28,7 +29,13 @@ EOF chmod 755 /var/lib/pgbackrest mount /var/lib/pgbackrest +CIPHER= # pgbackrest.conf setup +if [ $ENCRYPTED = "true" ]; then + CIPHER='repo1-cipher-type=aes-256-cbc +repo1-cipher-pass=acbd' +fi + cat< "/etc/pgbackrest.conf" [global] repo1-type=cifs @@ -39,8 +46,7 @@ log-level-console=warn log-level-file=info start-fast=y delta=y -repo1-cipher-type=aes-256-cbc -repo1-cipher-pass=acbd +$CIPHER [my_stanza] pg1-path=${PGDATA} @@ -54,8 +60,4 @@ ALTER SYSTEM SET "archive_command" TO 'pgbackrest --stanza=my_stanza archive-pus SELECT pg_reload_conf(); EOS -sudo -iu postgres pgbackrest --stanza=my_stanza check - - - - +sudo -iu postgres pgbackrest --stanza=my_stanza check \ No newline at end of file diff --git a/test/provision/pgbackrest_minio.bash b/test/provision/pgbackrest_minio.bash index 8d78203..950adf2 100644 --- a/test/provision/pgbackrest_minio.bash +++ b/test/provision/pgbackrest_minio.bash @@ -6,6 +6,7 @@ set -o pipefail PGVER="$1" PGDATA="$2" +ENCRYPTED="$3" PACKAGES=( pgbackrest @@ -13,7 +14,13 @@ PACKAGES=( yum install --nogpgcheck --quiet -y -e 0 "${PACKAGES[@]}" +CIPHER= # pgbackrest.conf setup +if [ $ENCRYPTED = "true" ]; then + CIPHER='repo1-cipher-type=aes-256-cbc +repo1-cipher-pass=acbd' +fi + cat< "/etc/pgbackrest.conf" [global] repo1-path=/repo1 @@ -31,8 +38,7 @@ log-level-console=warn log-level-file=info start-fast=y delta=y -repo1-cipher-type=aes-256-cbc -repo1-cipher-pass=acbd +$CIPHER [my_stanza] pg1-path=${PGDATA} diff --git a/test/provision/pgbackrest_remote_primary.bash b/test/provision/pgbackrest_remote_primary.bash index 093efa9..3ee3d4b 100644 --- a/test/provision/pgbackrest_remote_primary.bash +++ b/test/provision/pgbackrest_remote_primary.bash @@ -31,4 +31,4 @@ EOC cat <<'EOS' | "/usr/pgsql-${PGVER}/bin/psql" -U postgres ALTER SYSTEM SET "archive_command" TO 'pgbackrest --stanza=my_stanza archive-push %p'; SELECT pg_reload_conf(); -EOS +EOS \ No newline at end of file diff --git a/test/provision/pgbackrest_remote_standby.bash b/test/provision/pgbackrest_remote_standby.bash index 5775123..e8760f7 100644 --- a/test/provision/pgbackrest_remote_standby.bash +++ b/test/provision/pgbackrest_remote_standby.bash @@ -6,6 +6,7 @@ set -o pipefail PGVER="$1" PGDATA="$2" +ENCRYPTED="$3" PACKAGES=( pgbackrest @@ -13,7 +14,13 @@ PACKAGES=( yum install --nogpgcheck --quiet -y -e 0 "${PACKAGES[@]}" +CIPHER= # pgbackrest.conf setup +if [ $ENCRYPTED = "true" ]; then + CIPHER='repo1-cipher-type=aes-256-cbc +repo1-cipher-pass=acbd' +fi + cat< "/etc/pgbackrest.conf" [global] repo1-path=/var/lib/pgbackrest @@ -23,8 +30,7 @@ log-level-console=warn log-level-file=info start-fast=y delta=y -repo1-cipher-type=aes-256-cbc -repo1-cipher-pass=acbd +$CIPHER [my_stanza] pg1-host=pgsql-srv @@ -46,8 +52,7 @@ process-max=2 log-level-console=warn log-level-file=info delta=y -repo1-cipher-type=aes-256-cbc -repo1-cipher-pass=acbd +$CIPHER [my_stanza] pg1-path=${PGDATA} diff --git a/test/provision/pgsql.bash b/test/provision/pgsql.bash index d004de6..f4c3eae 100644 --- a/test/provision/pgsql.bash +++ b/test/provision/pgsql.bash @@ -10,6 +10,10 @@ PGDATA="$2" # install required packages yum install --nogpgcheck --quiet -y -e 0 "https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm" +if [ $PGVER -ge "13" ]; then + yum-config-manager --enable pgdg$PGVER-updates-testing +fi + PACKAGES=( "postgresql${PGVER}" "postgresql${PGVER}-server" @@ -70,4 +74,4 @@ usermod -aG postgres accessed_by_ssh echo "accessed_by_ssh ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers cp -rf /root/.ssh /home/accessed_by_ssh/.ssh chown -R accessed_by_ssh: /home/accessed_by_ssh/.ssh -restorecon -R /home/accessed_by_ssh/.ssh +restorecon -R /home/accessed_by_ssh/.ssh \ No newline at end of file diff --git a/test/regress/test-s1.bash b/test/regress/test-s1.bash index d5a7149..c966f66 100755 --- a/test/regress/test-s1.bash +++ b/test/regress/test-s1.bash @@ -1,12 +1,43 @@ #!/usr/bin/env bash - cd "$(dirname "$0")" + +# vars PLUGIN_PATH=/usr/lib64/nagios/plugins RESULTS_DIR=/tmp/results - -# Generate the expected results ? +SKIP_INIT=false GENERATE_EXPECTED=false +while getopts ":sgp:a:h" o; do + case "${o}" in + s) + SKIP_INIT=true + ;; + g) + GENERATE_EXPECTED=true + ;; + p) + PLUGIN_PATH=${OPTARG} + ;; + a) + ARCHIVE_OPTION=${OPTARG} + ;; + h ) + echo "Usage:" + echo " -s Skip backups initialization step." + echo " -g Generate expected results." + echo " -p Change check_pgbackrest plugin path." + echo " -a Add extra option to the archives service." + echo " -h Display this help message." + exit 0 + ;; + \? ) + echo "Invalid Option: -$OPTARG" 1>&2 + exit 1 + ;; + esac +done +shift $((OPTIND-1)) + if $GENERATE_EXPECTED; then RESULTS_DIR=expected fi @@ -16,9 +47,7 @@ if [ ! -d $RESULTS_DIR ]; then fi ## Tests - # Initiate backups (full, diff, incr) -SKIP_INIT=false if ! $SKIP_INIT; then echo "Initiate backups (full, diff, incr)" sudo -iu postgres pgbackrest --stanza=my_stanza backup --type=full --repo1-retention-full=1 @@ -56,29 +85,29 @@ echo "--service=archives missing arg" $PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives > $RESULTS_DIR/archives-missing-arg.out 2>&1 # --service=archives --repo-path -echo "--service=archives --repo-path" +echo "--service=archives --repo-path $ARCHIVE_OPTION" sudo -iu postgres psql -c "SELECT pg_switch_xlog();" > /dev/null 2>&1 sudo -iu postgres psql -c "SELECT pg_switch_wal();" > /dev/null 2>&1 sudo -iu postgres psql -c "SELECT pg_sleep(1);" > /dev/null 2>&1 -$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/var/lib/pgbackrest/archive | cut -f1 -d"-" > $RESULTS_DIR/archives-ok.out +$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/var/lib/pgbackrest/archive $ARCHIVE_OPTION | cut -f1 -d"-" > $RESULTS_DIR/archives-ok.out # --service=archives --ignore-archived-before -echo "--service=archives --ignore-archived-before" +echo "--service=archives --ignore-archived-before $ARCHIVE_OPTION" sudo -iu postgres psql -c "SELECT pg_sleep(2);" > /dev/null 2>&1 -$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/var/lib/pgbackrest/archive --ignore-archived-before=1s > $RESULTS_DIR/archives-ignore-before.out +$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/var/lib/pgbackrest/archive --ignore-archived-before=1s $ARCHIVE_OPTION > $RESULTS_DIR/archives-ignore-before.out # --service=archives --ignore-archived-after -echo "--service=archives --ignore-archived-after" -$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/var/lib/pgbackrest/archive --ignore-archived-after=1h > $RESULTS_DIR/archives-ignore-after.out +echo "--service=archives --ignore-archived-after $ARCHIVE_OPTION" +$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/var/lib/pgbackrest/archive --ignore-archived-after=1h $ARCHIVE_OPTION > $RESULTS_DIR/archives-ignore-after.out # --service=archives --latest-archive-age-alert -echo "--service=archives --latest-archive-age-alert" +echo "--service=archives --latest-archive-age-alert $ARCHIVE_OPTION" sudo -iu postgres psql -c "SELECT pg_sleep(2);" > /dev/null 2>&1 -$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/var/lib/pgbackrest/archive --latest-archive-age-alert=1h | cut -f1 -d"-" > $RESULTS_DIR/archives-age-alert-ok.out -$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/var/lib/pgbackrest/archive --latest-archive-age-alert=1s | cut -f1 -d"-" > $RESULTS_DIR/archives-age-alert-ko.out +$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/var/lib/pgbackrest/archive --latest-archive-age-alert=1h $ARCHIVE_OPTION | cut -f1 -d"-" > $RESULTS_DIR/archives-age-alert-ok.out +$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/var/lib/pgbackrest/archive --latest-archive-age-alert=1s $ARCHIVE_OPTION | cut -f1 -d"-" > $RESULTS_DIR/archives-age-alert-ko.out ## Results diff -abB expected/ $RESULTS_DIR/ > /tmp/regression.diffs if [ $(wc -l < /tmp/regression.diffs) -gt 0 ]; then cat /tmp/regression.diffs -fi +fi \ No newline at end of file diff --git a/test/regress/test-s2-from-primary.bash b/test/regress/test-s2-from-primary.bash index a2746aa..e8f25e4 100755 --- a/test/regress/test-s2-from-primary.bash +++ b/test/regress/test-s2-from-primary.bash @@ -1,12 +1,43 @@ #!/usr/bin/env bash - cd "$(dirname "$0")" + +# vars PLUGIN_PATH=/usr/lib64/nagios/plugins RESULTS_DIR=/tmp/results - -# Generate the expected results ? +SKIP_INIT=false GENERATE_EXPECTED=false +while getopts ":sgp:a:h" o; do + case "${o}" in + s) + SKIP_INIT=true + ;; + g) + GENERATE_EXPECTED=true + ;; + p) + PLUGIN_PATH=${OPTARG} + ;; + a) + ARCHIVE_OPTION=${OPTARG} + ;; + h ) + echo "Usage:" + echo " -s Skip backups initialization step." + echo " -g Generate expected results." + echo " -p Change check_pgbackrest plugin path." + echo " -a Add extra option to the archives service." + echo " -h Display this help message." + exit 0 + ;; + \? ) + echo "Invalid Option: -$OPTARG" 1>&2 + exit 1 + ;; + esac +done +shift $((OPTIND-1)) + if $GENERATE_EXPECTED; then RESULTS_DIR=expected fi @@ -16,9 +47,7 @@ if [ ! -d $RESULTS_DIR ]; then fi ## Tests - # Initiate backups (full, diff, incr) -SKIP_INIT=false if ! $SKIP_INIT; then echo "Initiate backups (full, diff, incr)" sudo -iu postgres ssh backup-srv "pgbackrest --stanza=my_stanza backup --type=full --repo1-retention-full=1" @@ -56,29 +85,29 @@ echo "--service=archives missing arg" $PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives > $RESULTS_DIR/archives-missing-arg.out 2>&1 # --service=archives --repo-path -echo "--service=archives --repo-path" +echo "--service=archives --repo-path $ARCHIVE_OPTION" sudo -iu postgres psql -c "SELECT pg_switch_xlog();" > /dev/null 2>&1 sudo -iu postgres psql -c "SELECT pg_switch_wal();" > /dev/null 2>&1 sudo -iu postgres psql -c "SELECT pg_sleep(1);" > /dev/null 2>&1 -$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/var/lib/pgbackrest/archive --repo-host="backup-srv" --repo-host-user=postgres | cut -f1 -d"-" > $RESULTS_DIR/archives-ok.out +$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/var/lib/pgbackrest/archive --repo-host="backup-srv" --repo-host-user=postgres $ARCHIVE_OPTION | cut -f1 -d"-" > $RESULTS_DIR/archives-ok.out # --service=archives --ignore-archived-before -echo "--service=archives --ignore-archived-before" +echo "--service=archives --ignore-archived-before $ARCHIVE_OPTION" sudo -iu postgres psql -c "SELECT pg_sleep(2);" > /dev/null 2>&1 -$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/var/lib/pgbackrest/archive --repo-host="backup-srv" --repo-host-user=postgres --ignore-archived-before=1s > $RESULTS_DIR/archives-ignore-before.out +$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/var/lib/pgbackrest/archive --repo-host="backup-srv" --repo-host-user=postgres --ignore-archived-before=1s $ARCHIVE_OPTION > $RESULTS_DIR/archives-ignore-before.out # --service=archives --ignore-archived-after -echo "--service=archives --ignore-archived-after" -$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/var/lib/pgbackrest/archive --repo-host="backup-srv" --repo-host-user=postgres --ignore-archived-after=1h > $RESULTS_DIR/archives-ignore-after.out +echo "--service=archives --ignore-archived-after $ARCHIVE_OPTION" +$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/var/lib/pgbackrest/archive --repo-host="backup-srv" --repo-host-user=postgres --ignore-archived-after=1h $ARCHIVE_OPTION > $RESULTS_DIR/archives-ignore-after.out # --service=archives --latest-archive-age-alert -echo "--service=archives --latest-archive-age-alert" +echo "--service=archives --latest-archive-age-alert $ARCHIVE_OPTION" sudo -iu postgres psql -c "SELECT pg_sleep(2);" > /dev/null 2>&1 -$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/var/lib/pgbackrest/archive --repo-host="backup-srv" --repo-host-user=postgres --latest-archive-age-alert=1h | cut -f1 -d"-" > $RESULTS_DIR/archives-age-alert-ok.out -$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/var/lib/pgbackrest/archive --repo-host="backup-srv" --repo-host-user=postgres --latest-archive-age-alert=1s | cut -f1 -d"-" > $RESULTS_DIR/archives-age-alert-ko.out +$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/var/lib/pgbackrest/archive --repo-host="backup-srv" --repo-host-user=postgres --latest-archive-age-alert=1h $ARCHIVE_OPTION | cut -f1 -d"-" > $RESULTS_DIR/archives-age-alert-ok.out +$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/var/lib/pgbackrest/archive --repo-host="backup-srv" --repo-host-user=postgres --latest-archive-age-alert=1s $ARCHIVE_OPTION | cut -f1 -d"-" > $RESULTS_DIR/archives-age-alert-ko.out ## Results diff -abB expected/ $RESULTS_DIR/ > /tmp/regression.diffs if [ $(wc -l < /tmp/regression.diffs) -gt 0 ]; then cat /tmp/regression.diffs -fi +fi \ No newline at end of file diff --git a/test/regress/test-s3.bash b/test/regress/test-s3.bash index 546d553..95c82d7 100755 --- a/test/regress/test-s3.bash +++ b/test/regress/test-s3.bash @@ -1,12 +1,43 @@ #!/usr/bin/env bash - cd "$(dirname "$0")" + +# vars PLUGIN_PATH=/usr/lib64/nagios/plugins RESULTS_DIR=/tmp/results - -# Generate the expected results ? +SKIP_INIT=false GENERATE_EXPECTED=false +while getopts ":sgp:a:h" o; do + case "${o}" in + s) + SKIP_INIT=true + ;; + g) + GENERATE_EXPECTED=true + ;; + p) + PLUGIN_PATH=${OPTARG} + ;; + a) + ARCHIVE_OPTION=${OPTARG} + ;; + h ) + echo "Usage:" + echo " -s Skip backups initialization step." + echo " -g Generate expected results." + echo " -p Change check_pgbackrest plugin path." + echo " -a Add extra option to the archives service." + echo " -h Display this help message." + exit 0 + ;; + \? ) + echo "Invalid Option: -$OPTARG" 1>&2 + exit 1 + ;; + esac +done +shift $((OPTIND-1)) + if $GENERATE_EXPECTED; then RESULTS_DIR=expected fi @@ -16,9 +47,7 @@ if [ ! -d $RESULTS_DIR ]; then fi ## Tests - # Initiate backups (full, diff, incr) -SKIP_INIT=false if ! $SKIP_INIT; then echo "Initiate backups (full, diff, incr)" sudo -iu postgres pgbackrest --stanza=my_stanza backup --type=full --repo1-retention-full=1 @@ -56,29 +85,29 @@ echo "--service=archives missing arg" $PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives > $RESULTS_DIR/archives-missing-arg.out 2>&1 # --service=archives --repo-path -echo "--service=archives --repo-path" +echo "--service=archives --repo-path $ARCHIVE_OPTION" sudo -iu postgres psql -c "SELECT pg_switch_xlog();" > /dev/null 2>&1 sudo -iu postgres psql -c "SELECT pg_switch_wal();" > /dev/null 2>&1 sudo -iu postgres psql -c "SELECT pg_sleep(1);" > /dev/null 2>&1 -$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/repo1/archive --repo-s3 --repo-s3-over-http | cut -f1 -d"-" > $RESULTS_DIR/archives-ok.out +$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/repo1/archive --repo-s3 --repo-s3-over-http $ARCHIVE_OPTION | cut -f1 -d"-" > $RESULTS_DIR/archives-ok.out # --service=archives --ignore-archived-before -echo "--service=archives --ignore-archived-before" +echo "--service=archives --ignore-archived-before $ARCHIVE_OPTION" sudo -iu postgres psql -c "SELECT pg_sleep(2);" > /dev/null 2>&1 -$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/repo1/archive --repo-s3 --repo-s3-over-http --ignore-archived-before=1s > $RESULTS_DIR/archives-ignore-before.out +$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/repo1/archive --repo-s3 --repo-s3-over-http --ignore-archived-before=1s $ARCHIVE_OPTION > $RESULTS_DIR/archives-ignore-before.out # --service=archives --ignore-archived-after -echo "--service=archives --ignore-archived-after" -$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/repo1/archive --repo-s3 --repo-s3-over-http --ignore-archived-after=1h > $RESULTS_DIR/archives-ignore-after.out +echo "--service=archives --ignore-archived-after $ARCHIVE_OPTION" +$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/repo1/archive --repo-s3 --repo-s3-over-http --ignore-archived-after=1h $ARCHIVE_OPTION > $RESULTS_DIR/archives-ignore-after.out # --service=archives --latest-archive-age-alert -echo "--service=archives --latest-archive-age-alert" +echo "--service=archives --latest-archive-age-alert $ARCHIVE_OPTION" sudo -iu postgres psql -c "SELECT pg_sleep(2);" > /dev/null 2>&1 -$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/repo1/archive --repo-s3 --repo-s3-over-http --latest-archive-age-alert=1h | cut -f1 -d"-" > $RESULTS_DIR/archives-age-alert-ok.out -$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/repo1/archive --repo-s3 --repo-s3-over-http --latest-archive-age-alert=1s | cut -f1 -d"-" > $RESULTS_DIR/archives-age-alert-ko.out +$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/repo1/archive --repo-s3 --repo-s3-over-http --latest-archive-age-alert=1h $ARCHIVE_OPTION | cut -f1 -d"-" > $RESULTS_DIR/archives-age-alert-ok.out +$PLUGIN_PATH/check_pgbackrest --stanza=my_stanza --service=archives --repo-path=/repo1/archive --repo-s3 --repo-s3-over-http --latest-archive-age-alert=1s $ARCHIVE_OPTION | cut -f1 -d"-" > $RESULTS_DIR/archives-age-alert-ko.out ## Results diff -abB expected/ $RESULTS_DIR/ > /tmp/regression.diffs if [ $(wc -l < /tmp/regression.diffs) -gt 0 ]; then cat /tmp/regression.diffs -fi +fi \ No newline at end of file