Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9cd25f2

Browse files
authored
Merge pull request#500 from postgrespro/PBCKP-153
PBCKP-153
2 parentsacc8edc +61cd620 commit9cd25f2

File tree

9 files changed

+116
-4
lines changed

9 files changed

+116
-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,constchar*data_dir,constchar*backup_dir,
1039-
boolextract_tablespaces,boolincremental,fio_locationlocation)
1039+
boolextract_tablespaces,boolincremental,fio_locationlocation,
1040+
constchar*waldir_path)
10401041
{
10411042
inti;
10421043
parray*links=NULL;
10431044
mode_tpg_tablespace_mode=DIR_PERMISSION;
10441045
charto_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
staticparray*exclude_absolute_paths_list=NULL;
124124
staticparray*exclude_relative_paths_list=NULL;
125+
staticchar*gl_waldir_path=NULL;
125126

126127
/* checkdb options */
127128
boolneed_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

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
PartialRestoreTypepartial_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
constchar*backup_dir,
10231025
boolextract_tablespaces,
10241026
boolincremental,
1025-
fio_locationlocation);
1027+
fio_locationlocation,
1028+
constchar*waldir_path);
10261029

10271030
externvoidread_tablespace_map(parray*links,constchar*backup_dir);
10281031
externvoidopt_tablespace_map(ConfigOption*opt,constchar*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.

‎tests/expected/option_help.out

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3916,3 +3916,59 @@ def test_restore_issue_313(self):
39163916

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp