Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9e72f6b

Browse files
committed
Restrict where INCREMENTAL.${NAME} files are recognized.
Previously, they were recognized anywhere in an incremental backup directory; now, we restrict this to places where they are expected to appear. That means this code will need updating if we ever do incremental backups of files in other places (e.g. SLRU files), but it lets you create a file called INCREMENTAL.config (or something like that) at the top level of the data directory and still have things work. Patch by me, per request from David Steele, who also reviewed. Discussion: http://postgr.es/m/5a7817da-6349-4653-8056-470300b6e512@pgmasters.net
1 parent d72d32f commit 9e72f6b

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-13
lines changed

src/bin/pg_combinebackup/pg_combinebackup.c

+34-13
Original file line numberDiff line numberDiff line change
@@ -799,25 +799,45 @@ process_directory_recursively(Oid tsoid,
799799
char manifest_prefix[MAXPGPATH];
800800
DIR *dir;
801801
struct dirent *de;
802-
bool is_pg_tblspc;
803-
bool is_pg_wal;
802+
bool is_pg_tblspc = false;
803+
bool is_pg_wal = false;
804+
bool is_incremental_dir = false;
804805
manifest_data *latest_manifest = manifests[n_prior_backups];
805806
pg_checksum_type checksum_type;
806807

807808
/*
808-
* pg_tblspc and pg_wal are special cases, so detect those here.
809+
* Classify this directory.
809810
*
810-
* pg_tblspc is only special at the top level, but subdirectories of
811-
* pg_wal are just as special as the top level directory.
811+
* We set is_pg_tblspc only for the toplevel pg_tblspc directory, because
812+
* the symlinks in that specific directory require special handling.
812813
*
813-
* Since incremental backup does not exist in pre-v10 versions, we don't
814-
* have to worry about the old pg_xlog naming.
814+
* We set is_pg_wal for the toplevel WAL directory and all of its
815+
* subdirectories, because those files are not included in the backup
816+
* manifest and hence need special treatement. (Since incremental backup
817+
* does not exist in pre-v10 versions, we don't have to worry about the
818+
* old pg_xlog naming.)
819+
*
820+
* We set is_incremental_dir for directories that can contain incremental
821+
* files requiring reconstruction. If such files occur outside these
822+
* directories, we want to just copy them straight to the output
823+
* directory. This is to protect against a user creating a file with a
824+
* strange name like INCREMENTAL.config and then compaining that
825+
* incremental backups don't work properly. The test here is a bit tricky:
826+
* incremental files occur in subdirectories of base, in pg_global itself,
827+
* and in subdirectories of pg_tblspc only if in-place tablespaces are
828+
* used.
815829
*/
816-
is_pg_tblspc = !OidIsValid(tsoid) && relative_path != NULL &&
817-
strcmp(relative_path, "pg_tblspc") == 0;
818-
is_pg_wal = !OidIsValid(tsoid) && relative_path != NULL &&
819-
(strcmp(relative_path, "pg_wal") == 0 ||
820-
strncmp(relative_path, "pg_wal/", 7) == 0);
830+
if (OidIsValid(tsoid))
831+
is_incremental_dir = true;
832+
else if (relative_path != NULL)
833+
{
834+
is_pg_tblspc = strcmp(relative_path, "pg_tblspc") == 0;
835+
is_pg_wal = (strcmp(relative_path, "pg_wal") == 0 ||
836+
strncmp(relative_path, "pg_wal/", 7) == 0);
837+
is_incremental_dir = strncmp(relative_path, "base/", 5) == 0 ||
838+
strcmp(relative_path, "global") == 0 ||
839+
strncmp(relative_path, "pg_tblspc/", 10) == 0;
840+
}
821841

822842
/*
823843
* If we're under pg_wal, then we don't need checksums, because these
@@ -955,7 +975,8 @@ process_directory_recursively(Oid tsoid,
955975
* If it's an incremental file, hand it off to the reconstruction
956976
* code, which will figure out what to do.
957977
*/
958-
if (strncmp(de->d_name, INCREMENTAL_PREFIX,
978+
if (is_incremental_dir &&
979+
strncmp(de->d_name, INCREMENTAL_PREFIX,
959980
INCREMENTAL_PREFIX_LENGTH) == 0)
960981
{
961982
/* Output path should not include "INCREMENTAL." prefix. */

src/bin/pg_combinebackup/t/005_integrity.pl

+9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
$node1->append_conf('postgresql.conf', 'summarize_wal = on');
2020
$node1->start;
2121

22+
# Create a file called INCREMENTAL.config in the root directory of the
23+
# first database instance. We only recognize INCREMENTAL.${original_name}
24+
# files under base and global and in tablespace directories, so this shouldn't
25+
# cause anything to fail.
26+
my $strangely_named_config_file = $node1->data_dir . '/INCREMENTAL.config';
27+
open(my $icfg, '>', $strangely_named_config_file)
28+
|| die "$strangely_named_config_file: $!";
29+
close($icfg);
30+
2231
# Set up another new database instance. force_initdb is used because
2332
# we want it to be a separate cluster with a different system ID.
2433
my $node2 = PostgreSQL::Test::Cluster->new('node2');

0 commit comments

Comments
 (0)