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

Commit28ba260

Browse files
committed
In base backup, only include our own tablespace version directory.
If you have clusters of different versions pointing to the same tablespacelocation, we would incorrectly include all the data belonging to the otherversions, too.Fixes bug #7986, reported by Sergey Burladyan.
1 parentd298b50 commit28ba260

File tree

1 file changed

+55
-13
lines changed

1 file changed

+55
-13
lines changed

‎src/backend/replication/basebackup.c

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include"access/xlog_internal.h"/* for pg_start/stop_backup */
2121
#include"catalog/pg_type.h"
22+
#include"common/relpath.h"
2223
#include"lib/stringinfo.h"
2324
#include"libpq/libpq.h"
2425
#include"libpq/pqformat.h"
@@ -45,6 +46,7 @@ typedef struct
4546

4647

4748
staticint64sendDir(char*path,intbasepathlen,boolsizeonly);
49+
staticint64sendTablespace(char*path,boolsizeonly);
4850
staticboolsendFile(char*readfilename,char*tarfilename,
4951
structstat*statbuf,boolmissing_ok);
5052
staticvoidsendFileWithContent(constchar*filename,constchar*content);
@@ -146,7 +148,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
146148
ti=palloc(sizeof(tablespaceinfo));
147149
ti->oid=pstrdup(de->d_name);
148150
ti->path=pstrdup(linkpath);
149-
ti->size=opt->progress ?sendDir(linkpath,strlen(linkpath), true) :-1;
151+
ti->size=opt->progress ?sendTablespace(fullpath, true) :-1;
150152
tablespaces=lappend(tablespaces,ti);
151153
#else
152154

@@ -181,29 +183,26 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
181183
pq_sendint(&buf,0,2);/* natts */
182184
pq_endmessage(&buf);
183185

184-
/* In the main tar, include the backup_label first. */
185-
if (ti->path==NULL)
186-
sendFileWithContent(BACKUP_LABEL_FILE,labelfile);
187-
188-
sendDir(ti->path==NULL ?"." :ti->path,
189-
ti->path==NULL ?1 :strlen(ti->path),
190-
false);
191-
192-
/* In the main tar, include pg_control last. */
193186
if (ti->path==NULL)
194187
{
195188
structstatstatbuf;
196189

190+
/* In the main tar, include the backup_label first... */
191+
sendFileWithContent(BACKUP_LABEL_FILE,labelfile);
192+
193+
/* ... then the bulk of the files ... */
194+
sendDir(".",1, false);
195+
196+
/* ... and pg_control after everything else. */
197197
if (lstat(XLOG_CONTROL_FILE,&statbuf)!=0)
198-
{
199198
ereport(ERROR,
200199
(errcode_for_file_access(),
201200
errmsg("could not stat control file \"%s\": %m",
202201
XLOG_CONTROL_FILE)));
203-
}
204-
205202
sendFile(XLOG_CONTROL_FILE,XLOG_CONTROL_FILE,&statbuf, false);
206203
}
204+
else
205+
sendTablespace(ti->path, false);
207206

208207
/*
209208
* If we're including WAL, and this is the main data directory we
@@ -728,6 +727,49 @@ sendFileWithContent(const char *filename, const char *content)
728727
}
729728
}
730729

730+
/*
731+
* Include the tablespace directory pointed to by 'path' in the output tar
732+
* stream. If 'sizeonly' is true, we just calculate a total length and return
733+
* it, without actually sending anything.
734+
*/
735+
staticint64
736+
sendTablespace(char*path,boolsizeonly)
737+
{
738+
int64size;
739+
charpathbuf[MAXPGPATH];
740+
structstatstatbuf;
741+
742+
/*
743+
* 'path' points to the tablespace location, but we only want to include
744+
* the version directory in it that belongs to us.
745+
*/
746+
snprintf(pathbuf,sizeof(pathbuf),"%s/%s",path,
747+
TABLESPACE_VERSION_DIRECTORY);
748+
749+
/*
750+
* Store a directory entry in the tar file so we get the permissions right.
751+
*/
752+
if (lstat(pathbuf,&statbuf)!=0)
753+
{
754+
if (errno!=ENOENT)
755+
ereport(ERROR,
756+
(errcode_for_file_access(),
757+
errmsg("could not stat file or directory \"%s\": %m",
758+
pathbuf)));
759+
760+
/* If the tablespace went away while scanning, it's no error. */
761+
return0;
762+
}
763+
if (!sizeonly)
764+
_tarWriteHeader(TABLESPACE_VERSION_DIRECTORY,NULL,&statbuf);
765+
size=512;/* Size of the header just added */
766+
767+
/* Send all the files in the tablespace version directory */
768+
size+=sendDir(pathbuf,strlen(path),sizeonly);
769+
770+
returnsize;
771+
}
772+
731773
/*
732774
* Include all files from the given directory in the output tar stream. If
733775
* 'sizeonly' is true, we just calculate a total length and return it, without

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp