diff --git a/src/dir.c b/src/dir.c index f05a2cc2..1f248e40 100644 --- a/src/dir.c +++ b/src/dir.c @@ -1263,8 +1263,47 @@ check_tablespace_mapping(pgBackup *backup) parray_free(links); } +void +check_extra_dir_mapping(pgBackup *backup) +{ + TablespaceListCell *cell; + parray *extra_dirs_to_restore; + bool found; + int i; + + if (!backup->extra_dir_str) + { + if (extra_remap_list.head) + elog(ERROR, "--extra-mapping option's old directory doesn't have " + "an entry in list of extra directories of current " + "backup: \"%s\"", extra_remap_list.head->old_dir); + return; + } + + extra_dirs_to_restore = make_extra_directory_list(backup->extra_dir_str); + for (cell = extra_remap_list.head; cell; cell = cell->next) + { + char *old_dir = cell->old_dir; + + found = false; + for (i = 0; i < parray_num(extra_dirs_to_restore); i++) + { + char *external_dir = parray_get(extra_dirs_to_restore, i); + if (strcmp(old_dir, external_dir) == 0) + { + found = true; + break; + } + } + if (!found) + elog(ERROR, "--extra-mapping option's old directory doesn't have " + "an entry in list of extra directories of current " + "backup: \"%s\"", cell->old_dir); + } +} + char * -check_extra_dir_mapping(char *current_dir) +get_extra_remap(char *current_dir) { TablespaceListCell *cell; diff --git a/src/pg_probackup.h b/src/pg_probackup.h index 5d91a00e..e2984755 100644 --- a/src/pg_probackup.h +++ b/src/pg_probackup.h @@ -509,7 +509,8 @@ extern void read_tablespace_map(parray *files, const char *backup_dir); extern void opt_tablespace_map(ConfigOption *opt, const char *arg); extern void opt_extradir_map(ConfigOption *opt, const char *arg); extern void check_tablespace_mapping(pgBackup *backup); -extern char* check_extra_dir_mapping(char *current_dir); +extern void check_extra_dir_mapping(pgBackup *backup); +extern char *get_extra_remap(char *current_dir); extern void print_file_list(FILE *out, const parray *files, const char *root, const char *extra_prefix, parray *extra_list); diff --git a/src/restore.c b/src/restore.c index 2eb6d563..f05184cb 100644 --- a/src/restore.c +++ b/src/restore.c @@ -285,7 +285,10 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt, * i.e. empty or not exist. */ if (is_restore) + { check_tablespace_mapping(dest_backup); + check_extra_dir_mapping(dest_backup); + } if (!is_restore || !rt->restore_no_validate) { @@ -461,10 +464,10 @@ restore_backup(pgBackup *backup, const char *extra_dir_str) if(extra_dir_str) { requested_extra_dirs = make_extra_directory_list(extra_dir_str); - for (int i = 0; i < parray_num(requested_extra_dirs); i++) + for (i = 0; i < parray_num(requested_extra_dirs); i++) { char *extra_path = parray_get(requested_extra_dirs, i); - extra_path = check_extra_dir_mapping(extra_path); + extra_path = get_extra_remap(extra_path); dir_create_dir(extra_path, DIR_PERMISSION); } } @@ -507,7 +510,7 @@ restore_backup(pgBackup *backup, const char *extra_dir_str) { char container_dir[MAXPGPATH]; - extra_path = check_extra_dir_mapping(extra_path); + extra_path = get_extra_remap(extra_path); makeExtraDirPathByNum(container_dir, extra_prefix, file->extra_dir_num); dir_name = GetRelativePath(file->path, container_dir); @@ -698,7 +701,7 @@ restore_files(void *arg) file->extra_dir_num - 1); if (backup_contains_extra(extra_path, arguments->req_extra_dirs)) { - extra_path = check_extra_dir_mapping(extra_path); + extra_path = get_extra_remap(extra_path); copy_file(arguments->extra_prefix, extra_path, file); } } diff --git a/tests/external.py b/tests/external.py index 19c6b4df..582402e6 100644 --- a/tests/external.py +++ b/tests/external.py @@ -127,8 +127,8 @@ class ExternalTest(ProbackupTest, unittest.TestCase): repr(self.output), self.cmd)) except ProbackupException as e: self.assertTrue( - 'ERROR: --tablespace-mapping option' in e.message and - 'have an entry in tablespace_map file' in e.message, + 'ERROR: --extra-mapping option' in e.message and + 'have an entry in list of extra directories' in e.message, '\n Unexpected Error Message: {0}\n CMD: {1}'.format( repr(e.message), self.cmd))