8000 [PBCKP-153] Added waldir option for location for the write-ahead log … · postgrespro/pg_probackup@4185570 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4185570

Browse files
committed
[PBCKP-153] Added waldir option for location for the write-ahead log directory (-X, --waldir=WALDIR)
1 parent 8bb0a61 commit 4185570

File tree

6 files changed

+58
-4
lines changed

6 files changed

+58
-4
lines changed

src/dir.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,13 +1036,20 @@ opt_externaldir_map(ConfigOption *opt, const char *arg)
10361036
*/
10371037
void
10381038
create_data_directories(parray *dest_files, const char *data_dir, const char *backup_dir,
1039-
bool extract_tablespaces, bool incremental, fio_location location)
1039+
bool extract_tablespaces, bool incremental, fio_location location,
1040+
const char* waldir_path)
10401041
{
10411042
int i;
10421043
parray *links = NULL;
10431044
mode_t pg_tablespace_mode = DIR_PERMISSION;
10441045
char to_path[MAXPGPATH];
10451046

1047+
if (waldir_path && !dir_is_empty(waldir_path, location))
1048+
{
1049+
elog(ERROR, "WAL directory location is not empty: \"%s\"", waldir_path);
1050+
}
1051+
1052+
10461053
/* get tablespace map */
10471054
if (extract_tablespaces)
10481055
{
@@ -1107,6 +1114,27 @@ create_data_directories(parray *dest_files, const char *data_dir, const char *ba
11071114
/* skip external directory content */
11081115
if (dir->external_dir_num != 0)
11091116
continue;
1117+
/* Create WAL directory and symlink if waldir_path is setting */
1118+
if (waldir_path && strcmp(dir->rel_path, PG_XLOG_DIR) == 0) {
1119+
/* get full path to PG_XLOG_DIR */
1120+
1121+
join_path_components(to_path, data_dir, PG_XLOG_DIR);
1122+
1123+
elog(VERBOSE, "Create directory \"%s\" and symbolic link \"%s\"",
1124+
waldir_path, to_path);
1125+
1126+
/* create tablespace directory from waldir_path*/
1127+
fio_mkdir(waldir_path, pg_tablespace_mode, location);
1128+
1129+
/* create link to linked_path */
1130+
if (fio_symlink(waldir_path, to_path, incremental, location) < 0)
1131+
elog(ERROR, "Could not create symbolic link \"%s\": %s",
1132+
to_path, strerror(errno));
1133+
1134+
continue;
1135+
1136+
1137+
}
11101138

11111139
/* tablespace_map exists */
11121140
if (links)

src/help.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ help_pg_probackup(void)
169169
printf(_(" [-T OLDDIR=NEWDIR] [--progress]\n"));
170170
printf(_(" [--external-mapping=OLDDIR=NEWDIR]\n"));
171171
printf(_(" [--skip-external-dirs] [--no-sync]\n"));
172+
printf(_(" [-X WALDIR | --waldir=WALDIR]\n"));
172173
printf(_(" [-I | --incremental-mode=none|checksum|lsn]\n"));
173174
printf(_(" [--db-include | --db-exclude]\n"));
174175
printf(_(" [--remote-proto] [--remote-host]\n"));
@@ -435,6 +436,7 @@ help_restore(void)
435436
printf(_(" [-T OLDDIR=NEWDIR]\n"));
436437
printf(_(" [--external-mapping=OLDDIR=NEWDIR]\n"));
437438
printf(_(" [--skip-external-dirs]\n"));
439+
printf(_(" [-X WALDIR | --waldir=WALDIR]\n"));
438440
printf(_(" [-I | --incremental-mode=none|checksum|lsn]\n"));
439441
printf(_(" [--db-include dbname | --db-exclude dbname]\n"));
440442
printf(_(" [--recovery-target-time=time|--recovery-target-xid=xid\n"));
@@ -472,6 +474,10 @@ help_restore(void)
472474
printf(_(" relocate the external directory from OLDDIR to NEWDIR\n"));
473475
printf(_(" --skip-external-dirs do not restore all external directories\n"));
474476

477+
478+
printf(_(" -X, --waldir=WALDIR location for the write-ahead log directory\n"));
479+
480+
475481
printf(_("\n Incremental restore options:\n"));
476482
printf(_(" -I, --incremental-mode=none|checksum|lsn\n"));
477483
printf(_(" reuse valid pages available in PGDATA if they have not changed\n"));

src/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ merge_chain(InstanceState *instanceState,
614614

615615
/* Create directories */
616616
create_data_directories(dest_backup->files, full_database_dir,
617-
dest_backup->root_dir, false, false, FIO_BACKUP_HOST);
617+
dest_backup->root_dir, false, false, FIO_BACKUP_HOST, NULL);
618618

619619
/* External directories stuff */
620620
if (dest_backup->external_dir_str)

src/pg_probackup.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ static parray *datname_include_list = NULL;
122122
/* arrays for --exclude-path's */
123123
static parray *exclude_absolute_paths_list = NULL;
124124
static parray *exclude_relative_paths_list = NULL;
125+
static char* waldir_path = NULL;
125126

126127
/* checkdb options */
127128
bool need_amcheck = false;
@@ -238,6 +239,7 @@ static ConfigOption cmd_options[] =
238239
{ 's', 160, "primary-conninfo", &primary_conninfo, SOURCE_CMD_STRICT },
239240
{ 's', 'S', "primary-slot-name",&replication_slot, SOURCE_CMD_STRICT },
240241
{ 'f', 'I', "incremental-mode", opt_incr_restore_mode, SOURCE_CMD_STRICT },
242+
{ 's', 'X', "waldir", &waldir_path, SOURCE_CMD_STRICT },
241243
/* checkdb options */
242244
{ 'b', 195, "amcheck", &need_amcheck, SOURCE_CMD_STRICT },
243245
{ 'b', 196, "heapallindexed", &heapallindexed, SOURCE_CMD_STRICT },
@@ -754,6 +756,21 @@ main(int argc, char *argv[])
754756
restore_params->partial_restore_type = INCLUDE;
755757
restore_params->partial_db_list = datname_include_list;
756758
}
759+
760+
if (waldir_path)
761+
{
762+
/* clean up xlog directory name, check it's absolute */
763+
canonicalize_path(waldir_path);
764+
if (!is_absolute_path(waldir_path))
765+
{
766+
elog(ERROR, "WAL directory location must be an absolute path");
767+
}
768+
if (strlen(waldir_path) > MAXPGPATH)
769+
elog(ERROR, "Value specified to --waldir is too long");
770+
771+
}
772+
restore_params->waldir = waldir_path;
773+
757774
}
758775

759776
/*

src/pg_probackup.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,8 @@ typedef struct pgRestoreParams
566566
/* options for partial restore */
567567
PartialRestoreType partial_restore_type;
568568
parray *partial_db_list;
569+
570+
char* waldir;
569571
} pgRestoreParams;
570572

571573
/* Options needed for set-backup command */
@@ -1022,7 +1024,8 @@ extern void create_data_directories(parray *dest_files,
10221024
const char *backup_dir,
10231025
bool extract_tablespaces,
10241026
bool incremental,
1025-
fio_location location);
1027+
fio_location location,
1028+
const char *waldir_path);
10261029

10271030
extern void read_tablespace_map(parray *links, const char *backup_dir);
10281031
extern void opt_tablespace_map(ConfigOption *opt, const char *arg);

src/restore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ restore_chain(pgBackup *dest_backup, parray *parent_chain,
801801
create_data_directories(dest_files, instance_config.pgdata,
802802
dest_backup->root_dir, backup_has_tblspc,
803803
params->incremental_mode != INCR_NONE,
804-
FIO_DB_HOST);
804+
FIO_DB_HOST, params->waldir);
805805

806806
/*
807807
* Restore dest_backup external directories.

0 commit comments

Comments
 (0)
0