diff --git a/src/bin/pg_basebackup/t/010_pg_basebackup.pl b/src/bin/pg_basebackup/t/010_pg_basebackup.pl old mode 100644 new mode 100755 index b7d36b6..367d2f6 --- a/src/bin/pg_basebackup/t/010_pg_basebackup.pl +++ b/src/bin/pg_basebackup/t/010_pg_basebackup.pl @@ -6,7 +6,7 @@ use File::Basename qw(basename dirname); use File::Path qw(rmtree); use PostgresNode; use TestLib; -use Test::More tests => 106; +use Test::More tests => 135; program_help_ok('pg_basebackup'); program_version_ok('pg_basebackup'); @@ -558,3 +558,113 @@ rmtree("$tempdir/backup_corrupt4"); $node->safe_psql('postgres', "DROP TABLE corrupt1;"); $node->safe_psql('postgres', "DROP TABLE corrupt2;"); + +# verify backup cluster using --verify-backup option. +$node->command_ok([ 'pg_basebackup', '-D', "$tempdir/backup_verify", '-X', 'none' ], + 'pg_basebackup runs - created backup_verify cluster'); +ok(-f "$tempdir/backup_verify/PG_VERSION", 'backup_verify cluster is created'); + +# make sure backup_manifest file is created. +ok(-f "$tempdir/backup_verify/backup_manifest", + 'backup_manifest file is present'); + +# verify plain backup without checksum. +$node->command_ok([ 'pg_basebackup', '-D', "$tempdir/backup_verify", '--verify-backup'], + 'plain backup without checksum is verified'); + +# backup verification without checksum should detect deleted files, new files or modified file sizes +rmtree("$tempdir/backup_verify/pg_hba.conf"); +open my $new_file_none, '>', "$tempdir/backup_verify/postgresql.new"; +print $new_file_none "port = 5555\n"; +close $new_file_none; +open my $modify_file_none, '>>', "$tempdir/backup_verify/postgresql.conf"; +print $modify_file_none "port = 5555\n"; +close $modify_file_none; + +$node->command_checks_all( + [ 'pg_basebackup', '-D', "$tempdir/backup_verify", '--verify-backup' ], + 0, + [qr{^$}], + [ + qr/\Qpg_basebackup: missing file: pg_hba.conf/, + qr/\Qpg_basebackup: extra file found: postgresql.new/, + qr/\Qpg_basebackup: size changed for file: postgresql.conf\E/ + ], + 'backup verification without checksum detected deleted files, new files or modified file sizes'); +rmtree("$tempdir/backup_verify"); + +# backup with --manifest-checksums=SHA256 +$node->command_ok([ 'pg_basebackup', '-D', "$tempdir/backup_verify", '-X', 'none', '--manifest-checksums', 'SHA256' ], + 'pg_basebackup runs - created backup_verify'); +ok(-f "$tempdir/backup_verify/PG_VERSION", 'backup_verify was created'); + +# make sure backup_manifest file created. +ok(-f "$tempdir/backup_verify/backup_manifest", + 'backup_manifest file is present'); + +# verify plain backup with checksum taken above. +$node->command_ok([ 'pg_basebackup', '-D', "$tempdir/backup_verify", '--verify-backup'], + 'plain backup with SHA256 checksum is verified'); + +# --verify-backup with SHA256 checksums should detect deleted files, new files or modified files +rmtree("$tempdir/backup_verify/pg_hba.conf"); +open my $new_file_sha256, '>', "$tempdir/backup_verify/postgresql.new"; +print $new_file_sha256 "port = 5555\n"; +close $new_file_sha256; +open my $same_size_file_sha256, '>', "$tempdir/backup_verify/PG_VERSION"; +print $same_size_file_sha256 "14"; +close $same_size_file_sha256; +open my $modify_file_sha256, '>>', "$tempdir/backup_verify/postgresql.conf"; +print $modify_file_sha256 "port = 5555\n"; +close $modify_file_sha256; + +$node->command_checks_all( + [ 'pg_basebackup', '-D', "$tempdir/backup_verify", '--verify-backup' ], + 0, + [qr{^$}], + [ + qr/\Qpg_basebackup: missing file: pg_hba.conf/, + qr/\Qpg_basebackup: extra file found: postgresql.new/, + qr/\Qpg_basebackup: checksum difference for file: PG_VERSION/, + qr/\Qpg_basebackup: size changed for file: postgresql.conf\E/ + ], + 'backup verification with SHA256 checksum detected deleted files, new files or modified files'); +rmtree("$tempdir/backup_verify"); + +# backup with --manifest-checksums=CRC32C +$node->command_ok([ 'pg_basebackup', '-D', "$tempdir/backup_verify", '-X', 'none', '--manifest-checksums', 'CRC32C' ], + 'pg_basebackup runs - created backup_verify'); +ok(-f "$tempdir/backup_verify/PG_VERSION", 'backup_verify was created'); + +# make sure backup_manifest file created. +ok(-f "$tempdir/backup_verify/backup_manifest", + 'backup_manifest file is present'); + +# verify plain backup with checksum taken above. +$node->command_ok([ 'pg_basebackup', '-D', "$tempdir/backup_verify", '--verify-backup'], + 'plain backup with CRC32C checksum is verified'); + +# --verify-backup with CRC32C checksums should detect deleted files, new files or modified files +rmtree("$tempdir/backup_verify/pg_hba.conf"); +open my $new_file_crc32c, '>', "$tempdir/backup_verify/postgresql.new"; +print $new_file_crc32c "port = 5555\n"; +close $new_file_crc32c; +open my $same_size_file_crc32c, '>', "$tempdir/backup_verify/PG_VERSION"; +print $same_size_file_crc32c "14"; +close $same_size_file_crc32c; +open my $modify_file_crc32c, '>>', "$tempdir/backup_verify/postgresql.conf"; +print $modify_file_crc32c "port = 5555\n"; +close $modify_file_crc32c; + +$node->command_checks_all( + [ 'pg_basebackup', '-D', "$tempdir/backup_verify", '--verify-backup' ], + 0, + [qr{^$}], + [ + qr/\Qpg_basebackup: missing file: pg_hba.conf/, + qr/\Qpg_basebackup: extra file found: postgresql.new/, + qr/\Qpg_basebackup: checksum difference for file: PG_VERSION/, + qr/\Qpg_basebackup: size changed for file: postgresql.conf\E/ + ], + 'backup verification with CRC32C checksum detected deleted files, new files or modified files'); +rmtree("$tempdir/backup_verify");