From adb021322c7b8eeb5f27e5c81906167329be68ee Mon Sep 17 00:00:00 2001 From: zhaobingyu <1783692558@qq.com> Date: Sat, 24 Sep 2022 17:14:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=97=AE=E9=A2=98=EF=BC=9A?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E6=95=B0=E6=8D=AE=E5=BA=93=E6=9C=89=E8=A1=A8?= =?UTF-8?q?=E7=A9=BA=E9=97=B4=EF=BC=8C=E5=A2=9E=E9=87=8F=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/pg_probackup/restore.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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) {