1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2024-12-01 09:51:43 +02:00

Throw an error when during a restore operation the user tries to remap

an external directory that is not in the destination backup
This commit is contained in:
Sergey Cherkashin 2019-02-11 18:07:12 +03:00
parent bda5d3b564
commit 14f48dcefb
4 changed files with 51 additions and 8 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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))