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

Commitd1b88f6

Browse files
committed
Add --xlogdir option to pg_basebackup, for specifying the pg_xlog directory.
Haribabu kommi, slightly modified by me.
1 parent551c782 commitd1b88f6

File tree

2 files changed

+73
-3
lines changed

2 files changed

+73
-3
lines changed

‎doc/src/sgml/ref/pg_basebackup.sgml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,18 @@ PostgreSQL documentation
202202
</listitem>
203203
</varlistentry>
204204

205+
<varlistentry>
206+
<term><option>--xlogdir=<replaceable class="parameter">xlogdir</replaceable></option></term>
207+
<listitem>
208+
<para>
209+
Specifies the location for the transaction log directory.
210+
<replaceable>xlogdir</replaceable> must be an absolute path.
211+
The transaction log directory can only be specified when
212+
the backup is in plain mode.
213+
</para>
214+
</listitem>
215+
</varlistentry>
216+
205217
<varlistentry>
206218
<term><option>-x</option></term>
207219
<term><option>--xlog</option></term>

‎src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
/* Global options */
3737
char*basedir=NULL;
38+
staticchar*xlog_dir="";
3839
charformat='p';/* p(lain)/t(ar) */
3940
char*label="pg_basebackup base backup";
4041
boolshowprogress= false;
@@ -115,6 +116,7 @@ usage(void)
115116
printf(_(" -x, --xlog include required WAL files in backup (fetch mode)\n"));
116117
printf(_(" -X, --xlog-method=fetch|stream\n"
117118
" include required WAL files with specified method\n"));
119+
printf(_(" --xlogdir=XLOGDIR location for the transaction log directory\n"));
118120
printf(_(" -z, --gzip compress tar output\n"));
119121
printf(_(" -Z, --compress=0-9 compress tar output with given compression level\n"));
120122
printf(_("\nGeneral options:\n"));
@@ -980,10 +982,14 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum)
980982
{
981983
/*
982984
* When streaming WAL, pg_xlog will have been created
983-
* by the wal receiver process, so just ignore failure
984-
* on that.
985+
* by the wal receiver process. Also, when transaction
986+
* log directory location was specified, pg_xlog has
987+
* already been created as a symbolic link before
988+
* starting the actual backup. So just ignore failure
989+
* on them.
985990
*/
986-
if (!streamwal||strcmp(filename+strlen(filename)-8,"/pg_xlog")!=0)
991+
if ((!streamwal&& (strcmp(xlog_dir,"")==0))
992+
||strcmp(filename+strlen(filename)-8,"/pg_xlog")!=0)
987993
{
988994
fprintf(stderr,
989995
_("%s: could not create directory \"%s\": %s\n"),
@@ -1666,6 +1672,7 @@ main(int argc, char **argv)
16661672
{"status-interval",required_argument,NULL,'s'},
16671673
{"verbose",no_argument,NULL,'v'},
16681674
{"progress",no_argument,NULL,'P'},
1675+
{"xlogdir",required_argument,NULL,1},
16691676
{NULL,0,NULL,0}
16701677
};
16711678
intc;
@@ -1750,6 +1757,9 @@ main(int argc, char **argv)
17501757
exit(1);
17511758
}
17521759
break;
1760+
case1:
1761+
xlog_dir=pg_strdup(optarg);
1762+
break;
17531763
case'l':
17541764
label=pg_strdup(optarg);
17551765
break;
@@ -1872,6 +1882,30 @@ main(int argc, char **argv)
18721882
exit(1);
18731883
}
18741884

1885+
if (strcmp(xlog_dir,"")!=0)
1886+
{
1887+
if (format!='p')
1888+
{
1889+
fprintf(stderr,
1890+
_("%s: transaction log directory location can only be specified in plain mode\n"),
1891+
progname);
1892+
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),
1893+
progname);
1894+
exit(1);
1895+
}
1896+
1897+
/* clean up xlog directory name, check it's absolute */
1898+
canonicalize_path(xlog_dir);
1899+
if (!is_absolute_path(xlog_dir))
1900+
{
1901+
fprintf(stderr,_("%s: transaction log directory location must be "
1902+
"an absolute path\n"),progname);
1903+
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),
1904+
progname);
1905+
exit(1);
1906+
}
1907+
}
1908+
18751909
#ifndefHAVE_LIBZ
18761910
if (compresslevel!=0)
18771911
{
@@ -1890,6 +1924,30 @@ main(int argc, char **argv)
18901924
if (format=='p'||strcmp(basedir,"-")!=0)
18911925
verify_dir_is_empty_or_create(basedir);
18921926

1927+
/* Create transaction log symlink, if required */
1928+
if (strcmp(xlog_dir,"")!=0)
1929+
{
1930+
char*linkloc;
1931+
1932+
verify_dir_is_empty_or_create(xlog_dir);
1933+
1934+
/* form name of the place where the symlink must go */
1935+
linkloc=psprintf("%s/pg_xlog",basedir);
1936+
1937+
#ifdefHAVE_SYMLINK
1938+
if (symlink(xlog_dir,linkloc)!=0)
1939+
{
1940+
fprintf(stderr,_("%s: could not create symbolic link \"%s\": %s\n"),
1941+
progname,linkloc,strerror(errno));
1942+
exit(1);
1943+
}
1944+
#else
1945+
fprintf(stderr,_("%s: symlinks are not supported on this platform"));
1946+
exit(1);
1947+
#endif
1948+
free(linkloc);
1949+
}
1950+
18931951
BaseBackup();
18941952

18951953
return0;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp