mirror of
https://github.com/postgres/postgres.git
synced 2025-05-06 19:59:18 +03:00
Fix handling of symlinked pg_stat_tmp and pg_replslot
This was already fixed in HEAD as part of 6ad8ac60 but was not backpatched. Also change the way pg_xlog is handled to be the same as the other directories. Patch from me with pg_xlog addition from Michael Paquier, test updates from David Steele.
This commit is contained in:
parent
3af8467e9a
commit
b6a323a8c9
@ -57,6 +57,8 @@ static bool sendFile(char *readfilename, char *tarfilename,
|
|||||||
static void sendFileWithContent(const char *filename, const char *content);
|
static void sendFileWithContent(const char *filename, const char *content);
|
||||||
static void _tarWriteHeader(const char *filename, const char *linktarget,
|
static void _tarWriteHeader(const char *filename, const char *linktarget,
|
||||||
struct stat * statbuf);
|
struct stat * statbuf);
|
||||||
|
static int64 _tarWriteDir(const char *pathbuf, int basepathlen, struct stat * statbuf,
|
||||||
|
bool sizeonly);
|
||||||
static void send_int8_string(StringInfoData *buf, int64 intval);
|
static void send_int8_string(StringInfoData *buf, int64 intval);
|
||||||
static void SendBackupHeader(List *tablespaces);
|
static void SendBackupHeader(List *tablespaces);
|
||||||
static void base_backup_cleanup(int code, Datum arg);
|
static void base_backup_cleanup(int code, Datum arg);
|
||||||
@ -969,9 +971,7 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces,
|
|||||||
if ((statrelpath != NULL && strcmp(pathbuf, statrelpath) == 0) ||
|
if ((statrelpath != NULL && strcmp(pathbuf, statrelpath) == 0) ||
|
||||||
strncmp(de->d_name, PG_STAT_TMP_DIR, strlen(PG_STAT_TMP_DIR)) == 0)
|
strncmp(de->d_name, PG_STAT_TMP_DIR, strlen(PG_STAT_TMP_DIR)) == 0)
|
||||||
{
|
{
|
||||||
if (!sizeonly)
|
size += _tarWriteDir(pathbuf, basepathlen, &statbuf, sizeonly);
|
||||||
_tarWriteHeader(pathbuf + basepathlen + 1, NULL, &statbuf);
|
|
||||||
size += 512;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -981,9 +981,7 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces,
|
|||||||
*/
|
*/
|
||||||
if (strcmp(de->d_name, "pg_replslot") == 0)
|
if (strcmp(de->d_name, "pg_replslot") == 0)
|
||||||
{
|
{
|
||||||
if (!sizeonly)
|
size += _tarWriteDir(pathbuf, basepathlen, &statbuf, sizeonly);
|
||||||
_tarWriteHeader(pathbuf + basepathlen + 1, NULL, &statbuf);
|
|
||||||
size += 512; /* Size of the header just added */
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -994,18 +992,8 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces,
|
|||||||
*/
|
*/
|
||||||
if (strcmp(pathbuf, "./pg_xlog") == 0)
|
if (strcmp(pathbuf, "./pg_xlog") == 0)
|
||||||
{
|
{
|
||||||
if (!sizeonly)
|
/* If pg_xlog is a symlink, write it as a directory anyway */
|
||||||
{
|
size += _tarWriteDir(pathbuf, basepathlen, &statbuf, sizeonly);
|
||||||
/* If pg_xlog is a symlink, write it as a directory anyway */
|
|
||||||
#ifndef WIN32
|
|
||||||
if (S_ISLNK(statbuf.st_mode))
|
|
||||||
#else
|
|
||||||
if (pgwin32_is_junction(pathbuf))
|
|
||||||
#endif
|
|
||||||
statbuf.st_mode = S_IFDIR | S_IRWXU;
|
|
||||||
_tarWriteHeader(pathbuf + basepathlen + 1, NULL, &statbuf);
|
|
||||||
}
|
|
||||||
size += 512; /* Size of the header just added */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Also send archive_status directory (by hackishly reusing
|
* Also send archive_status directory (by hackishly reusing
|
||||||
@ -1247,6 +1235,30 @@ _tarWriteHeader(const char *filename, const char *linktarget,
|
|||||||
pq_putmessage('d', h, 512);
|
pq_putmessage('d', h, 512);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write tar header for a directory. If the entry in statbuf is a link then
|
||||||
|
* write it as a directory anyway.
|
||||||
|
*/
|
||||||
|
static int64
|
||||||
|
_tarWriteDir(const char *pathbuf, int basepathlen, struct stat * statbuf,
|
||||||
|
bool sizeonly)
|
||||||
|
{
|
||||||
|
if (sizeonly)
|
||||||
|
/* Directory headers are always 512 bytes */
|
||||||
|
return 512;
|
||||||
|
|
||||||
|
/* If symlink, write it as a directory anyway */
|
||||||
|
#ifndef WIN32
|
||||||
|
if (S_ISLNK(statbuf->st_mode))
|
||||||
|
#else
|
||||||
|
if (pgwin32_is_junction(pathbuf))
|
||||||
|
#endif
|
||||||
|
statbuf->st_mode = S_IFDIR | S_IRWXU;
|
||||||
|
|
||||||
|
_tarWriteHeader(pathbuf + basepathlen + 1, NULL, statbuf);
|
||||||
|
return 512;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Increment the network transfer counter by the given number of bytes,
|
* Increment the network transfer counter by the given number of bytes,
|
||||||
* and sleep if necessary to comply with the requested network transfer
|
* and sleep if necessary to comply with the requested network transfer
|
||||||
|
@ -4,7 +4,7 @@ use Cwd;
|
|||||||
use Config;
|
use Config;
|
||||||
use PostgresNode;
|
use PostgresNode;
|
||||||
use TestLib;
|
use TestLib;
|
||||||
use Test::More tests => 51;
|
use Test::More tests => 52;
|
||||||
|
|
||||||
program_help_ok('pg_basebackup');
|
program_help_ok('pg_basebackup');
|
||||||
program_version_ok('pg_basebackup');
|
program_version_ok('pg_basebackup');
|
||||||
@ -102,7 +102,17 @@ unlink "$pgdata/$superlongname";
|
|||||||
# skip on Windows.
|
# skip on Windows.
|
||||||
SKIP:
|
SKIP:
|
||||||
{
|
{
|
||||||
skip "symlinks not supported on Windows", 10 if ($windows_os);
|
skip "symlinks not supported on Windows", 11 if ($windows_os);
|
||||||
|
|
||||||
|
# Move pg_replslot out of $pgdata and create a symlink to it.
|
||||||
|
$node->stop;
|
||||||
|
|
||||||
|
rename("$pgdata/pg_replslot", "$tempdir/pg_replslot")
|
||||||
|
or BAIL_OUT "could not move $pgdata/pg_replslot";
|
||||||
|
symlink("$tempdir/pg_replslot", "$pgdata/pg_replslot")
|
||||||
|
or BAIL_OUT "could not symlink to $pgdata/pg_replslot";
|
||||||
|
|
||||||
|
$node->start;
|
||||||
|
|
||||||
# Create a temporary directory in the system location and symlink it
|
# Create a temporary directory in the system location and symlink it
|
||||||
# to our physical temp location. That way we can use shorter names
|
# to our physical temp location. That way we can use shorter names
|
||||||
@ -140,6 +150,8 @@ SKIP:
|
|||||||
"tablespace symlink was updated");
|
"tablespace symlink was updated");
|
||||||
closedir $dh;
|
closedir $dh;
|
||||||
|
|
||||||
|
ok(-d "$tempdir/backup1/pg_replslot", 'pg_replslot symlink copied as directory');
|
||||||
|
|
||||||
mkdir "$tempdir/tbl=spc2";
|
mkdir "$tempdir/tbl=spc2";
|
||||||
$node->safe_psql('postgres', "DROP TABLE test1;");
|
$node->safe_psql('postgres', "DROP TABLE test1;");
|
||||||
$node->safe_psql('postgres', "DROP TABLESPACE tblspc1;");
|
$node->safe_psql('postgres', "DROP TABLESPACE tblspc1;");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user