diff --git a/src/bin/pg_probackup/restore.cpp b/src/bin/pg_probackup/restore.cpp index 34cccd8cc..b13b7acfe 100644 --- a/src/bin/pg_probackup/restore.cpp +++ b/src/bin/pg_probackup/restore.cpp @@ -18,6 +18,7 @@ #include "thread.h" #include "common/fe_memutils.h" +#include "catalog/catalog.h" #define RESTORE_ARRAY_LEN 100 @@ -933,6 +934,25 @@ static void get_pgdata_files(const char *pgdata_path, pretty_time); } +static bool skip_some_tblspc_files(pgFile *file) +{ + Oid tblspcOid; + int sscanf_res; + char tmp_rel_path[MAXPGPATH]; + bool equ_tbs_version_dir = false; + bool prefix_equ_tbs_version_dir = false; + + sscanf_res = sscanf_s(file->rel_path, PG_TBLSPC_DIR "/%u/%[^/]/", + &tblspcOid, tmp_rel_path, sizeof(tmp_rel_path)); + equ_tbs_version_dir = (strcmp(tmp_rel_path, TABLESPACE_VERSION_DIRECTORY) == 0); + prefix_equ_tbs_version_dir = (strncmp(tmp_rel_path, TABLESPACE_VERSION_DIRECTORY, + strlen(TABLESPACE_VERSION_DIRECTORY)) == 0); + + if (sscanf_res == 2 && !equ_tbs_version_dir && prefix_equ_tbs_version_dir) + return true; + return false; +} + static void remove_redundant_files(const char *pgdata_path, parray *pgdata_files, pgBackup *dest_backup) @@ -946,6 +966,10 @@ static void remove_redundant_files(const char *pgdata_path, { pgFile *file = (pgFile *)parray_get(pgdata_files, i); + /* For incremental backups, we need to skip some files */ + if (skip_some_tblspc_files(file)) + continue; + /* if file does not exists in destination list, then we can safely unlink it */ if (parray_bsearch(dest_backup->files, file, pgFileCompareRelPathWithExternal) == NULL) {