Skip to content

Commit 96a5f13

Browse files
committed
Save and compare system-identifier.
1 parent 90897a5 commit 96a5f13

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

init.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ do_init(void)
3434
char *log_directory = NULL;
3535
char *archive_command = NULL;
3636
FILE *fp;
37+
uint64 _system_identifier;
3738

3839
struct dirent **dp;
3940
int results;
@@ -58,6 +59,7 @@ do_init(void)
5859
parse_postgresql_conf(path, &log_directory, &archive_command);
5960
}
6061

62+
_system_identifier = get_system_identifier(false);
6163
/* create pg_probackup.conf */
6264
join_path_components(path, backup_path, PG_RMAN_INI_FILE);
6365
fp = fopen(path, "wt");
@@ -67,6 +69,7 @@ do_init(void)
6769
join_path_components(arclog_path_dir, backup_path, "wal");
6870
dir_create_dir(arclog_path_dir, DIR_PERMISSION);
6971

72+
fprintf(fp, "system-identifier = %li\n", _system_identifier);
7073
fprintf(fp, "\n");
7174
fclose(fp);
7275

pg_probackup.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ bool from_replica = false;
4040
static bool backup_logs = false;
4141
bool progress = false;
4242
bool delete_wal = false;
43+
uint64 system_identifier = 0;
4344

4445
/* restore configuration */
4546
static char *target_time;
@@ -74,6 +75,8 @@ static pgut_option options[] =
7475
{ 'u', 6, "timeline", &target_tli, SOURCE_CMDLINE },
7576
/* delete options */
7677
{ 'b', 12, "wal", &delete_wal },
78+
/* other */
79+
{ 'U', 13, "system-identifier", &system_identifier, SOURCE_FILE },
7780
{ 0 }
7881
};
7982

@@ -188,10 +191,16 @@ main(int argc, char *argv[])
188191
{
189192
pgBackupOption bkupopt;
190193
int res;
194+
uint64 _system_identifier;
191195
bkupopt.smooth_checkpoint = smooth_checkpoint;
192196
bkupopt.keep_data_generations = keep_data_generations;
193197
bkupopt.keep_data_days = keep_data_days;
194198

199+
_system_identifier = get_system_identifier(true);
200+
if (_system_identifier != system_identifier)
201+
elog(ERROR, "Backup directory was initialized for system id = %ld, but target system id = %ld",
202+
system_identifier, _system_identifier);
203+
195204
/* Do the backup */
196205
res = do_backup(bkupopt);
197206
if (res != 0)

pg_probackup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ extern bool stream_wal;
205205
extern bool from_replica;
206206
extern bool progress;
207207
extern bool delete_wal;
208+
extern uint64 system_identifier;
208209

209210
/* in backup.c */
210211
extern int do_backup(pgBackupOption bkupopt);
@@ -310,6 +311,7 @@ extern XLogRecPtr get_last_ptrack_lsn(void);
310311
extern uint32 get_data_checksum_version(bool safe);
311312
extern char *base36enc(long unsigned int value);
312313
extern long unsigned int base36dec(const char *text);
314+
extern uint64 get_system_identifier(bool safe);
313315

314316
/* in status.c */
315317
extern bool is_pg_running(void);

util.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,23 @@ get_current_timeline(bool safe)
122122
return ControlFile.checkPointCopy.ThisTimeLineID;
123123
}
124124

125+
uint64
126+
get_system_identifier(bool safe)
127+
{
128+
ControlFileData ControlFile;
129+
char *buffer;
130+
size_t size;
131+
132+
/* First fetch file... */
133+
buffer = slurpFile(pgdata, "global/pg_control", &size, safe);
134+
if (buffer == NULL)
135+
return 0;
136+
digestControlFile(&ControlFile, buffer, size);
137+
pg_free(buffer);
138+
139+
return ControlFile.system_identifier;
140+
}
141+
125142
uint32
126143
get_data_checksum_version(bool safe)
127144
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy