1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2025-01-20 11:34:51 +02:00

Rename feature from "extra directories" to "external directories"

This commit is contained in:
Sergey Cherkashin 2019-02-12 17:19:18 +03:00
parent a12fe744f9
commit dbefa9e183
11 changed files with 289 additions and 272 deletions

View File

@ -468,7 +468,7 @@ do_backup_instance(void)
{ {
int i; int i;
char database_path[MAXPGPATH]; char database_path[MAXPGPATH];
char extra_prefix[MAXPGPATH]; /* Temp value. Used as template */ char external_prefix[MAXPGPATH]; /* Temp value. Used as template */
char dst_backup_path[MAXPGPATH]; char dst_backup_path[MAXPGPATH];
char label[1024]; char label[1024];
XLogRecPtr prev_backup_start_lsn = InvalidXLogRecPtr; XLogRecPtr prev_backup_start_lsn = InvalidXLogRecPtr;
@ -481,13 +481,13 @@ do_backup_instance(void)
pgBackup *prev_backup = NULL; pgBackup *prev_backup = NULL;
parray *prev_backup_filelist = NULL; parray *prev_backup_filelist = NULL;
parray *backup_list = NULL; parray *backup_list = NULL;
parray *extra_dirs = NULL; parray *external_dirs = NULL;
pgFile *pg_control = NULL; pgFile *pg_control = NULL;
elog(LOG, "Database backup start"); elog(LOG, "Database backup start");
if(current.extra_dir_str) if(current.external_dir_str)
extra_dirs = make_extra_directory_list(current.extra_dir_str); external_dirs = make_external_directory_list(current.external_dir_str);
/* Initialize size summary */ /* Initialize size summary */
current.data_bytes = 0; current.data_bytes = 0;
@ -579,7 +579,8 @@ do_backup_instance(void)
pg_start_backup(label, smooth_checkpoint, &current); pg_start_backup(label, smooth_checkpoint, &current);
pgBackupGetPath(&current, database_path, lengthof(database_path),DATABASE_DIR); pgBackupGetPath(&current, database_path, lengthof(database_path),DATABASE_DIR);
pgBackupGetPath(&current, extra_prefix, lengthof(extra_prefix), EXTRA_DIR); pgBackupGetPath(&current, external_prefix, lengthof(external_prefix),
EXTERNAL_DIR);
/* start stream replication */ /* start stream replication */
if (stream_wal) if (stream_wal)
@ -636,12 +637,13 @@ do_backup_instance(void)
/* /*
* Append to backup list all files and directories * Append to backup list all files and directories
* from extra directory option * from external directory option
*/ */
if (extra_dirs) if (external_dirs)
for (i = 0; i < parray_num(extra_dirs); i++) for (i = 0; i < parray_num(external_dirs); i++)
/* Extra dirs numeration starts with 1. 0 value is not extra dir */ /* External dirs numeration starts with 1.
dir_list_file(backup_files_list, parray_get(extra_dirs, i), * 0 value is not external dir */
dir_list_file(backup_files_list, parray_get(external_dirs, i),
false, true, false, i+1); false, true, false, i+1);
/* /*
@ -705,9 +707,10 @@ do_backup_instance(void)
char *dir_name; char *dir_name;
if (!is_remote_backup) if (!is_remote_backup)
if (file->extra_dir_num) if (file->external_dir_num)
dir_name = GetRelativePath(file->path, dir_name = GetRelativePath(file->path,
parray_get(extra_dirs, file->extra_dir_num - 1)); parray_get(external_dirs,
file->external_dir_num - 1));
else else
dir_name = GetRelativePath(file->path, instance_config.pgdata); dir_name = GetRelativePath(file->path, instance_config.pgdata);
else else
@ -715,10 +718,11 @@ do_backup_instance(void)
elog(VERBOSE, "Create directory \"%s\"", dir_name); elog(VERBOSE, "Create directory \"%s\"", dir_name);
if (file->extra_dir_num) if (file->external_dir_num)
{ {
char temp[MAXPGPATH]; char temp[MAXPGPATH];
snprintf(temp, MAXPGPATH, "%s%d", extra_prefix, file->extra_dir_num); snprintf(temp, MAXPGPATH, "%s%d", external_prefix,
file->external_dir_num);
join_path_components(dirpath, temp, dir_name); join_path_components(dirpath, temp, dir_name);
} }
else else
@ -734,7 +738,7 @@ do_backup_instance(void)
parray_qsort(backup_files_list, pgFileCompareSize); parray_qsort(backup_files_list, pgFileCompareSize);
/* Sort the array for binary search */ /* Sort the array for binary search */
if (prev_backup_filelist) if (prev_backup_filelist)
parray_qsort(prev_backup_filelist, pgFileComparePathWithExtra); parray_qsort(prev_backup_filelist, pgFileComparePathWithExternal);
/* init thread args with own file lists */ /* init thread args with own file lists */
threads = (pthread_t *) palloc(sizeof(pthread_t) * num_threads); threads = (pthread_t *) palloc(sizeof(pthread_t) * num_threads);
@ -746,8 +750,8 @@ do_backup_instance(void)
arg->from_root = instance_config.pgdata; arg->from_root = instance_config.pgdata;
arg->to_root = database_path; arg->to_root = database_path;
arg->extra_prefix = extra_prefix; arg->external_prefix = external_prefix;
arg->extra_dirs = extra_dirs; arg->external_dirs = external_dirs;
arg->files_list = backup_files_list; arg->files_list = backup_files_list;
arg->prev_filelist = prev_backup_filelist; arg->prev_filelist = prev_backup_filelist;
arg->prev_start_lsn = prev_backup_start_lsn; arg->prev_start_lsn = prev_backup_start_lsn;
@ -853,11 +857,11 @@ do_backup_instance(void)
/* Print the list of files to backup catalog */ /* Print the list of files to backup catalog */
write_backup_filelist(&current, backup_files_list, instance_config.pgdata, write_backup_filelist(&current, backup_files_list, instance_config.pgdata,
NULL, extra_dirs); NULL, external_dirs);
/* clean extra directories list */ /* clean external directories list */
if (extra_dirs) if (external_dirs)
free_dir_list(extra_dirs); free_dir_list(external_dirs);
/* Compute summary of size of regular files in the backup */ /* Compute summary of size of regular files in the backup */
for (i = 0; i < parray_num(backup_files_list); i++) for (i = 0; i < parray_num(backup_files_list); i++)
@ -990,11 +994,11 @@ do_backup(time_t start_time)
StrNCpy(current.program_version, PROGRAM_VERSION, StrNCpy(current.program_version, PROGRAM_VERSION,
sizeof(current.program_version)); sizeof(current.program_version));
/* Save list of extra directories */ /* Save list of external directories */
if (instance_config.extra_dir_str && if (instance_config.external_dir_str &&
pg_strcasecmp(instance_config.extra_dir_str, "none") != 0) pg_strcasecmp(instance_config.external_dir_str, "none") != 0)
{ {
current.extra_dir_str = instance_config.extra_dir_str; current.external_dir_str = instance_config.external_dir_str;
} }
/* Create backup directory and BACKUP_CONTROL_FILE */ /* Create backup directory and BACKUP_CONTROL_FILE */
@ -2292,11 +2296,11 @@ backup_files(void *arg)
if (S_ISREG(buf.st_mode)) if (S_ISREG(buf.st_mode))
{ {
pgFile **prev_file = NULL; pgFile **prev_file = NULL;
char *extra_path = NULL; char *external_path = NULL;
if (file->extra_dir_num) if (file->external_dir_num)
extra_path = parray_get(arguments->extra_dirs, external_path = parray_get(arguments->external_dirs,
file->extra_dir_num - 1); file->external_dir_num - 1);
/* Check that file exist in previous backup */ /* Check that file exist in previous backup */
if (current.backup_mode != BACKUP_MODE_FULL) if (current.backup_mode != BACKUP_MODE_FULL)
@ -2304,13 +2308,13 @@ backup_files(void *arg)
char *relative; char *relative;
pgFile key; pgFile key;
relative = GetRelativePath(file->path, file->extra_dir_num ? relative = GetRelativePath(file->path, file->external_dir_num ?
extra_path : arguments->from_root); external_path : arguments->from_root);
key.path = relative; key.path = relative;
key.extra_dir_num = file->extra_dir_num; key.external_dir_num = file->external_dir_num;
prev_file = (pgFile **) parray_bsearch(arguments->prev_filelist, prev_file = (pgFile **) parray_bsearch(arguments->prev_filelist,
&key, pgFileComparePathWithExtra); &key, pgFileComparePathWithExternal);
if (prev_file) if (prev_file)
/* File exists in previous backup */ /* File exists in previous backup */
file->exists_in_prev = true; file->exists_in_prev = true;
@ -2335,7 +2339,7 @@ backup_files(void *arg)
continue; continue;
} }
} }
else if (!file->extra_dir_num && else if (!file->external_dir_num &&
strcmp(file->name, "pg_control") == 0) strcmp(file->name, "pg_control") == 0)
copy_pgcontrol_file(arguments->from_root, arguments->to_root, copy_pgcontrol_file(arguments->from_root, arguments->to_root,
file); file);
@ -2344,7 +2348,7 @@ backup_files(void *arg)
const char *src; const char *src;
const char *dst; const char *dst;
bool skip = false; bool skip = false;
char extra_dst[MAXPGPATH]; char external_dst[MAXPGPATH];
/* If non-data file has not changed since last backup... */ /* If non-data file has not changed since last backup... */
if (prev_file && file->exists_in_prev && if (prev_file && file->exists_in_prev &&
@ -2356,12 +2360,13 @@ backup_files(void *arg)
skip = true; /* ...skip copying file. */ skip = true; /* ...skip copying file. */
} }
/* Set file paths */ /* Set file paths */
if (file->extra_dir_num) if (file->external_dir_num)
{ {
makeExtraDirPathByNum(extra_dst, arguments->extra_prefix, makeExternalDirPathByNum(external_dst,
file->extra_dir_num); arguments->external_prefix,
src = extra_path; file->external_dir_num);
dst = extra_dst; src = external_path;
dst = external_dst;
} }
else else
{ {

View File

@ -414,19 +414,21 @@ pgBackupCreateDir(pgBackup *backup)
temp = palloc(strlen(DATABASE_DIR) + 1); temp = palloc(strlen(DATABASE_DIR) + 1);
parray_append(subdirs, temp); parray_append(subdirs, temp);
/* Add extra dirs containers */ /* Add external dirs containers */
if (backup->extra_dir_str) if (backup->external_dir_str)
{ {
parray *extradirs_list = make_extra_directory_list(backup->extra_dir_str); parray *external_list;
for (int i = 0; i < parray_num(extradirs_list); i++)
external_list = make_external_directory_list(backup->external_dir_str);
for (int i = 0; i < parray_num(external_list); i++)
{ {
/* 20 chars is enough to hold the extradir number in string. */ /* 20 chars is enough to hold the externaldir number in string. */
temp = palloc(strlen(EXTRA_DIR) + 20); temp = palloc(strlen(EXTERNAL_DIR) + 20);
/* Numeration of extradirs starts with 1 */ /* Numeration of externaldirs starts with 1 */
makeExtraDirPathByNum(temp, EXTRA_DIR, i+1); makeExternalDirPathByNum(temp, EXTERNAL_DIR, i+1);
parray_append(subdirs, temp); parray_append(subdirs, temp);
} }
free_dir_list(extradirs_list); free_dir_list(external_list);
} }
pgBackupGetPath(backup, path, lengthof(path), NULL); pgBackupGetPath(backup, path, lengthof(path), NULL);
@ -517,9 +519,9 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
if (backup->primary_conninfo) if (backup->primary_conninfo)
fprintf(out, "primary_conninfo = '%s'\n", backup->primary_conninfo); fprintf(out, "primary_conninfo = '%s'\n", backup->primary_conninfo);
/* print extra directories list */ /* print external directories list */
if (backup->extra_dir_str) if (backup->external_dir_str)
fprintf(out, "extra-directory = '%s'\n", backup->extra_dir_str); fprintf(out, "external-dirs = '%s'\n", backup->external_dir_str);
} }
/* /*
@ -551,7 +553,7 @@ write_backup(pgBackup *backup)
*/ */
void void
write_backup_filelist(pgBackup *backup, parray *files, const char *root, write_backup_filelist(pgBackup *backup, parray *files, const char *root,
const char *extra_prefix, parray *extra_list) const char *external_prefix, parray *external_list)
{ {
FILE *fp; FILE *fp;
char path[MAXPGPATH]; char path[MAXPGPATH];
@ -563,7 +565,7 @@ write_backup_filelist(pgBackup *backup, parray *files, const char *root,
elog(ERROR, "Cannot open file list \"%s\": %s", path, elog(ERROR, "Cannot open file list \"%s\": %s", path,
strerror(errno)); strerror(errno));
print_file_list(fp, files, root, extra_prefix, extra_list); print_file_list(fp, files, root, external_prefix, external_list);
if (fflush(fp) != 0 || if (fflush(fp) != 0 ||
fsync(fileno(fp)) != 0 || fsync(fileno(fp)) != 0 ||
@ -614,7 +616,7 @@ readBackupControlFile(const char *path)
{'u', 0, "compress-level", &backup->compress_level, SOURCE_FILE_STRICT}, {'u', 0, "compress-level", &backup->compress_level, SOURCE_FILE_STRICT},
{'b', 0, "from-replica", &backup->from_replica, SOURCE_FILE_STRICT}, {'b', 0, "from-replica", &backup->from_replica, SOURCE_FILE_STRICT},
{'s', 0, "primary-conninfo", &backup->primary_conninfo, SOURCE_FILE_STRICT}, {'s', 0, "primary-conninfo", &backup->primary_conninfo, SOURCE_FILE_STRICT},
{'s', 0, "extra-directory", &backup->extra_dir_str, SOURCE_FILE_STRICT}, {'s', 0, "external-dirs", &backup->external_dir_str, SOURCE_FILE_STRICT},
{0} {0}
}; };
@ -844,7 +846,7 @@ pgBackupInit(pgBackup *backup)
backup->primary_conninfo = NULL; backup->primary_conninfo = NULL;
backup->program_version[0] = '\0'; backup->program_version[0] = '\0';
backup->server_version[0] = '\0'; backup->server_version[0] = '\0';
backup->extra_dir_str = NULL; backup->external_dir_str = NULL;
} }
/* free pgBackup object */ /* free pgBackup object */
@ -854,7 +856,7 @@ pgBackupFree(void *backup)
pgBackup *b = (pgBackup *) backup; pgBackup *b = (pgBackup *) backup;
pfree(b->primary_conninfo); pfree(b->primary_conninfo);
pfree(b->extra_dir_str); pfree(b->external_dir_str);
pfree(backup); pfree(backup);
} }

