You've already forked pg_probackup
mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2026-06-21 01:34:15 +02:00
Save encrypted property in backup control file
This commit is contained in:
+6
-6
@@ -179,7 +179,7 @@ push_wal_file(const char *from_path, const char *to_path, bool is_compress,
|
||||
snprintf(to_path_temp, sizeof(to_path_temp), "%s.partial", gz_to_path);
|
||||
|
||||
gz_out = fio_gzopen(to_path_temp, PG_BINARY_W, instance_config.compress_level, FIO_BACKUP_HOST,
|
||||
instance_config.encryption);
|
||||
current_backup->encrypted);
|
||||
if (gz_out == NULL)
|
||||
elog(ERROR, "Cannot open destination temporary WAL file \"%s\": %s",
|
||||
to_path_temp, strerror(errno));
|
||||
@@ -194,7 +194,7 @@ push_wal_file(const char *from_path, const char *to_path, bool is_compress,
|
||||
if (out_fd < 0)
|
||||
elog(ERROR, "Cannot open destination temporary WAL file \"%s\": %s",
|
||||
to_path_temp, strerror(errno));
|
||||
out = fio_fdopen(to_path_temp, out_fd, PG_BINARY_W, instance_config.encryption);
|
||||
out = fio_fdopen(to_path_temp, out_fd, PG_BINARY_W, current_backup->encrypted);
|
||||
}
|
||||
|
||||
/* copy content */
|
||||
@@ -336,7 +336,7 @@ get_wal_file(const char *from_path, const char *to_path)
|
||||
/* open file for read */
|
||||
if (!is_decompress)
|
||||
{
|
||||
in = fio_fopen(from_path, PG_BINARY_R, FIO_BACKUP_HOST, instance_config.encryption);
|
||||
in = fio_fopen(from_path, PG_BINARY_R, FIO_BACKUP_HOST, current_backup->encrypted);
|
||||
if (in == NULL)
|
||||
elog(ERROR, "Cannot open source WAL file \"%s\": %s",
|
||||
from_path, strerror(errno));
|
||||
@@ -345,7 +345,7 @@ get_wal_file(const char *from_path, const char *to_path)
|
||||
else
|
||||
{
|
||||
gz_in = fio_gzopen(gz_from_path, PG_BINARY_R, Z_DEFAULT_COMPRESSION,
|
||||
FIO_BACKUP_HOST, instance_config.encryption);
|
||||
FIO_BACKUP_HOST, current_backup->encrypted);
|
||||
if (gz_in == NULL)
|
||||
elog(ERROR, "Cannot open compressed WAL file \"%s\": %s",
|
||||
gz_from_path, strerror(errno));
|
||||
@@ -500,7 +500,7 @@ fileEqualCRC(const char *path1, const char *path2, bool path2_is_compressed)
|
||||
gzFile gz_in = NULL;
|
||||
|
||||
INIT_FILE_CRC32(true, crc2);
|
||||
gz_in = fio_gzopen(path2, PG_BINARY_R, Z_DEFAULT_COMPRESSION, FIO_BACKUP_HOST, instance_config.encryption);
|
||||
gz_in = fio_gzopen(path2, PG_BINARY_R, Z_DEFAULT_COMPRESSION, FIO_BACKUP_HOST, current_backup->encrypted);
|
||||
if (gz_in == NULL)
|
||||
/* File cannot be read */
|
||||
elog(ERROR,
|
||||
@@ -531,7 +531,7 @@ fileEqualCRC(const char *path1, const char *path2, bool path2_is_compressed)
|
||||
else
|
||||
#endif
|
||||
{
|
||||
crc2 = pgFileGetCRC(path2, true, true, NULL, FIO_BACKUP_HOST, instance_config.encryption);
|
||||
crc2 = pgFileGetCRC(path2, true, true, NULL, FIO_BACKUP_HOST, current_backup->encrypted);
|
||||
}
|
||||
|
||||
/* Get checksum of original file */
|
||||
|
||||
@@ -518,6 +518,7 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
|
||||
fio_fprintf(out, "#Configuration\n");
|
||||
fio_fprintf(out, "backup-mode = %s\n", pgBackupGetBackupMode(backup));
|
||||
fio_fprintf(out, "stream = %s\n", backup->stream ? "true" : "false");
|
||||
fio_fprintf(out, "encrypted = %s\n", backup->encrypted ? "true" : "false");
|
||||
fio_fprintf(out, "compress-alg = %s\n",
|
||||
deparse_compress_alg(backup->compress_alg));
|
||||
fio_fprintf(out, "compress-level = %d\n", backup->compress_level);
|
||||
@@ -702,6 +703,7 @@ readBackupControlFile(const char *path)
|
||||
{'s', 0, "program-version", &program_version, SOURCE_FILE_STRICT},
|
||||
{'s', 0, "server-version", &server_version, SOURCE_FILE_STRICT},
|
||||
{'b', 0, "stream", &backup->stream, SOURCE_FILE_STRICT},
|
||||
{'b', 0, "encrypted", &backup->encrypted, SOURCE_FILE_STRICT},
|
||||
{'s', 0, "status", &status, SOURCE_FILE_STRICT},
|
||||
{'s', 0, "parent-backup-id", &parent_backup, SOURCE_FILE_STRICT},
|
||||
{'s', 0, "compress-alg", &compress_alg, SOURCE_FILE_STRICT},
|
||||
@@ -933,6 +935,7 @@ pgBackupInit(pgBackup *backup)
|
||||
backup->checksum_version = 0;
|
||||
|
||||
backup->stream = false;
|
||||
backup->encrypted = false;
|
||||
backup->from_replica = false;
|
||||
backup->parent_backup = INVALID_BACKUP_ID;
|
||||
backup->parent_backup_link = NULL;
|
||||
|
||||
+5
-5
@@ -598,7 +598,7 @@ backup_data_file(backup_files_arg* arguments,
|
||||
nblocks = file->size/BLCKSZ;
|
||||
|
||||
/* open backup file for write */
|
||||
out = fio_fopen(to_path, PG_BINARY_W, FIO_BACKUP_HOST, instance_config.encryption);
|
||||
out = fio_fopen(to_path, PG_BINARY_W, FIO_BACKUP_HOST, current_backup->encrypted);
|
||||
if (out == NULL)
|
||||
{
|
||||
int errno_tmp = errno;
|
||||
@@ -727,7 +727,7 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
|
||||
if (file->write_size != BYTES_INVALID)
|
||||
{
|
||||
/* open backup mode file for read */
|
||||
in = fio_fopen(file->path, PG_BINARY_R, FIO_LOCAL_HOST, file->is_datafile && instance_config.encryption);
|
||||
in = fio_fopen(file->path, PG_BINARY_R, FIO_LOCAL_HOST, file->is_datafile && current_backup->encrypted);
|
||||
if (in == NULL)
|
||||
{
|
||||
elog(ERROR, "Cannot open backup file \"%s\": %s", file->path,
|
||||
@@ -963,7 +963,7 @@ copy_file(fio_location from_location, const char *to_root,
|
||||
file->write_size = 0;
|
||||
|
||||
/* open backup mode file for read */
|
||||
in = fio_fopen(file->path, PG_BINARY_R, from_location, file->is_datafile && instance_config.encryption && from_location == FIO_BACKUP_HOST);
|
||||
in = fio_fopen(file->path, PG_BINARY_R, from_location, file->is_datafile && current_backup->encrypted && from_location == FIO_BACKUP_HOST);
|
||||
if (in == NULL)
|
||||
{
|
||||
FIN_FILE_CRC32(true, crc);
|
||||
@@ -988,7 +988,7 @@ copy_file(fio_location from_location, const char *to_root,
|
||||
|
||||
/* open backup file for write */
|
||||
join_path_components(to_path, to_root, file->rel_path);
|
||||
out = fio_fopen(to_path, PG_BINARY_W, to_location, file->is_datafile && instance_config.encryption && to_location == FIO_BACKUP_HOST);
|
||||
out = fio_fopen(to_path, PG_BINARY_W, to_location, file->is_datafile && current_backup->encrypted && to_location == FIO_BACKUP_HOST);
|
||||
if (out == NULL)
|
||||
{
|
||||
int errno_tmp = errno;
|
||||
@@ -1272,7 +1272,7 @@ check_file_pages(pgFile *file, XLogRecPtr stop_lsn, uint32 checksum_version,
|
||||
|
||||
elog(VERBOSE, "Validate relation blocks for file %s", file->path);
|
||||
|
||||
in = fio_fopen(file->path, PG_BINARY_R, FIO_BACKUP_HOST, instance_config.encryption);
|
||||
in = fio_fopen(file->path, PG_BINARY_R, FIO_BACKUP_HOST, current_backup->encrypted);
|
||||
if (in == NULL)
|
||||
{
|
||||
if (errno == ENOENT)
|
||||
|
||||
+2
-2
@@ -513,7 +513,7 @@ merge_files(void *arg)
|
||||
* Recalculate crc for backup prior to 2.0.25.
|
||||
*/
|
||||
if (parse_program_version(from_backup->program_version) < 20025)
|
||||
file->crc = pgFileGetCRC(to_file_path, true, true, NULL, FIO_LOCAL_HOST, instance_config.encryption);
|
||||
file->crc = pgFileGetCRC(to_file_path, true, true, NULL, FIO_LOCAL_HOST, to_backup->encrypted);
|
||||
/* Otherwise just get it from the previous file */
|
||||
else
|
||||
file->crc = to_file->crc;
|
||||
@@ -637,7 +637,7 @@ merge_files(void *arg)
|
||||
* do that.
|
||||
*/
|
||||
file->write_size = pgFileSize(to_file_path);
|
||||
file->crc = pgFileGetCRC(to_file_path, true, true, NULL, FIO_LOCAL_HOST, instance_config.encryption);
|
||||
file->crc = pgFileGetCRC(to_file_path, true, true, NULL, FIO_LOCAL_HOST, to_backup->encrypted);
|
||||
}
|
||||
}
|
||||
else if (file->external_dir_num)
|
||||
|
||||
+2
-2
@@ -736,7 +736,7 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
|
||||
return -1;
|
||||
}
|
||||
reader_data->xlogfile = fio_fdopen(reader_data->xlogpath, fd, "rb",
|
||||
instance_config.encryption && !stream_wal);
|
||||
current_backup->encrypted && !current_backup->stream);
|
||||
}
|
||||
#ifdef HAVE_LIBZ
|
||||
/* Try to open compressed WAL segment */
|
||||
@@ -752,7 +752,7 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
|
||||
reader_data->xlogexists = true;
|
||||
reader_data->gz_xlogfile = fio_gzopen(reader_data->gz_xlogpath,
|
||||
"rb", -1, FIO_BACKUP_HOST,
|
||||
instance_config.encryption && !stream_wal);
|
||||
current_backup->encrypted && !current_backup->stream);
|
||||
if (reader_data->gz_xlogfile == NULL)
|
||||
{
|
||||
elog(WARNING, "Thread [%d]: Could not open compressed WAL segment \"%s\": %s",
|
||||
|
||||
+7
-3
@@ -127,6 +127,7 @@ ShowFormat show_format = SHOW_PLAIN;
|
||||
|
||||
/* current settings */
|
||||
pgBackup current;
|
||||
pgBackup* current_backup = ¤t;
|
||||
static ProbackupSubcmd backup_subcmd = NO_CMD;
|
||||
|
||||
static bool help_opt = false;
|
||||
@@ -197,8 +198,6 @@ static ConfigOption cmd_options[] =
|
||||
{ 'b', 152, "overwrite", &file_overwrite, SOURCE_CMD_STRICT },
|
||||
/* show options */
|
||||
{ 'f', 153, "format", opt_show_format, SOURCE_CMD_STRICT },
|
||||
/* encryption options */
|
||||
{ 'b', 158, "encryption", &encryption_shortcut,SOURCE_CMD_STRICT },
|
||||
|
||||
/* options for backward compatibility */
|
||||
{ 's', 136, "time", &target_time, SOURCE_CMD_STRICT },
|
||||
@@ -725,8 +724,13 @@ static void encryption_init(void)
|
||||
if (instance_config.encryption)
|
||||
{
|
||||
if (!instance_config.remote.host)
|
||||
elog(ERROR, "Encryp;tion is upported only for remote backups");
|
||||
elog(ERROR, "Encryption is supported only for remote backups");
|
||||
|
||||
current.encrypted = true;
|
||||
}
|
||||
|
||||
if (current.encrypted)
|
||||
{
|
||||
fio_crypto_init();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,6 +302,7 @@ struct pgBackup
|
||||
bool stream; /* Was this backup taken in stream mode?
|
||||
* i.e. does it include all needed WAL files? */
|
||||
bool from_replica; /* Was this backup taken from replica */
|
||||
bool encrypted; /* Was this backup encrypted */
|
||||
time_t parent_backup; /* Identifier of the previous backup.
|
||||
* Which is basic backup for this
|
||||
* incremental backup. */
|
||||
@@ -466,6 +467,9 @@ extern bool heapallindexed;
|
||||
/* current settings */
|
||||
extern pgBackup current;
|
||||
|
||||
/* current backup */
|
||||
extern pgBackup* current_backup;
|
||||
|
||||
/* argv of the process */
|
||||
extern char** commands_args;
|
||||
|
||||
|
||||
@@ -522,6 +522,8 @@ restore_backup(pgBackup *backup, parray *dest_external_dirs, parray *dest_files)
|
||||
restore_files_arg *threads_args;
|
||||
bool restore_isok = true;
|
||||
|
||||
current_backup = backup;
|
||||
|
||||
if (backup->status != BACKUP_STATUS_OK &&
|
||||
backup->status != BACKUP_STATUS_DONE)
|
||||
elog(ERROR, "Backup %s cannot be restored because it is not valid",
|
||||
|
||||
+3
-1
@@ -54,6 +54,8 @@ pgBackupValidate(pgBackup *backup)
|
||||
validate_files_arg *threads_args;
|
||||
int i;
|
||||
|
||||
current_backup = backup;
|
||||
|
||||
/* Check backup version */
|
||||
if (parse_program_version(backup->program_version) > parse_program_version(PROGRAM_VERSION))
|
||||
elog(ERROR, "pg_probackup binary version is %s, but backup %s version is %s. "
|
||||
@@ -257,7 +259,7 @@ pgBackupValidateFiles(void *arg)
|
||||
crc = pgFileGetCRC(file->path,
|
||||
arguments->backup_version <= 20021 ||
|
||||
arguments->backup_version >= 20025,
|
||||
true, NULL, FIO_LOCAL_HOST, file->is_datafile && instance_config.encryption);
|
||||
true, NULL, FIO_LOCAL_HOST, file->is_datafile && current_backup->encrypted);
|
||||
if (crc != file->crc)
|
||||
{
|
||||
elog(WARNING, "Invalid CRC of backup file \"%s\" : %X. Expected %X",
|
||||
|
||||
Reference in New Issue
Block a user