From d89aa79d60cd4a997103e8261dda23a709c6ce51 Mon Sep 17 00:00:00 2001 From: zhaobingyu <1783692558@qq.com> Date: Mon, 10 Oct 2022 10:43:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=AE=E9=A2=98=EF=BC=8Cgs?= =?UTF-8?q?=5Fprobackup=E5=B7=A5=E5=85=B7=E5=9C=A8=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E7=BB=9D=E5=AF=B9=E8=B7=AF=E5=BE=84=E8=A1=A8=E7=A9=BA=E9=97=B4?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=E7=BB=93=E6=9E=9C=E4=B8=8D=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/pg_probackup/restore.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/bin/pg_probackup/restore.cpp b/src/bin/pg_probackup/restore.cpp index b13b7acfe..9ff3340f2 100644 --- a/src/bin/pg_probackup/restore.cpp +++ b/src/bin/pg_probackup/restore.cpp @@ -73,7 +73,8 @@ static void get_pgdata_files(const char *pgdata_path, parray *external_dirs); static void remove_redundant_files(const char *pgdata_path, parray *pgdata_files, - pgBackup *dest_backup); + pgBackup *dest_backup, + parray *external_dirs); static void threads_handle(pthread_t *threads, restore_files_arg *threads_args, pgBackup *dest_backup, @@ -803,7 +804,7 @@ restore_chain(pgBackup *dest_backup, parray *parent_chain, { pgdata_files = parray_new(); get_pgdata_files(pgdata_path, pgdata_files, external_dirs); - remove_redundant_files(pgdata_path, pgdata_files, dest_backup); + remove_redundant_files(pgdata_path, pgdata_files, dest_backup, external_dirs); } /* @@ -955,27 +956,35 @@ static bool skip_some_tblspc_files(pgFile *file) static void remove_redundant_files(const char *pgdata_path, parray *pgdata_files, - pgBackup *dest_backup) + pgBackup *dest_backup, + parray *external_dirs) { char pretty_time[20]; time_t start_time, end_time; elog(INFO, "Removing redundant files in destination directory"); time(&start_time); - for (int i = 0; (size_t)i < parray_num(pgdata_files); i++) - { + for (int i = 0; (size_t)i < parray_num(pgdata_files); i++) { pgFile *file = (pgFile *)parray_get(pgdata_files, i); + bool in_tablespace = false; /* For incremental backups, we need to skip some files */ - if (skip_some_tblspc_files(file)) + in_tablespace = path_is_prefix_of_path(PG_TBLSPC_DIR, file->rel_path); + if (in_tablespace && 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) - { + if (parray_bsearch(dest_backup->files, file, + pgFileCompareRelPathWithExternal) == NULL) { char fullpath[MAXPGPATH]; - join_path_components(fullpath, pgdata_path, file->rel_path); + if (file->external_dir_num) { + char *external_path = (char *)parray_get(external_dirs, + file->external_dir_num - 1); + join_path_components(fullpath, external_path, file->rel_path); + } else { + join_path_components(fullpath, pgdata_path, file->rel_path); + } fio_delete(file->mode, fullpath, FIO_DB_HOST); elog(VERBOSE, "Deleted file \"%s\"", fullpath);