Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7591667

Browse files
committed
Merge branch 'release_2_5_7' into REL_2_5
2 parents 2f19f6d + 9cd25f2 commit 7591667

File tree

9 files changed

+116
-4
lines changed

9 files changed

+116
-4
lines changed

src/dir.c

+29-1
Original file line numberDiff line numberDiff line change
@@ -1040,13 +1040,20 @@ opt_externaldir_map(ConfigOption *opt, const char *arg)
10401040
*/
10411041
void
10421042
create_data_directories(parray *dest_files, const char *data_dir, const char *backup_dir,
1043-
bool extract_tablespaces, bool incremental, fio_location location)
1043+
bool extract_tablespaces, bool incremental, fio_location location,
1044+
const char* waldir_path)
10441045
{
10451046
int i;
10461047
parray *links = NULL;
10471048
mode_t pg_tablespace_mode = DIR_PERMISSION;
10481049
char to_path[MAXPGPATH];
10491050

1051+
if (waldir_path && !dir_is_empty(waldir_path, location))
1052+
{
1053+
elog(ERROR, "WAL directory location is not empty: \"%s\"", waldir_path);
1054+
}
1055+
1056+
10501057
/* get tablespace map */
10511058
if (extract_tablespaces)
10521059
{
@@ -1111,6 +1118,27 @@ create_data_directories(parray *dest_files, const char *data_dir, const char *ba
11111118
/* skip external directory content */
11121119
if (dir->external_dir_num != 0)
11131120
continue;
1121+
/* Create WAL directory and symlink if waldir_path is setting */
1122+
if (waldir_path && strcmp(dir->rel_path, PG_XLOG_DIR) == 0) {
1123+
/* get full path to PG_XLOG_DIR */
1124+
1125+
join_path_components(to_path, data_dir, PG_XLOG_DIR);
1126+
1127+
elog(VERBOSE, "Create directory \"%s\" and symbolic link \"%s\"",
1128+
waldir_path, to_path);
1129+
1130+
/* create tablespace directory from waldir_path*/
1131+
fio_mkdir(waldir_path, pg_tablespace_mode, location);
1132+
1133+
/* create link to linked_path */
1134+
if (fio_symlink(waldir_path, to_path, incremental, location) < 0)
1135+
elog(ERROR, "Could not create symbolic link \"%s\": %s",
1136+
to_path, strerror(errno));
1137+
1138+
continue;
1139+
1140+
1141+
}
11141142

11151143
/* tablespace_map exists */
11161144
if (links)

src/help.c

+6
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

+1-1
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

+17
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* gl_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", &gl_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 (gl_waldir_path)
761+
{
762+
/* clean up xlog directory name, check it's absolute */
763+
canonicalize_path(gl_waldir_path);
764+
if (!is_absolute_path(gl_waldir_path))
765+
{
766+
elog(ERROR, "WAL directory location must be an absolute path");
767+
}
768+
if (strlen(gl_waldir_path) > MAXPGPATH)
769+
elog(ERROR, "Value specified to --waldir is too long");
770+
771+
}
772+
restore_params->waldir = gl_waldir_path;
773+
757774
}
758775

759776
/*

src/pg_probackup.h

+4-1
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 */
@@ -1023,7 +1025,8 @@ extern void create_data_directories(parray *dest_files,
10231025
const char *backup_dir,
10241026
bool extract_tablespaces,
10251027
bool incremental,
1026-
fio_location location);
1028+
fio_location location,
1029+
const char *waldir_path);
10271030

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

src/restore.c

+1-1
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.

tests/expected/option_help.out

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ pg_probackup - utility to manage backup/recovery of PostgreSQL database.
8686
[-T OLDDIR=NEWDIR] [--progress]
8787
[--external-mapping=OLDDIR=NEWDIR]
8888
[--skip-external-dirs] [--no-sync]
89+
[-X WALDIR | --waldir=WALDIR]
8990
[-I | --incremental-mode=none|checksum|lsn]
9091
[--db-include | --db-exclude]
9192
[--remote-proto] [--remote-host]

tests/expected/option_help_ru.out

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ pg_probackup - утилита для управления резервным к
8686
[-T OLDDIR=NEWDIR] [--progress]
8787
[--external-mapping=OLDDIR=NEWDIR]
8888
[--skip-external-dirs] [--no-sync]
89+
[-X WALDIR | --waldir=WALDIR]
8990
[-I | --incremental-mode=none|checksum|lsn]
9091
[--db-include | --db-exclude]
9192
[--remote-proto] [--remote-host]

tests/restore.py

+56
Original file line numberDiff line numberDiff line change
@@ -3920,3 +3920,59 @@ def test_restore_issue_313(self):
39203920

39213921
# Clean after yourself
39223922
self.del_test_dir(module_name, fname)
3923+
3924+
# @unittest.skip("skip")
3925+
def test_restore_with_waldir(self):
3926+
"""recovery using tablespace-mapping option and page backup"""
3927+
fname = self.id().split('.')[3]
3928+
node = self.make_simple_node(
3929+
base_dir=os.path.join(module_name, fname, 'node'),
3930+
initdb_params=['--data-checksums'])
3931+
3932+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
3933+
self.init_pb(backup_dir)
3934+
self.add_instance(backup_dir, 'node', node)
3935+
self.set_archiving(backup_dir, 'node', node)
3936+
node.slow_start()
3937+
3938+
3939+
with node.connect("postgres") as con:
3940+
con.execute(
3941+
"CREATE TABLE tbl AS SELECT * "
3942+
"FROM generate_series(0,3) AS integer")
3943+
con.commit()
3944+
3945+
# Full backup
3946+
backup_id = self.backup_node(backup_dir, 'node', node)
3947+
3948+
node.stop()
3949+
node.cleanup()
3950+
3951+
# Create waldir
3952+
waldir_path = os.path.join(node.base_dir, "waldir")
3953+
os.makedirs(waldir_path)
3954+
3955+
# Test recovery from latest
3956+
self.assertIn(
3957+
"INFO: Restore of backup {0} completed.".format(backup_id),
3958+
self.restore_node(
3959+
backup_dir, 'node', node,
3960+
options=[
3961+
"-X", "%s" % (waldir_path)]),
3962+
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
3963+
repr(self.output), self.cmd))
3964+
node.slow_start()
3965+
3966+
count = node.execute("postgres", "SELECT count(*) FROM tbl")
3967+
self.assertEqual(count[0][0], 4)
3968+
3969+
# check pg_wal is symlink
3970+
if node.major_version >= 10:
3971+
wal_path=os.path.join(node.data_dir, "pg_wal")
3972+
else:
3973+
wal_path=os.path.join(node.data_dir, "pg_xlog")
3974+
3975+
self.assertEqual(os.path.islink(wal_path), True)
3976+
3977+
# Clean after yourself
3978+
self.del_test_dir(module_name, fname)

0 commit comments

Comments
 (0)