mirror of
https://github.com/postgres/postgres.git
synced 2025-06-17 17:02:08 +03:00
Add the system identifier to backup manifests.
Before this patch, if you took a full backup on server A and then tried to use the backup manifest to take an incremental backup on server B, it wouldn't know that the manifest was from a different server and so the incremental backup operation could potentially complete without error. When you later tried to run pg_combinebackup, you'd find out that your incremental backup was and always had been invalid. That's poor timing, because nobody likes finding out about backup problems only at restore time. With this patch, you'll get an error when trying to take the (invalid) incremental backup, which seems a lot nicer. Amul Sul, revised by me. Review by Michael Paquier. Discussion: http://postgr.es/m/CA+TgmoYLZzbSAMM3cAjV4Y+iCRZn-bR9H2+Mdz7NdaJFU1Zb5w@mail.gmail.com
This commit is contained in:
@ -20,6 +20,7 @@
|
||||
#include "postgres.h"
|
||||
|
||||
#include "access/timeline.h"
|
||||
#include "access/xlog.h"
|
||||
#include "backup/basebackup_incremental.h"
|
||||
#include "backup/walsummary.h"
|
||||
#include "common/blkreftable.h"
|
||||
@ -113,6 +114,10 @@ struct IncrementalBackupInfo
|
||||
BlockRefTable *brtab;
|
||||
};
|
||||
|
||||
static void manifest_process_version(JsonManifestParseContext *context,
|
||||
int manifest_version);
|
||||
static void manifest_process_system_identifier(JsonManifestParseContext *context,
|
||||
uint64 manifest_system_identifier);
|
||||
static void manifest_process_file(JsonManifestParseContext *context,
|
||||
char *pathname,
|
||||
size_t size,
|
||||
@ -199,6 +204,8 @@ FinalizeIncrementalManifest(IncrementalBackupInfo *ib)
|
||||
|
||||
/* Parse the manifest. */
|
||||
context.private_data = ib;
|
||||
context.version_cb = manifest_process_version;
|
||||
context.system_identifier_cb = manifest_process_system_identifier;
|
||||
context.per_file_cb = manifest_process_file;
|
||||
context.per_wal_range_cb = manifest_process_wal_range;
|
||||
context.error_cb = manifest_report_error;
|
||||
@ -927,6 +934,39 @@ hash_string_pointer(const char *s)
|
||||
return hash_bytes(ss, strlen(s));
|
||||
}
|
||||
|
||||
/*
|
||||
* This callback to validate the manifest version for incremental backup.
|
||||
*/
|
||||
static void
|
||||
manifest_process_version(JsonManifestParseContext *context,
|
||||
int manifest_version)
|
||||
{
|
||||
/* Incremental backups don't work with manifest version 1 */
|
||||
if (manifest_version == 1)
|
||||
context->error_cb(context,
|
||||
"backup manifest version 1 does not support incremental backup");
|
||||
}
|
||||
|
||||
/*
|
||||
* This callback to validate the manifest system identifier against the current
|
||||
* database server.
|
||||
*/
|
||||
static void
|
||||
manifest_process_system_identifier(JsonManifestParseContext *context,
|
||||
uint64 manifest_system_identifier)
|
||||
{
|
||||
uint64 system_identifier;
|
||||
|
||||
/* Get system identifier of current system */
|
||||
system_identifier = GetSystemIdentifier();
|
||||
|
||||
if (manifest_system_identifier != system_identifier)
|
||||
context->error_cb(context,
|
||||
"manifest system identifier is %llu, but database system identifier is %llu",
|
||||
(unsigned long long) manifest_system_identifier,
|
||||
(unsigned long long) system_identifier);
|
||||
}
|
||||
|
||||
/*
|
||||
* This callback is invoked for each file mentioned in the backup manifest.
|
||||
*
|
||||
|
Reference in New Issue
Block a user