View File

@ -62,8 +62,8 @@ ConfigOption instance_options[] =
}, },
#endif #endif
{ {
's', 'E', "extra-directory", 's', 'E', "external-dirs",
&instance_config.extra_dir_str, SOURCE_CMD, 0, &instance_config.external_dir_str, SOURCE_CMD, 0,
OPTION_INSTANCE_GROUP, 0, option_get_value OPTION_INSTANCE_GROUP, 0, option_get_value
}, },
/* Connection options */ /* Connection options */

106
src/dir.c
View File

@ -122,7 +122,7 @@ static char dir_check_file(const char *root, pgFile *file);
static void dir_list_file_internal(parray *files, const char *root, static void dir_list_file_internal(parray *files, const char *root,
pgFile *parent, bool exclude, pgFile *parent, bool exclude,
bool omit_symlink, parray *black_list, bool omit_symlink, parray *black_list,
int extra_dir_num); int external_dir_num);
static void list_data_directories(parray *files, const char *path, bool is_root, static void list_data_directories(parray *files, const char *path, bool is_root,
bool exclude); bool exclude);
@ -133,7 +133,7 @@ static void opt_path_map(ConfigOption *opt, const char *arg,
static TablespaceList tablespace_dirs = {NULL, NULL}; static TablespaceList tablespace_dirs = {NULL, NULL};
static TablespaceCreatedList tablespace_created_dirs = {NULL, NULL}; static TablespaceCreatedList tablespace_created_dirs = {NULL, NULL};
/* Extra directories mapping */ /* Extra directories mapping */
static TablespaceList extra_remap_list = {NULL, NULL}; static TablespaceList external_remap_list = {NULL, NULL};
/* /*
* Create directory, also create parent directories if necessary. * Create directory, also create parent directories if necessary.
@ -162,7 +162,7 @@ dir_create_dir(const char *dir, mode_t mode)
} }
pgFile * pgFile *
pgFileNew(const char *path, bool omit_symlink, int extra_dir_num) pgFileNew(const char *path, bool omit_symlink, int external_dir_num)
{ {
struct stat st; struct stat st;
pgFile *file; pgFile *file;
@ -180,7 +180,7 @@ pgFileNew(const char *path, bool omit_symlink, int extra_dir_num)
file = pgFileInit(path); file = pgFileInit(path);
file->size = st.st_size; file->size = st.st_size;
file->mode = st.st_mode; file->mode = st.st_mode;
file->extra_dir_num = extra_dir_num; file->external_dir_num = external_dir_num;
return file; return file;
} }
@ -231,7 +231,7 @@ pgFileInit(const char *path)
/* Number of blocks readed during backup */ /* Number of blocks readed during backup */
file->n_blocks = BLOCKNUM_INVALID; file->n_blocks = BLOCKNUM_INVALID;
file->compress_alg = NOT_DEFINED_COMPRESS; file->compress_alg = NOT_DEFINED_COMPRESS;
file->extra_dir_num = 0; file->external_dir_num = 0;
return file; return file;
} }
@ -353,11 +353,11 @@ pgFileComparePath(const void *f1, const void *f2)
} }
/* /*
* Compare two pgFile with their path and extra_dir_num * Compare two pgFile with their path and external_dir_num
* in ascending order of ASCII code. * in ascending order of ASCII code.
*/ */
int int
pgFileComparePathWithExtra(const void *f1, const void *f2) pgFileComparePathWithExternal(const void *f1, const void *f2)
{ {
pgFile *f1p = *(pgFile **)f1; pgFile *f1p = *(pgFile **)f1;
pgFile *f2p = *(pgFile **)f2; pgFile *f2p = *(pgFile **)f2;
@ -366,9 +366,9 @@ pgFileComparePathWithExtra(const void *f1, const void *f2)
res = strcmp(f1p->path, f2p->path); res = strcmp(f1p->path, f2p->path);
if (!res) if (!res)
{ {
if (f1p->extra_dir_num > f2p->extra_dir_num) if (f1p->external_dir_num > f2p->external_dir_num)
return 1; return 1;
else if (f1p->extra_dir_num < f2p->extra_dir_num) else if (f1p->external_dir_num < f2p->external_dir_num)
return -1; return -1;
else else
return 0; return 0;
@ -423,7 +423,7 @@ BlackListCompare(const void *str1, const void *str2)
*/ */
void void
dir_list_file(parray *files, const char *root, bool exclude, bool omit_symlink, dir_list_file(parray *files, const char *root, bool exclude, bool omit_symlink,
bool add_root, int extra_dir_num) bool add_root, int external_dir_num)
{ {
pgFile *file; pgFile *file;
parray *black_list = NULL; parray *black_list = NULL;
@ -462,7 +462,7 @@ dir_list_file(parray *files, const char *root, bool exclude, bool omit_symlink,
parray_qsort(black_list, BlackListCompare); parray_qsort(black_list, BlackListCompare);
} }
file = pgFileNew(root, false, extra_dir_num); file = pgFileNew(root, false, external_dir_num);
if (file == NULL) if (file == NULL)
return; return;
@ -475,7 +475,7 @@ dir_list_file(parray *files, const char *root, bool exclude, bool omit_symlink,
parray_append(files, file); parray_append(files, file);
dir_list_file_internal(files, root, file, exclude, omit_symlink, black_list, dir_list_file_internal(files, root, file, exclude, omit_symlink, black_list,
extra_dir_num); external_dir_num);
if (!add_root) if (!add_root)
pgFileFree(file); pgFileFree(file);
@ -686,7 +686,8 @@ dir_check_file(const char *root, pgFile *file)
*/ */
static void static void
dir_list_file_internal(parray *files, const char *root, pgFile *parent, dir_list_file_internal(parray *files, const char *root, pgFile *parent,
bool exclude, bool omit_symlink, parray *black_list, int extra_dir_num) bool exclude, bool omit_symlink, parray *black_list,
int external_dir_num)
{ {
DIR *dir; DIR *dir;
struct dirent *dent; struct dirent *dent;
@ -716,7 +717,7 @@ dir_list_file_internal(parray *files, const char *root, pgFile *parent,
join_path_components(child, parent->path, dent->d_name); join_path_components(child, parent->path, dent->d_name);
file = pgFileNew(child, omit_symlink, extra_dir_num); file = pgFileNew(child, omit_symlink, external_dir_num);
if (file == NULL) if (file == NULL)
continue; continue;
@ -773,7 +774,7 @@ dir_list_file_internal(parray *files, const char *root, pgFile *parent,
*/ */
if (S_ISDIR(file->mode)) if (S_ISDIR(file->mode))
dir_list_file_internal(files, root, file, exclude, omit_symlink, dir_list_file_internal(files, root, file, exclude, omit_symlink,
black_list, extra_dir_num); black_list, external_dir_num);
} }
if (errno && errno != ENOENT) if (errno && errno != ENOENT)
@ -986,11 +987,11 @@ opt_tablespace_map(ConfigOption *opt, const char *arg)
opt_path_map(opt, arg, &tablespace_dirs, "tablespace"); opt_path_map(opt, arg, &tablespace_dirs, "tablespace");
} }
/* Parse extra directories mapping */ /* Parse external directories mapping */
void void
opt_extradir_map(ConfigOption *opt, const char *arg) opt_externaldir_map(ConfigOption *opt, const char *arg)
{ {
opt_path_map(opt, arg, &extra_remap_list, "extra directory"); opt_path_map(opt, arg, &external_remap_list, "external directory");
} }
/* /*
@ -1264,31 +1265,31 @@ check_tablespace_mapping(pgBackup *backup)
} }
void void
check_extra_dir_mapping(pgBackup *backup) check_external_dir_mapping(pgBackup *backup)
{ {
TablespaceListCell *cell; TablespaceListCell *cell;
parray *extra_dirs_to_restore; parray *external_dirs_to_restore;
bool found; bool found;
int i; int i;
if (!backup->extra_dir_str) if (!backup->external_dir_str)
{ {
if (extra_remap_list.head) if (external_remap_list.head)
elog(ERROR, "--extra-mapping option's old directory doesn't have " elog(ERROR, "--external-mapping option's old directory doesn't "
"an entry in list of extra directories of current " "have an entry in list of external directories of current "
"backup: \"%s\"", extra_remap_list.head->old_dir); "backup: \"%s\"", external_remap_list.head->old_dir);
return; return;
} }
extra_dirs_to_restore = make_extra_directory_list(backup->extra_dir_str); external_dirs_to_restore = make_external_directory_list(backup->external_dir_str);
for (cell = extra_remap_list.head; cell; cell = cell->next) for (cell = external_remap_list.head; cell; cell = cell->next)
{ {
char *old_dir = cell->old_dir; char *old_dir = cell->old_dir;
found = false; found = false;
for (i = 0; i < parray_num(extra_dirs_to_restore); i++) for (i = 0; i < parray_num(external_dirs_to_restore); i++)
{ {
char *external_dir = parray_get(extra_dirs_to_restore, i); char *external_dir = parray_get(external_dirs_to_restore, i);
if (strcmp(old_dir, external_dir) == 0) if (strcmp(old_dir, external_dir) == 0)
{ {
found = true; found = true;
@ -1296,18 +1297,18 @@ check_extra_dir_mapping(pgBackup *backup)
} }
} }
if (!found) if (!found)
elog(ERROR, "--extra-mapping option's old directory doesn't have " elog(ERROR, "--external-mapping option's old directory doesn't "
"an entry in list of extra directories of current " "have an entry in list of external directories of current "
"backup: \"%s\"", cell->old_dir); "backup: \"%s\"", cell->old_dir);
} }
} }
char * char *
get_extra_remap(char *current_dir) get_external_remap(char *current_dir)
{ {
TablespaceListCell *cell; TablespaceListCell *cell;
for (cell = extra_remap_list.head; cell; cell = cell->next) for (cell = external_remap_list.head; cell; cell = cell->next)
{ {
char *old_dir = cell->old_dir; char *old_dir = cell->old_dir;
@ -1322,7 +1323,7 @@ get_extra_remap(char *current_dir)
*/ */
void void
print_file_list(FILE *out, const parray *files, const char *root, print_file_list(FILE *out, const parray *files, const char *root,
const char *extra_prefix, parray *extra_list) const char *external_prefix, parray *external_list)
{ {
size_t i; size_t i;
@ -1335,20 +1336,20 @@ print_file_list(FILE *out, const parray *files, const char *root,
/* omit root directory portion */ /* omit root directory portion */
if (root && strstr(path, root) == path) if (root && strstr(path, root) == path)
path = GetRelativePath(path, root); path = GetRelativePath(path, root);
else if (file->extra_dir_num && !extra_prefix) else if (file->external_dir_num && !external_prefix)
{ {
Assert(extra_list); Assert(external_list);
path = GetRelativePath(path, parray_get(extra_list, path = GetRelativePath(path, parray_get(external_list,
file->extra_dir_num - 1)); file->external_dir_num - 1));
} }
fprintf(out, "{\"path\":\"%s\", \"size\":\"" INT64_FORMAT "\", " fprintf(out, "{\"path\":\"%s\", \"size\":\"" INT64_FORMAT "\", "
"\"mode\":\"%u\", \"is_datafile\":\"%u\", " "\"mode\":\"%u\", \"is_datafile\":\"%u\", "
"\"is_cfs\":\"%u\", \"crc\":\"%u\", " "\"is_cfs\":\"%u\", \"crc\":\"%u\", "
"\"compress_alg\":\"%s\", \"extra_dir_num\":\"%d\"", "\"compress_alg\":\"%s\", \"external_dir_num\":\"%d\"",
path, file->write_size, file->mode, path, file->write_size, file->mode,
file->is_datafile ? 1 : 0, file->is_cfs ? 1 : 0, file->crc, file->is_datafile ? 1 : 0, file->is_cfs ? 1 : 0, file->crc,
deparse_compress_alg(file->compress_alg), file->extra_dir_num); deparse_compress_alg(file->compress_alg), file->external_dir_num);
if (file->is_datafile) if (file->is_datafile)
fprintf(out, ",\"segno\":\"%d\"", file->segno); fprintf(out, ",\"segno\":\"%d\"", file->segno);
@ -1511,7 +1512,8 @@ bad_format:
* If root is not NULL, path will be absolute path. * If root is not NULL, path will be absolute path.
*/ */
parray * parray *
dir_read_file_list(const char *root, const char *extra_prefix, const char *file_txt) dir_read_file_list(const char *root, const char *external_prefix,
const char *file_txt)
{ {
FILE *fp; FILE *fp;
parray *files; parray *files;
@ -1533,7 +1535,7 @@ dir_read_file_list(const char *root, const char *extra_prefix, const char *file_
mode, /* bit length of mode_t depends on platforms */ mode, /* bit length of mode_t depends on platforms */
is_datafile, is_datafile,
is_cfs, is_cfs,
extra_dir_num, external_dir_num,
crc, crc,
segno, segno,
n_blocks; n_blocks;
@ -1546,13 +1548,13 @@ dir_read_file_list(const char *root, const char *extra_prefix, const char *file_
get_control_value(buf, "is_cfs", NULL, &is_cfs, false); get_control_value(buf, "is_cfs", NULL, &is_cfs, false);
get_control_value(buf, "crc", NULL, &crc, true); get_control_value(buf, "crc", NULL, &crc, true);
get_control_value(buf, "compress_alg", compress_alg_string, NULL, false); get_control_value(buf, "compress_alg", compress_alg_string, NULL, false);
get_control_value(buf, "extra_dir_num", NULL, &extra_dir_num, false); get_control_value(buf, "external_dir_num", NULL, &external_dir_num, false);
if (extra_dir_num && extra_prefix) if (external_dir_num && external_prefix)
{ {
char temp[MAXPGPATH]; char temp[MAXPGPATH];
makeExtraDirPathByNum(temp, extra_prefix, extra_dir_num); makeExternalDirPathByNum(temp, external_prefix, external_dir_num);
join_path_components(filepath, temp, path); join_path_components(filepath, temp, path);
} }
else if (root) else if (root)
@ -1568,7 +1570,7 @@ dir_read_file_list(const char *root, const char *extra_prefix, const char *file_
file->is_cfs = is_cfs ? true : false; file->is_cfs = is_cfs ? true : false;
file->crc = (pg_crc32) crc; file->crc = (pg_crc32) crc;
file->compress_alg = parse_compress_alg(compress_alg_string); file->compress_alg = parse_compress_alg(compress_alg_string);
file->extra_dir_num = extra_dir_num; file->external_dir_num = external_dir_num;
/* /*
* Optional fields * Optional fields
@ -1656,11 +1658,11 @@ pgFileSize(const char *path)
} }
/* /*
* Construct parray containing extra directories paths * Construct parray containing external directories paths
* from string like /path1:/path2 * from string like /path1:/path2
*/ */
parray * parray *
make_extra_directory_list(const char *colon_separated_dirs) make_external_directory_list(const char *colon_separated_dirs)
{ {
char *p; char *p;
parray *list = parray_new(); parray *list = parray_new();
@ -1693,19 +1695,19 @@ free_dir_list(parray *list)
/* Append to string "path_prefix" int "dir_num" */ /* Append to string "path_prefix" int "dir_num" */
void void
makeExtraDirPathByNum(char *ret_path, const char *path_prefix, makeExternalDirPathByNum(char *ret_path, const char *path_prefix,
const int dir_num) const int dir_num)
{ {
sprintf(ret_path, "%s%d", path_prefix, dir_num); sprintf(ret_path, "%s%d", path_prefix, dir_num);
} }
/* Check if "dir" presents in "dirs_list" */ /* Check if "dir" presents in "dirs_list" */
bool bool
backup_contains_extra(const char *dir, parray *dirs_list) backup_contains_external(const char *dir, parray *dirs_list)
{ {
void *search_result; void *search_result;
if (!dirs_list) /* There is no extra dirs in backup */ if (!dirs_list) /* There is no external dirs in backup */
return false; return false;
search_result = parray_bsearch(dirs_list, dir, BlackListCompare); search_result = parray_bsearch(dirs_list, dir, BlackListCompare);
return search_result != NULL; return search_result != NULL;

View File

@ -119,13 +119,13 @@ help_pg_probackup(void)
printf(_(" [--master-port=port] [--master-user=user_name]\n")); printf(_(" [--master-port=port] [--master-user=user_name]\n"));
printf(_(" [--replica-timeout=timeout]\n")); printf(_(" [--replica-timeout=timeout]\n"));
printf(_(" [--skip-block-validation]\n")); printf(_(" [--skip-block-validation]\n"));
printf(_(" [--extra-directory=extra-directory-path]\n")); printf(_(" [--external-dirs=external-directory-path]\n"));
printf(_("\n %s restore -B backup-path --instance=instance_name\n"), PROGRAM_NAME); printf(_("\n %s restore -B backup-path --instance=instance_name\n"), PROGRAM_NAME);
printf(_(" [-D pgdata-path] [-i backup-id] [--progress]\n")); printf(_(" [-D pgdata-path] [-i backup-id] [--progress]\n"));
printf(_(" [--time=time|--xid=xid|--lsn=lsn [--inclusive=boolean]]\n")); printf(_(" [--time=time|--xid=xid|--lsn=lsn [--inclusive=boolean]]\n"));
printf(_(" [--timeline=timeline] [-T OLDDIR=NEWDIR]\n")); printf(_(" [--timeline=timeline] [-T OLDDIR=NEWDIR]\n"));
printf(_(" [--extra-mapping=OLDDIR=NEWDIR]\n")); printf(_(" [--external-mapping=OLDDIR=NEWDIR]\n"));
printf(_(" [--immediate] [--recovery-target-name=target-name]\n")); printf(_(" [--immediate] [--recovery-target-name=target-name]\n"));
printf(_(" [--recovery-target-action=pause|promote|shutdown]\n")); printf(_(" [--recovery-target-action=pause|promote|shutdown]\n"));
printf(_(" [--restore-as-replica]\n")); printf(_(" [--restore-as-replica]\n"));
@ -210,7 +210,7 @@ help_backup(void)
printf(_(" [--master-port=port] [--master-user=user_name]\n")); printf(_(" [--master-port=port] [--master-user=user_name]\n"));
printf(_(" [--replica-timeout=timeout]\n")); printf(_(" [--replica-timeout=timeout]\n"));
printf(_(" [--skip-block-validation]\n")); printf(_(" [--skip-block-validation]\n"));
printf(_(" [-E extra-directory=extra-directory-path]\n\n")); printf(_(" [-E external-dirs=external-directory-path]\n\n"));
printf(_(" -B, --backup-path=backup-path location of the backup storage area\n")); printf(_(" -B, --backup-path=backup-path location of the backup storage area\n"));
printf(_(" -b, --backup-mode=backup-mode backup mode=FULL|PAGE|DELTA|PTRACK\n")); printf(_(" -b, --backup-mode=backup-mode backup mode=FULL|PAGE|DELTA|PTRACK\n"));
@ -223,7 +223,7 @@ help_backup(void)
printf(_(" --archive-timeout=timeout wait timeout for WAL segment archiving (default: 5min)\n")); printf(_(" --archive-timeout=timeout wait timeout for WAL segment archiving (default: 5min)\n"));
printf(_(" --progress show progress\n")); printf(_(" --progress show progress\n"));
printf(_(" --skip-block-validation set to validate only file-level checksum\n")); printf(_(" --skip-block-validation set to validate only file-level checksum\n"));
printf(_(" -E --extra-directory=extra-directory-path\n")); printf(_(" -E --external-dirs=external-directory-path\n"));
printf(_(" backup some directory not from pgdata \n")); printf(_(" backup some directory not from pgdata \n"));
printf(_("\n Logging options:\n")); printf(_("\n Logging options:\n"));
@ -286,7 +286,7 @@ help_restore(void)
printf(_(" [-D pgdata-path] [-i backup-id] [--progress]\n")); printf(_(" [-D pgdata-path] [-i backup-id] [--progress]\n"));
printf(_(" [--time=time|--xid=xid|--lsn=lsn [--inclusive=boolean]]\n")); printf(_(" [--time=time|--xid=xid|--lsn=lsn [--inclusive=boolean]]\n"));
printf(_(" [--timeline=timeline] [-T OLDDIR=NEWDIR]\n")); printf(_(" [--timeline=timeline] [-T OLDDIR=NEWDIR]\n"));
printf(_(" [--extra-mapping=OLDDIR=NEWDIR]\n")); printf(_(" [--external-mapping=OLDDIR=NEWDIR]\n"));
printf(_(" [--immediate] [--recovery-target-name=target-name]\n")); printf(_(" [--immediate] [--recovery-target-name=target-name]\n"));
printf(_(" [--recovery-target-action=pause|promote|shutdown]\n")); printf(_(" [--recovery-target-action=pause|promote|shutdown]\n"));
printf(_(" [--restore-as-replica] [--no-validate]\n")); printf(_(" [--restore-as-replica] [--no-validate]\n"));
@ -306,8 +306,8 @@ help_restore(void)
printf(_(" --timeline=timeline recovering into a particular timeline\n")); printf(_(" --timeline=timeline recovering into a particular timeline\n"));
printf(_(" -T, --tablespace-mapping=OLDDIR=NEWDIR\n")); printf(_(" -T, --tablespace-mapping=OLDDIR=NEWDIR\n"));
printf(_(" relocate the tablespace from directory OLDDIR to NEWDIR\n")); printf(_(" relocate the tablespace from directory OLDDIR to NEWDIR\n"));
printf(_(" --extra-mapping=OLDDIR=NEWDIR\n")); printf(_(" --external-mapping=OLDDIR=NEWDIR\n"));
printf(_(" relocate the extra directory from OLDDIR to NEWDIR\n")); printf(_(" relocate the external directory from OLDDIR to NEWDIR\n"));
printf(_(" --immediate end recovery as soon as a consistent state is reached\n")); printf(_(" --immediate end recovery as soon as a consistent state is reached\n"));
printf(_(" --recovery-target-name=target-name\n")); printf(_(" --recovery-target-name=target-name\n"));
@ -498,11 +498,11 @@ help_set_config(void)
printf(_(" [--master-port=port] [--master-user=user_name]\n")); printf(_(" [--master-port=port] [--master-user=user_name]\n"));
printf(_(" [--replica-timeout=timeout]\n")); printf(_(" [--replica-timeout=timeout]\n"));
printf(_(" [--archive-timeout=timeout]\n")); printf(_(" [--archive-timeout=timeout]\n"));
printf(_(" [-E extra-directory=extra-directory-path]\n\n")); printf(_(" [-E external-dirs=external-directory-path]\n\n"));
printf(_(" -B, --backup-path=backup-path location of the backup storage area\n")); printf(_(" -B, --backup-path=backup-path location of the backup storage area\n"));
printf(_(" --instance=instance_name name of the instance\n")); printf(_(" --instance=instance_name name of the instance\n"));
printf(_(" -E --extra-directory=extra-directory-path\n")); printf(_(" -E --external-dirs=external-directory-path\n"));
printf(_(" backup some directory not from pgdata \n")); printf(_(" backup some directory not from pgdata \n"));
printf(_("\n Logging options:\n")); printf(_("\n Logging options:\n"));
@ -570,12 +570,12 @@ help_add_instance(void)
{ {
printf(_("%s add-instance -B backup-path -D pgdata-path\n"), PROGRAM_NAME); printf(_("%s add-instance -B backup-path -D pgdata-path\n"), PROGRAM_NAME);
printf(_(" --instance=instance_name\n")); printf(_(" --instance=instance_name\n"));
printf(_(" -E extra-directory=extra-directory-path\n\n")); printf(_(" -E external-dirs=external-directory-path\n\n"));
printf(_(" -B, --backup-path=backup-path location of the backup storage area\n")); printf(_(" -B, --backup-path=backup-path location of the backup storage area\n"));
printf(_(" -D, --pgdata=pgdata-path location of the database storage area\n")); printf(_(" -D, --pgdata=pgdata-path location of the database storage area\n"));
printf(_(" --instance=instance_name name of the new instance\n")); printf(_(" --instance=instance_name name of the new instance\n"));
printf(_(" -E --extra-directory=extra-directory-path\n")); printf(_(" -E --external-dirs=external-directory-path\n"));
printf(_(" backup some directory not from pgdata \n")); printf(_(" backup some directory not from pgdata \n"));
} }

View File

@ -18,14 +18,14 @@ typedef struct
{ {
parray *to_files; parray *to_files;
parray *files; parray *files;
parray *from_extra; parray *from_external;
pgBackup *to_backup; pgBackup *to_backup;
pgBackup *from_backup; pgBackup *from_backup;
const char *to_root; const char *to_root;
const char *from_root; const char *from_root;
const char *to_extra_prefix; const char *to_external_prefix;
const char *from_extra_prefix; const char *from_external_prefix;
/* /*
* Return value from the thread. * Return value from the thread.
@ -37,9 +37,10 @@ typedef struct
static void merge_backups(pgBackup *backup, pgBackup *next_backup); static void merge_backups(pgBackup *backup, pgBackup *next_backup);
static void *merge_files(void *arg); static void *merge_files(void *arg);
static void static void
reorder_extra_dirs(pgBackup *to_backup, parray *to_extra, parray *from_extra); reorder_external_dirs(pgBackup *to_backup, parray *to_external,
parray *from_external);
static int static int
get_extra_index(const char *key, const parray *list); get_external_index(const char *key, const parray *list);
/* /*
* Implementation of MERGE command. * Implementation of MERGE command.
@ -165,15 +166,15 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
*from_backup_id = base36enc_dup(from_backup->start_time); *from_backup_id = base36enc_dup(from_backup->start_time);
char to_backup_path[MAXPGPATH], char to_backup_path[MAXPGPATH],
to_database_path[MAXPGPATH], to_database_path[MAXPGPATH],
to_extra_prefix[MAXPGPATH], to_external_prefix[MAXPGPATH],
from_backup_path[MAXPGPATH], from_backup_path[MAXPGPATH],
from_database_path[MAXPGPATH], from_database_path[MAXPGPATH],
from_extra_prefix[MAXPGPATH], from_external_prefix[MAXPGPATH],
control_file[MAXPGPATH]; control_file[MAXPGPATH];
parray *files, parray *files,
*to_files; *to_files;
parray *to_extra = NULL, parray *to_external = NULL,
*from_extra = NULL; *from_external = NULL;
pthread_t *threads = NULL; pthread_t *threads = NULL;
merge_files_arg *threads_args = NULL; merge_files_arg *threads_args = NULL;
int i; int i;
@ -209,13 +210,13 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
pgBackupGetPath(to_backup, to_backup_path, lengthof(to_backup_path), NULL); pgBackupGetPath(to_backup, to_backup_path, lengthof(to_backup_path), NULL);
pgBackupGetPath(to_backup, to_database_path, lengthof(to_database_path), pgBackupGetPath(to_backup, to_database_path, lengthof(to_database_path),
DATABASE_DIR); DATABASE_DIR);
pgBackupGetPath(to_backup, to_extra_prefix, lengthof(to_database_path), pgBackupGetPath(to_backup, to_external_prefix, lengthof(to_database_path),
EXTRA_DIR); EXTERNAL_DIR);
pgBackupGetPath(from_backup, from_backup_path, lengthof(from_backup_path), NULL); pgBackupGetPath(from_backup, from_backup_path, lengthof(from_backup_path), NULL);
pgBackupGetPath(from_backup, from_database_path, lengthof(from_database_path), pgBackupGetPath(from_backup, from_database_path, lengthof(from_database_path),
DATABASE_DIR); DATABASE_DIR);
pgBackupGetPath(from_backup, from_extra_prefix, lengthof(from_database_path), pgBackupGetPath(from_backup, from_external_prefix, lengthof(from_database_path),
EXTRA_DIR); EXTERNAL_DIR);
/* /*
* Get list of files which will be modified or removed. * Get list of files which will be modified or removed.
@ -252,32 +253,32 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
threads = (pthread_t *) palloc(sizeof(pthread_t) * num_threads); threads = (pthread_t *) palloc(sizeof(pthread_t) * num_threads);
threads_args = (merge_files_arg *) palloc(sizeof(merge_files_arg) * num_threads); threads_args = (merge_files_arg *) palloc(sizeof(merge_files_arg) * num_threads);
/* Create extra directories lists */ /* Create external directories lists */
if (to_backup->extra_dir_str) if (to_backup->external_dir_str)
to_extra = make_extra_directory_list(to_backup->extra_dir_str); to_external = make_external_directory_list(to_backup->external_dir_str);
if (from_backup->extra_dir_str) if (from_backup->external_dir_str)
from_extra = make_extra_directory_list(from_backup->extra_dir_str); from_external = make_external_directory_list(from_backup->external_dir_str);
/* /*
* Rename extra directoties in to_backup (if exists) * Rename external directoties in to_backup (if exists)
* according to numeration of extra dirs in from_backup. * according to numeration of external dirs in from_backup.
*/ */
if (to_extra) if (to_external)
reorder_extra_dirs(to_backup, to_extra, from_extra); reorder_external_dirs(to_backup, to_external, from_external);
/* Setup threads */ /* Setup threads */
for (i = 0; i < parray_num(files); i++) for (i = 0; i < parray_num(files); i++)
{ {
pgFile *file = (pgFile *) parray_get(files, i); pgFile *file = (pgFile *) parray_get(files, i);
/* if the entry was an extra directory, create it in the backup */ /* if the entry was an external directory, create it in the backup */
if (file->extra_dir_num && S_ISDIR(file->mode)) if (file->external_dir_num && S_ISDIR(file->mode))
{ {
char dirpath[MAXPGPATH]; char dirpath[MAXPGPATH];
char new_container[MAXPGPATH]; char new_container[MAXPGPATH];
makeExtraDirPathByNum(new_container, to_extra_prefix, makeExternalDirPathByNum(new_container, to_external_prefix,
file->extra_dir_num); file->external_dir_num);
join_path_components(dirpath, new_container, file->path); join_path_components(dirpath, new_container, file->path);
dir_create_dir(dirpath, DIR_PERMISSION); dir_create_dir(dirpath, DIR_PERMISSION);
} }
@ -294,9 +295,9 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
arg->from_backup = from_backup; arg->from_backup = from_backup;
arg->to_root = to_database_path; arg->to_root = to_database_path;
arg->from_root = from_database_path; arg->from_root = from_database_path;
arg->from_extra = from_extra; arg->from_external = from_external;
arg->to_extra_prefix = to_extra_prefix; arg->to_external_prefix = to_external_prefix;
arg->from_extra_prefix = from_extra_prefix; arg->from_external_prefix = from_external_prefix;
/* By default there are some error */ /* By default there are some error */
arg->ret = 1; arg->ret = 1;
@ -325,9 +326,9 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
to_backup->recovery_time = from_backup->recovery_time; to_backup->recovery_time = from_backup->recovery_time;
to_backup->recovery_xid = from_backup->recovery_xid; to_backup->recovery_xid = from_backup->recovery_xid;
pfree(to_backup->extra_dir_str); pfree(to_backup->external_dir_str);
to_backup->extra_dir_str = from_backup->extra_dir_str; to_backup->external_dir_str = from_backup->external_dir_str;
from_backup->extra_dir_str = NULL; /* For safe pgBackupFree() */ from_backup->external_dir_str = NULL; /* For safe pgBackupFree() */
/* /*
* If one of the backups isn't "stream" backup then the target backup become * If one of the backups isn't "stream" backup then the target backup become
* non-stream backup too. * non-stream backup too.
@ -354,7 +355,7 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
to_backup->wal_bytes = BYTES_INVALID; to_backup->wal_bytes = BYTES_INVALID;
write_backup_filelist(to_backup, files, from_database_path, write_backup_filelist(to_backup, files, from_database_path,
from_extra_prefix, NULL); from_external_prefix, NULL);
write_backup(to_backup); write_backup(to_backup);
delete_source_backup: delete_source_backup:
@ -371,10 +372,10 @@ delete_source_backup:
for (i = 0; i < parray_num(to_files); i++) for (i = 0; i < parray_num(to_files); i++)
{ {
pgFile *file = (pgFile *) parray_get(to_files, i); pgFile *file = (pgFile *) parray_get(to_files, i);
char *dir_name = parray_get(to_external, file->external_dir_num - 1);
if (file->extra_dir_num && if (file->external_dir_num &&
backup_contains_extra(parray_get(to_extra, file->extra_dir_num - 1), backup_contains_external(dir_name, from_external))
from_extra))
/* Dir already removed*/ /* Dir already removed*/
continue; continue;
@ -490,11 +491,11 @@ merge_files(void *arg)
} }
/* We need to make full path, file object has relative path */ /* We need to make full path, file object has relative path */
if (file->extra_dir_num) if (file->external_dir_num)
{ {
char temp[MAXPGPATH]; char temp[MAXPGPATH];
makeExtraDirPathByNum(temp, argument->from_extra_prefix, makeExternalDirPathByNum(temp, argument->from_external_prefix,
file->extra_dir_num); file->external_dir_num);
join_path_components(from_file_path, temp, file->path); join_path_components(from_file_path, temp, file->path);
} }
@ -612,21 +613,21 @@ merge_files(void *arg)
} }
else if (strcmp(file->name, "pg_control") == 0) else if (strcmp(file->name, "pg_control") == 0)
copy_pgcontrol_file(argument->from_root, argument->to_root, file); copy_pgcontrol_file(argument->from_root, argument->to_root, file);
else if (file->extra_dir_num) else if (file->external_dir_num)
{ {
char from_root[MAXPGPATH]; char from_root[MAXPGPATH];
char to_root[MAXPGPATH]; char to_root[MAXPGPATH];
int new_dir_num; int new_dir_num;
char *file_extra_path = parray_get(argument->from_extra, char *file_external_path = parray_get(argument->from_external,
file->extra_dir_num - 1); file->external_dir_num - 1);
Assert(argument->from_extra); Assert(argument->from_external);
new_dir_num = get_extra_index(file_extra_path, new_dir_num = get_external_index(file_external_path,
argument->from_extra); argument->from_external);
makeExtraDirPathByNum(from_root, argument->from_extra_prefix, makeExternalDirPathByNum(from_root, argument->from_external_prefix,
file->extra_dir_num); file->external_dir_num);
makeExtraDirPathByNum(to_root, argument->to_extra_prefix, makeExternalDirPathByNum(to_root, argument->to_external_prefix,
new_dir_num); new_dir_num);
copy_file(from_root, to_root, file); copy_file(from_root, to_root, file);
} }
else else
@ -668,9 +669,9 @@ remove_dir_with_files(const char *path)
} }
} }
/* Get index of extra directory */ /* Get index of external directory */
static int static int
get_extra_index(const char *key, const parray *list) get_external_index(const char *key, const parray *list)
{ {
if (!list) /* Nowhere to search */ if (!list) /* Nowhere to search */
return -1; return -1;
@ -682,29 +683,31 @@ get_extra_index(const char *key, const parray *list)
return -1; return -1;
} }
/* Rename directories in to_backup according to order in from_extra */ /* Rename directories in to_backup according to order in from_external */
static void static void
reorder_extra_dirs(pgBackup *to_backup, parray *to_extra, parray *from_extra) reorder_external_dirs(pgBackup *to_backup, parray *to_external,
parray *from_external)
{ {
char extradir_template[MAXPGPATH]; char externaldir_template[MAXPGPATH];
pgBackupGetPath(to_backup, extradir_template, pgBackupGetPath(to_backup, externaldir_template,
lengthof(extradir_template), EXTRA_DIR); lengthof(externaldir_template), EXTERNAL_DIR);
for (int i = 0; i < parray_num(to_extra); i++) for (int i = 0; i < parray_num(to_external); i++)
{ {
int from_num = get_extra_index(parray_get(to_extra, i), from_extra); int from_num = get_external_index(parray_get(to_external, i),
from_external);
if (from_num == -1) if (from_num == -1)
{ {
char old_path[MAXPGPATH]; char old_path[MAXPGPATH];
makeExtraDirPathByNum(old_path, extradir_template, i + 1); makeExternalDirPathByNum(old_path, externaldir_template, i + 1);
remove_dir_with_files(old_path); remove_dir_with_files(old_path);
} }
else if (from_num != i + 1) else if (from_num != i + 1)
{ {
char old_path[MAXPGPATH]; char old_path[MAXPGPATH];
char new_path[MAXPGPATH]; char new_path[MAXPGPATH];
makeExtraDirPathByNum(old_path, extradir_template, i + 1); makeExternalDirPathByNum(old_path, externaldir_template, i + 1);
makeExtraDirPathByNum(new_path, extradir_template, from_num); makeExternalDirPathByNum(new_path, externaldir_template, from_num);
elog(VERBOSE, "Rename %s to %s", old_path, new_path); elog(VERBOSE, "Rename %s to %s", old_path, new_path);
if (rename (old_path, new_path) == -1) if (rename (old_path, new_path) == -1)
elog(ERROR, "Could not rename directory \"%s\" to \"%s\": %s", elog(ERROR, "Could not rename directory \"%s\" to \"%s\": %s",

View File

@ -54,8 +54,8 @@ char backup_instance_path[MAXPGPATH];
*/ */
char arclog_path[MAXPGPATH] = ""; char arclog_path[MAXPGPATH] = "";
/* colon separated extra directories list ("/path1:/path2") */ /* colon separated external directories list ("/path1:/path2") */
char *extradir = NULL; char *externaldir = NULL;
/* common options */ /* common options */
static char *backup_id_string = NULL; static char *backup_id_string = NULL;
int num_threads = 1; int num_threads = 1;
@ -145,7 +145,7 @@ static ConfigOption cmd_options[] =
{ 's', 138, "inclusive", &target_inclusive, SOURCE_CMD_STRICT }, { 's', 138, "inclusive", &target_inclusive, SOURCE_CMD_STRICT },
{ 'u', 139, "timeline", &target_tli, SOURCE_CMD_STRICT }, { 'u', 139, "timeline", &target_tli, SOURCE_CMD_STRICT },
{ 'f', 'T', "tablespace-mapping", opt_tablespace_map, SOURCE_CMD_STRICT }, { 'f', 'T', "tablespace-mapping", opt_tablespace_map, SOURCE_CMD_STRICT },
{ 'f', 155, "extra-mapping", opt_extradir_map, SOURCE_CMD_STRICT }, { 'f', 155, "external-mapping", opt_externaldir_map, SOURCE_CMD_STRICT },
{ 'b', 140, "immediate", &target_immediate, SOURCE_CMD_STRICT }, { 'b', 140, "immediate", &target_immediate, SOURCE_CMD_STRICT },
{ 's', 141, "recovery-target-name", &target_name, SOURCE_CMD_STRICT }, { 's', 141, "recovery-target-name", &target_name, SOURCE_CMD_STRICT },
{ 's', 142, "recovery-target-action", &target_action, SOURCE_CMD_STRICT }, { 's', 142, "recovery-target-action", &target_action, SOURCE_CMD_STRICT },

View File

@ -48,7 +48,7 @@
#define PG_BACKUP_LABEL_FILE "backup_label" #define PG_BACKUP_LABEL_FILE "backup_label"
#define PG_BLACK_LIST "black_list" #define PG_BLACK_LIST "black_list"
#define PG_TABLESPACE_MAP_FILE "tablespace_map" #define PG_TABLESPACE_MAP_FILE "tablespace_map"
#define EXTRA_DIR "extra_directories/extradir" #define EXTERNAL_DIR "external_directories/externaldir"
/* Timeout defaults */ /* Timeout defaults */
#define ARCHIVE_TIMEOUT_DEFAULT 300 #define ARCHIVE_TIMEOUT_DEFAULT 300
@ -122,7 +122,7 @@ typedef struct pgFile
int n_blocks; /* size of the file in blocks, readed during DELTA backup */ int n_blocks; /* size of the file in blocks, readed during DELTA backup */
bool is_cfs; /* Flag to distinguish files compressed by CFS*/ bool is_cfs; /* Flag to distinguish files compressed by CFS*/
bool is_database; bool is_database;
int extra_dir_num; /* Number of extra directory. 0 if not extra */ int external_dir_num; /* Number of external directory. 0 if not external */
bool exists_in_prev; /* Mark files, both data and regular, that exists in previous backup */ bool exists_in_prev; /* Mark files, both data and regular, that exists in previous backup */
CompressAlg compress_alg; /* compression algorithm applied to the file */ CompressAlg compress_alg; /* compression algorithm applied to the file */
volatile pg_atomic_flag lock; /* lock for synchronization of parallel threads */ volatile pg_atomic_flag lock; /* lock for synchronization of parallel threads */
@ -180,7 +180,7 @@ typedef struct InstanceConfig
uint32 xlog_seg_size; uint32 xlog_seg_size;
char *pgdata; char *pgdata;
char *extra_dir_str; char *external_dir_str;
const char *pgdatabase; const char *pgdatabase;
const char *pghost; const char *pghost;
const char *pgport; const char *pgport;
@ -261,7 +261,8 @@ struct pgBackup
pgBackup *parent_backup_link; pgBackup *parent_backup_link;
char *primary_conninfo; /* Connection parameters of the backup char *primary_conninfo; /* Connection parameters of the backup
* in the format suitable for recovery.conf */ * in the format suitable for recovery.conf */
char *extra_dir_str; /* List of extra directories, separated by ':' */ char *external_dir_str; /* List of external directories,
* separated by ':' */
}; };
/* Recovery target for restore and validate subcommands */ /* Recovery target for restore and validate subcommands */
@ -292,11 +293,11 @@ typedef struct
{ {
const char *from_root; const char *from_root;
const char *to_root; const char *to_root;
const char *extra_prefix; const char *external_prefix;
parray *files_list; parray *files_list;
parray *prev_filelist; parray *prev_filelist;
parray *extra_dirs; parray *external_dirs;
XLogRecPtr prev_start_lsn; XLogRecPtr prev_start_lsn;
PGconn *backup_conn; PGconn *backup_conn;
@ -474,8 +475,8 @@ extern pgBackup *catalog_get_last_data_backup(parray *backup_list,
extern void catalog_lock(void); extern void catalog_lock(void);
extern void pgBackupWriteControl(FILE *out, pgBackup *backup); extern void pgBackupWriteControl(FILE *out, pgBackup *backup);
extern void write_backup_filelist(pgBackup *backup, parray *files, extern void write_backup_filelist(pgBackup *backup, parray *files,
const char *root, const char *extra_prefix, const char *root, const char *external_prefix,
parray *extra_list); parray *external_list);
extern void pgBackupGetPath(const pgBackup *backup, char *path, size_t len, extern void pgBackupGetPath(const pgBackup *backup, char *path, size_t len,
const char *subdir); const char *subdir);
@ -500,26 +501,27 @@ extern const char* deparse_compress_alg(int alg);
/* in dir.c */ /* in dir.c */
extern void dir_list_file(parray *files, const char *root, bool exclude, extern void dir_list_file(parray *files, const char *root, bool exclude,
bool omit_symlink, bool add_root, int extra_dir_num); bool omit_symlink, bool add_root, int external_dir_num);
extern void create_data_directories(const char *data_dir, extern void create_data_directories(const char *data_dir,
const char *backup_dir, const char *backup_dir,
bool extract_tablespaces); bool extract_tablespaces);
extern void read_tablespace_map(parray *files, const char *backup_dir); extern void read_tablespace_map(parray *files, const char *backup_dir);
extern void opt_tablespace_map(ConfigOption *opt, const char *arg); extern void opt_tablespace_map(ConfigOption *opt, const char *arg);
extern void opt_extradir_map(ConfigOption *opt, const char *arg); extern void opt_externaldir_map(ConfigOption *opt, const char *arg);
extern void check_tablespace_mapping(pgBackup *backup); extern void check_tablespace_mapping(pgBackup *backup);
extern void check_extra_dir_mapping(pgBackup *backup); extern void check_external_dir_mapping(pgBackup *backup);
extern char *get_extra_remap(char *current_dir); extern char *get_external_remap(char *current_dir);
extern void print_file_list(FILE *out, const parray *files, const char *root, extern void print_file_list(FILE *out, const parray *files, const char *root,
const char *extra_prefix, parray *extra_list); const char *external_prefix, parray *external_list);
extern parray *dir_read_file_list(const char *root, const char *extra_prefix, const char *file_txt); extern parray *dir_read_file_list(const char *root, const char *external_prefix,
extern parray *make_extra_directory_list(const char *colon_separated_dirs); const char *file_txt);
extern parray *make_external_directory_list(const char *colon_separated_dirs);
extern void free_dir_list(parray *list); extern void free_dir_list(parray *list);
extern void makeExtraDirPathByNum(char *ret_path, const char *pattern_path, extern void makeExternalDirPathByNum(char *ret_path, const char *pattern_path,
const int dir_num); const int dir_num);
extern bool backup_contains_extra(const char *dir, parray *dirs_list); extern bool backup_contains_external(const char *dir, parray *dirs_list);
extern int dir_create_dir(const char *path, mode_t mode); extern int dir_create_dir(const char *path, mode_t mode);
extern bool dir_is_empty(const char *path); extern bool dir_is_empty(const char *path);
@ -527,14 +529,14 @@ extern bool dir_is_empty(const char *path);
extern bool fileExists(const char *path); extern bool fileExists(const char *path);
extern size_t pgFileSize(const char *path); extern size_t pgFileSize(const char *path);
extern pgFile *pgFileNew(const char *path, bool omit_symlink, int extra_dir_num); extern pgFile *pgFileNew(const char *path, bool omit_symlink, int external_dir_num);
extern pgFile *pgFileInit(const char *path); extern pgFile *pgFileInit(const char *path);
extern void pgFileDelete(pgFile *file); extern void pgFileDelete(pgFile *file);
extern void pgFileFree(void *file); extern void pgFileFree(void *file);
extern pg_crc32 pgFileGetCRC(const char *file_path, bool use_crc32c, extern pg_crc32 pgFileGetCRC(const char *file_path, bool use_crc32c,
bool raise_on_deleted, size_t *bytes_read); bool raise_on_deleted, size_t *bytes_read);
extern int pgFileComparePath(const void *f1, const void *f2); extern int pgFileComparePath(const void *f1, const void *f2);
extern int pgFileComparePathWithExtra(const void *f1, const void *f2); extern int pgFileComparePathWithExternal(const void *f1, const void *f2);
extern int pgFileComparePathDesc(const void *f1, const void *f2); extern int pgFileComparePathDesc(const void *f1, const void *f2);
extern int pgFileCompareLinked(const void *f1, const void *f2); extern int pgFileCompareLinked(const void *f1, const void *f2);
extern int pgFileCompareSize(const void *f1, const void *f2); extern int pgFileCompareSize(const void *f1, const void *f2);

View File

@ -21,9 +21,9 @@ typedef struct
{ {
parray *files; parray *files;
pgBackup *backup; pgBackup *backup;
parray *req_extra_dirs; parray *req_external_dirs;
parray *cur_extra_dirs; parray *cur_external_dirs;
char *extra_prefix; char *external_prefix;
/* /*
* Return value from the thread. * Return value from the thread.
@ -32,7 +32,7 @@ typedef struct
int ret; int ret;
} restore_files_arg; } restore_files_arg;
static void restore_backup(pgBackup *backup, const char *extra_dir_str); static void restore_backup(pgBackup *backup, const char *external_dir_str);
static void create_recovery_conf(time_t backup_id, static void create_recovery_conf(time_t backup_id,
pgRecoveryTarget *rt, pgRecoveryTarget *rt,
pgBackup *backup); pgBackup *backup);
@ -287,7 +287,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
if (is_restore) if (is_restore)
{ {
check_tablespace_mapping(dest_backup); check_tablespace_mapping(dest_backup);
check_extra_dir_mapping(dest_backup); check_external_dir_mapping(dest_backup);
} }
if (!is_restore || !rt->restore_no_validate) if (!is_restore || !rt->restore_no_validate)
@ -393,7 +393,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
elog(ERROR, "Backup %s was created for version %s which doesn't support recovery_target_lsn", elog(ERROR, "Backup %s was created for version %s which doesn't support recovery_target_lsn",
base36enc(dest_backup->start_time), dest_backup->server_version); base36enc(dest_backup->start_time), dest_backup->server_version);
restore_backup(backup, dest_backup->extra_dir_str); restore_backup(backup, dest_backup->external_dir_str);
} }
/* /*
@ -420,16 +420,16 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
* Restore one backup. * Restore one backup.
*/ */
void void
restore_backup(pgBackup *backup, const char *extra_dir_str) restore_backup(pgBackup *backup, const char *external_dir_str)
{ {
char timestamp[100]; char timestamp[100];
char this_backup_path[MAXPGPATH]; char this_backup_path[MAXPGPATH];
char database_path[MAXPGPATH]; char database_path[MAXPGPATH];
char extra_prefix[MAXPGPATH]; char external_prefix[MAXPGPATH];
char list_path[MAXPGPATH]; char list_path[MAXPGPATH];
parray *files; parray *files;
parray *requested_extra_dirs = NULL; parray *requested_external_dirs = NULL;
parray *current_extra_dirs = NULL; parray *current_external_dirs = NULL;
int i; int i;
/* arrays with meta info for multi threaded backup */ /* arrays with meta info for multi threaded backup */
pthread_t *threads; pthread_t *threads;
@ -461,61 +461,63 @@ restore_backup(pgBackup *backup, const char *extra_dir_str)
pgBackupGetPath(backup, this_backup_path, lengthof(this_backup_path), NULL); pgBackupGetPath(backup, this_backup_path, lengthof(this_backup_path), NULL);
create_data_directories(instance_config.pgdata, this_backup_path, true); create_data_directories(instance_config.pgdata, this_backup_path, true);
if(extra_dir_str) if(external_dir_str)
{ {
requested_extra_dirs = make_extra_directory_list(extra_dir_str); requested_external_dirs = make_external_directory_list(external_dir_str);
for (i = 0; i < parray_num(requested_extra_dirs); i++) for (i = 0; i < parray_num(requested_external_dirs); i++)
{ {
char *extra_path = parray_get(requested_extra_dirs, i); char *external_path = parray_get(requested_external_dirs, i);
extra_path = get_extra_remap(extra_path); external_path = get_external_remap(external_path);
dir_create_dir(extra_path, DIR_PERMISSION); dir_create_dir(external_path, DIR_PERMISSION);
} }
} }
if(backup->extra_dir_str) if(backup->external_dir_str)
current_extra_dirs = make_extra_directory_list(backup->extra_dir_str); current_external_dirs = make_external_directory_list(backup->external_dir_str);
/* /*
* Get list of files which need to be restored. * Get list of files which need to be restored.
*/ */
pgBackupGetPath(backup, database_path, lengthof(database_path), DATABASE_DIR); pgBackupGetPath(backup, database_path, lengthof(database_path), DATABASE_DIR);
pgBackupGetPath(backup, extra_prefix, lengthof(extra_prefix), EXTRA_DIR); pgBackupGetPath(backup, external_prefix, lengthof(external_prefix),
EXTERNAL_DIR);
pgBackupGetPath(backup, list_path, lengthof(list_path), DATABASE_FILE_LIST); pgBackupGetPath(backup, list_path, lengthof(list_path), DATABASE_FILE_LIST);
files = dir_read_file_list(database_path, extra_prefix, list_path); files = dir_read_file_list(database_path, external_prefix, list_path);
/* Restore directories in do_backup_instance way */ /* Restore directories in do_backup_instance way */
parray_qsort(files, pgFileComparePath); parray_qsort(files, pgFileComparePath);
/* /*
* Make extra directories before restore * Make external directories before restore
* and setup threads at the same time * and setup threads at the same time
*/ */
for (i = 0; i < parray_num(files); i++) for (i = 0; i < parray_num(files); i++)
{ {
pgFile *file = (pgFile *) parray_get(files, i); pgFile *file = (pgFile *) parray_get(files, i);
/* if the entry was an extra directory, create it in the backup */ /* if the entry was an external directory, create it in the backup */
if (file->extra_dir_num && S_ISDIR(file->mode)) if (file->external_dir_num && S_ISDIR(file->mode))
{ {
char dirpath[MAXPGPATH]; char dirpath[MAXPGPATH];
char *dir_name; char *dir_name;
char *extra_path; char *external_path;
if (!current_extra_dirs || if (!current_external_dirs ||
parray_num(current_extra_dirs) < file->extra_dir_num - 1) parray_num(current_external_dirs) < file->external_dir_num - 1)
elog(ERROR, "Inconsistent extra directory backup metadata"); elog(ERROR, "Inconsistent external directory backup metadata");
extra_path = parray_get(current_extra_dirs, file->extra_dir_num - 1); external_path = parray_get(current_external_dirs,
if (backup_contains_extra(extra_path, requested_extra_dirs)) file->external_dir_num - 1);
if (backup_contains_external(external_path, requested_external_dirs))
{ {
char container_dir[MAXPGPATH]; char container_dir[MAXPGPATH];
extra_path = get_extra_remap(extra_path); external_path = get_external_remap(external_path);
makeExtraDirPathByNum(container_dir, extra_prefix, makeExternalDirPathByNum(container_dir, external_prefix,
file->extra_dir_num); file->external_dir_num);
dir_name = GetRelativePath(file->path, container_dir); dir_name = GetRelativePath(file->path, container_dir);
elog(VERBOSE, "Create directory \"%s\"", dir_name); elog(VERBOSE, "Create directory \"%s\"", dir_name);
join_path_components(dirpath, extra_path, dir_name); join_path_components(dirpath, external_path, dir_name);
dir_create_dir(dirpath, DIR_PERMISSION); dir_create_dir(dirpath, DIR_PERMISSION);
} }
} }
@ -533,9 +535,9 @@ restore_backup(pgBackup *backup, const char *extra_dir_str)
arg->files = files; arg->files = files;
arg->backup = backup; arg->backup = backup;
arg->req_extra_dirs = requested_extra_dirs; arg->req_external_dirs = requested_external_dirs;
arg->cur_extra_dirs = current_extra_dirs; arg->cur_external_dirs = current_external_dirs;
arg->extra_prefix = extra_prefix; arg->external_prefix = external_prefix;
/* By default there are some error */ /* By default there are some error */
threads_args[i].ret = 1; threads_args[i].ret = 1;
@ -578,13 +580,13 @@ remove_deleted_files(pgBackup *backup)
parray *files; parray *files;
parray *files_restored; parray *files_restored;
char filelist_path[MAXPGPATH]; char filelist_path[MAXPGPATH];
char extra_prefix[MAXPGPATH]; char external_prefix[MAXPGPATH];
int i; int i;
pgBackupGetPath(backup, filelist_path, lengthof(filelist_path), DATABASE_FILE_LIST); pgBackupGetPath(backup, filelist_path, lengthof(filelist_path), DATABASE_FILE_LIST);
pgBackupGetPath(backup, extra_prefix, lengthof(extra_prefix), EXTRA_DIR); pgBackupGetPath(backup, external_prefix, lengthof(external_prefix), EXTERNAL_DIR);
/* Read backup's filelist using target database path as base path */ /* Read backup's filelist using target database path as base path */
files = dir_read_file_list(instance_config.pgdata, extra_prefix, filelist_path); files = dir_read_file_list(instance_config.pgdata, external_prefix, filelist_path);
parray_qsort(files, pgFileComparePathDesc); parray_qsort(files, pgFileComparePathDesc);
/* Get list of files actually existing in target database */ /* Get list of files actually existing in target database */
@ -693,14 +695,15 @@ restore_files(void *arg)
false, false,
parse_program_version(arguments->backup->program_version)); parse_program_version(arguments->backup->program_version));
} }
else if (file->extra_dir_num) else if (file->external_dir_num)
{ {
char *extra_path = parray_get(arguments->cur_extra_dirs, char *external_path = parray_get(arguments->cur_external_dirs,
file->extra_dir_num - 1); file->external_dir_num - 1);
if (backup_contains_extra(extra_path, arguments->req_extra_dirs)) if (backup_contains_external(external_path,
arguments->req_external_dirs))
{ {
extra_path = get_extra_remap(extra_path); external_path = get_external_remap(external_path);
copy_file(arguments->extra_prefix, extra_path, file); copy_file(arguments->external_prefix, external_path, file);
} }
} }
else if (strcmp(file->name, "pg_control") == 0) else if (strcmp(file->name, "pg_control") == 0)

View File

@ -43,7 +43,7 @@ void
pgBackupValidate(pgBackup *backup) pgBackupValidate(pgBackup *backup)
{ {
char base_path[MAXPGPATH]; char base_path[MAXPGPATH];
char extra_prefix[MAXPGPATH]; char external_prefix[MAXPGPATH];
char path[MAXPGPATH]; char path[MAXPGPATH];
parray *files; parray *files;
bool corrupted = false; bool corrupted = false;
@ -90,9 +90,9 @@ pgBackupValidate(pgBackup *backup)
elog(WARNING, "Invalid backup_mode of backup %s", base36enc(backup->start_time)); elog(WARNING, "Invalid backup_mode of backup %s", base36enc(backup->start_time));
pgBackupGetPath(backup, base_path, lengthof(base_path), DATABASE_DIR); pgBackupGetPath(backup, base_path, lengthof(base_path), DATABASE_DIR);
pgBackupGetPath(backup, extra_prefix, lengthof(extra_prefix), EXTRA_DIR); pgBackupGetPath(backup, external_prefix, lengthof(external_prefix), EXTERNAL_DIR);
pgBackupGetPath(backup, path, lengthof(path), DATABASE_FILE_LIST); pgBackupGetPath(backup, path, lengthof(path), DATABASE_FILE_LIST);
files = dir_read_file_list(base_path, extra_prefix, path); files = dir_read_file_list(base_path, external_prefix, path);
/* setup threads */ /* setup threads */
for (i = 0; i < parray_num(files); i++) for (i = 0; i < parray_num(files); i++)
@ -240,7 +240,7 @@ pgBackupValidateFiles(void *arg)
*/ */
if (arguments->backup_version >= 20025 && if (arguments->backup_version >= 20025 &&
strcmp(file->name, "pg_control") == 0 && strcmp(file->name, "pg_control") == 0 &&
!file->extra_dir_num) !file->external_dir_num)
crc = get_pgcontrol_checksum(arguments->base_path); crc = get_pgcontrol_checksum(arguments->base_path);
else else
crc = pgFileGetCRC(file->path, crc = pgFileGetCRC(file->path,

View File

@ -29,13 +29,13 @@ class ExternalTest(ProbackupTest, unittest.TestCase):
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup') backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
external_dir = os.path.join(node.base_dir, 'somedirectory') external_dir = os.path.join(node.base_dir, 'somedirectory')
# copy postgresql.conf to extra_directory # copy postgresql.conf to external_directory
os.mkdir(external_dir) os.mkdir(external_dir)
shutil.copyfile( shutil.copyfile(
os.path.join(node.data_dir, 'postgresql.conf'), os.path.join(node.data_dir, 'postgresql.conf'),
os.path.join(external_dir, 'postgresql.conf')) os.path.join(external_dir, 'postgresql.conf'))
# create directory in extra_directory # create directory in external_directory
self.init_pb(backup_dir) self.init_pb(backup_dir)
self.add_instance(backup_dir, 'node', node) self.add_instance(backup_dir, 'node', node)
self.set_archiving(backup_dir, 'node', node) self.set_archiving(backup_dir, 'node', node)
@ -44,7 +44,7 @@ class ExternalTest(ProbackupTest, unittest.TestCase):
backup_id = self.backup_node( backup_id = self.backup_node(
backup_dir, 'node', node, backup_dir, 'node', node,
options=[ options=[
'--extra-directory={0}'.format(external_dir)]) '--external-dirs={0}'.format(external_dir)])
if self.paranoia: if self.paranoia:
pgdata = self.pgdata_content( pgdata = self.pgdata_content(
@ -93,7 +93,7 @@ class ExternalTest(ProbackupTest, unittest.TestCase):
external_dir1_old = self.get_tblspace_path(node, 'external_dir1') external_dir1_old = self.get_tblspace_path(node, 'external_dir1')
external_dir2_old = self.get_tblspace_path(node, 'external_dir2') external_dir2_old = self.get_tblspace_path(node, 'external_dir2')
# copy postgresql.conf to extra_directory # copy postgresql.conf to external_directory
os.mkdir(external_dir1_old) os.mkdir(external_dir1_old)
os.mkdir(external_dir2_old) os.mkdir(external_dir2_old)
shutil.copyfile( shutil.copyfile(
@ -115,9 +115,9 @@ class ExternalTest(ProbackupTest, unittest.TestCase):
backup_dir, 'node', node_restored, backup_dir, 'node', node_restored,
options=[ options=[
"-j", "4", "-j", "4",
"--extra-mapping={0}={1}".format( "--external-mapping={0}={1}".format(
external_dir1_old, external_dir1_new), external_dir1_old, external_dir1_new),
"--extra-mapping={0}={1}".format( "--external-mapping={0}={1}".format(
external_dir2_old, external_dir2_new)]) external_dir2_old, external_dir2_new)])
# we should die here because exception is what we expect to happen # we should die here because exception is what we expect to happen
self.assertEqual( self.assertEqual(
@ -127,8 +127,8 @@ class ExternalTest(ProbackupTest, unittest.TestCase):
repr(self.output), self.cmd)) repr(self.output), self.cmd))
except ProbackupException as e: except ProbackupException as e:
self.assertTrue( self.assertTrue(
'ERROR: --extra-mapping option' in e.message and 'ERROR: --external-mapping option' in e.message and
'have an entry in list of extra directories' in e.message, 'have an entry in list of external directories' in e.message,
'\n Unexpected Error Message: {0}\n CMD: {1}'.format( '\n Unexpected Error Message: {0}\n CMD: {1}'.format(
repr(e.message), self.cmd)) repr(e.message), self.cmd))
@ -142,9 +142,9 @@ class ExternalTest(ProbackupTest, unittest.TestCase):
backup_dir, 'node', node_restored, backup_dir, 'node', node_restored,
options=[ options=[
"-j", "4", "-j", "4",
"--extra-mapping={0}={1}".format( "--external-mapping={0}={1}".format(
external_dir1_old, external_dir1_new), external_dir1_old, external_dir1_new),
"--extra-mapping={0}={1}".format( "--external-mapping={0}={1}".format(
external_dir2_old, external_dir2_new)]) external_dir2_old, external_dir2_new)])
if self.paranoia: if self.paranoia:
@ -223,14 +223,14 @@ class ExternalTest(ProbackupTest, unittest.TestCase):
# Clean after yourself # Clean after yourself
self.del_test_dir(module_name, fname) self.del_test_dir(module_name, fname)
# extra directory contain symlink to file # external directory contain symlink to file
# extra directory contain symlink to directory # external directory contain symlink to directory
# latest page backup without extra_dir # latest page backup without external_dir
# multiple external directories # multiple external directories
# --extra-directory=none # --external-dirs=none
# --extra-directory point to a file # --external-dirs point to a file
# extra directory in config and in command line # external directory in config and in command line
# extra directory contain multuple directories, some of them my be empty # external directory contain multuple directories, some of them my be empty
# forbid to external-dirs to point to tablespace directories # forbid to external-dirs to point to tablespace directories
# check that not changed files are not copied by next backup # check that not changed files are not copied by next backup
# merge # merge