Skip to content

Commit f22d1cf

Browse files
committed
Remove the dbid on the return of BASHBACKUP
1 parent 09102ae commit f22d1cf

2 files changed

Lines changed: 47 additions & 5 deletions

File tree

src/backend/backup/basebackup_copy.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,24 @@ bbsink_copystream_begin_archive(bbsink *sink, const char *archive_name)
167167
bbsink_state *state = sink->bbs_state;
168168
tablespaceinfo *ti;
169169
StringInfoData buf;
170+
char *link_path_to_be_sent;
170171

171172
ti = list_nth(state->tablespaces, state->tablespace_num);
172173
pq_beginmessage(&buf, 'd'); /* CopyData */
173174
pq_sendbyte(&buf, 'n'); /* New archive */
174175
pq_sendstring(&buf, archive_name);
175-
pq_sendstring(&buf, ti->path == NULL ? "" : ti->path);
176+
if(ti->rpath == NULL && ti->path)
177+
{
178+
/* Lop off the dbid before sending the link target. */
179+
char *link_path_without_dbid = pstrdup(ti->path);
180+
char *file_sep_before_dbid_in_link_path =
181+
strrchr(link_path_without_dbid, '/');
182+
*file_sep_before_dbid_in_link_path = '\0';
183+
link_path_to_be_sent = link_path_without_dbid;
184+
}
185+
else
186+
link_path_to_be_sent = ti->path;
187+
pq_sendstring(&buf, ti->path == NULL ? "" : link_path_to_be_sent);
176188
pq_endmessage(&buf);
177189
}
178190

@@ -407,8 +419,23 @@ SendTablespaceList(List *tablespaces)
407419
}
408420
else
409421
{
422+
char *link_path_to_be_sent;
423+
410424
values[0] = ObjectIdGetDatum(strtoul(ti->oid, NULL, 10));
411-
values[1] = CStringGetTextDatum(ti->path);
425+
426+
if(ti->rpath == NULL && ti->path)
427+
{
428+
/* Lop off the dbid before sending the link target. */
429+
char *link_path_without_dbid = pstrdup(ti->path);
430+
char *file_sep_before_dbid_in_link_path =
431+
strrchr(link_path_without_dbid, '/');
432+
*file_sep_before_dbid_in_link_path = '\0';
433+
link_path_to_be_sent = link_path_without_dbid;
434+
}
435+
else
436+
link_path_to_be_sent = ti->path;
437+
438+
values[1] = CStringGetTextDatum(link_path_to_be_sent);
412439
}
413440
if (ti->size >= 0)
414441
values[2] = Int64GetDatum(ti->size / 1024);

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,9 +1156,23 @@ CreateBackupStreamer(char *archive_name, char *spclocation,
11561156
if (spclocation == NULL)
11571157
directory = basedir;
11581158
else if (!is_absolute_path(spclocation))
1159-
directory = psprintf("%s/%s", basedir, spclocation);
1159+
{
1160+
if (target_gp_dbid < 1)
1161+
{
1162+
pg_log_error("cannot restore user-defined tablespaces without the --target-gp-dbid option");
1163+
exit(1);
1164+
}
1165+
directory = psprintf("%s/%s/%d", basedir, spclocation, target_gp_dbid);
1166+
}
11601167
else
1161-
directory = get_tablespace_mapping(spclocation);
1168+
{
1169+
if (target_gp_dbid < 1)
1170+
{
1171+
pg_log_error("cannot restore user-defined tablespaces without the --target-gp-dbid option");
1172+
exit(1);
1173+
}
1174+
directory = psprintf("%s/%d", spclocation, target_gp_dbid);
1175+
}
11621176
streamer = bbstreamer_extractor_new(directory,
11631177
get_tablespace_mapping,
11641178
progress_update_filename);
@@ -2066,11 +2080,12 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
20662080
* won't be storing anything into these directories and thus should
20672081
* not create them.
20682082
*/
2083+
// sleep(30);
20692084
if (backup_target == NULL && format == 'p' && !PQgetisnull(res, i, 1))
20702085
{
20712086
char path_with_subdir[MAXPGPATH];
20722087
char *path = PQgetvalue(res, i, 1);
2073-
2088+
20742089
if (is_absolute_path(path))
20752090
path = unconstify(char *, get_tablespace_mapping(path));
20762091
else

0 commit comments

Comments
 (0)