# Copyright (c) 2021-2025, PostgreSQL Global Development Group # # This test aims to validate that restoring an incremental backup works # properly even when the reference backup is on a different timeline. use strict; use warnings FATAL => 'all'; use File::Compare; use PostgreSQL::Test::Cluster; use PostgreSQL::Test::Utils; use Test::More; # Can be changed to test the other modes. my $mode = $ENV{PG_TEST_PG_COMBINEBACKUP_MODE} || '--copy'; note "testing using mode $mode"; # Set up a new database instance. my $node1 = PostgreSQL::Test::Cluster->new('node1'); $node1->init(has_archiving => 1, allows_streaming => 1); $node1->append_conf('postgresql.conf', 'summarize_wal = on'); $node1->start; # Create a table and insert a test row into it. $node1->safe_psql('postgres', <backup_dir . '/backup1'; $node1->command_ok( [ 'pg_basebackup', '--pgdata' => $backup1path, '--no-sync', '--checkpoint' => 'fast' ], "full backup from node1"); # Insert a second row on the original node. $node1->safe_psql('postgres', <backup_dir . '/backup2'; $node1->command_ok( [ 'pg_basebackup', '--pgdata' => $backup2path, '--no-sync', '--checkpoint' => 'fast', '--incremental' => $backup1path . '/backup_manifest' ], "incremental backup from node1"); # Restore the incremental backup and use it to create a new node. my $node2 = PostgreSQL::Test::Cluster->new('node2'); $node2->init_from_backup($node1, 'backup2', combine_with_prior => ['backup1']); $node2->start(); # Insert rows on both nodes. $node1->safe_psql('postgres', <safe_psql('postgres', <backup_dir . '/backup3'; $node2->command_ok( [ 'pg_basebackup', '--pgdata' => $backup3path, '--no-sync', '--checkpoint' => 'fast', '--incremental' => $backup2path . '/backup_manifest' ], "incremental backup from node2"); # Restore the incremental backup and use it to create a new node. my $node3 = PostgreSQL::Test::Cluster->new('node3'); $node3->init_from_backup( $node1, 'backup3', combine_with_prior => [ 'backup1', 'backup2' ], combine_mode => $mode); $node3->start(); # Let's insert one more row. $node3->safe_psql('postgres', <safe_psql('postgres', <command_ok( [ 'pg_verifybackup', $node1->backup_dir . '/' . $backup_name ], "verify backup $backup_name"); } # OK, that's all. done_testing();