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

Commit04ebf18

Browse files
committed
Save encrypted property in backup control file
1 parented790f4 commit04ebf18

File tree

9 files changed

+34
-19
lines changed

9 files changed

+34
-19
lines changed

‎src/archive.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ push_wal_file(const char *from_path, const char *to_path, bool is_compress,
179179
snprintf(to_path_temp,sizeof(to_path_temp),"%s.partial",gz_to_path);
180180

181181
gz_out=fio_gzopen(to_path_temp,PG_BINARY_W,instance_config.compress_level,FIO_BACKUP_HOST,
182-
instance_config.encryption);
182+
current_backup->encrypted);
183183
if (gz_out==NULL)
184184
elog(ERROR,"Cannot open destination temporary WAL file \"%s\": %s",
185185
to_path_temp,strerror(errno));
@@ -194,7 +194,7 @@ push_wal_file(const char *from_path, const char *to_path, bool is_compress,
194194
if (out_fd<0)
195195
elog(ERROR,"Cannot open destination temporary WAL file \"%s\": %s",
196196
to_path_temp,strerror(errno));
197-
out=fio_fdopen(to_path_temp,out_fd,PG_BINARY_W,instance_config.encryption);
197+
out=fio_fdopen(to_path_temp,out_fd,PG_BINARY_W,current_backup->encrypted);
198198
}
199199

200200
/* copy content */
@@ -336,7 +336,7 @@ get_wal_file(const char *from_path, const char *to_path)
336336
/* open file for read */
337337
if (!is_decompress)
338338
{
339-
in=fio_fopen(from_path,PG_BINARY_R,FIO_BACKUP_HOST,instance_config.encryption);
339+
in=fio_fopen(from_path,PG_BINARY_R,FIO_BACKUP_HOST,current_backup->encrypted);
340340
if (in==NULL)
341341
elog(ERROR,"Cannot open source WAL file \"%s\": %s",
342342
from_path,strerror(errno));
@@ -345,7 +345,7 @@ get_wal_file(const char *from_path, const char *to_path)
345345
else
346346
{
347347
gz_in=fio_gzopen(gz_from_path,PG_BINARY_R,Z_DEFAULT_COMPRESSION,
348-
FIO_BACKUP_HOST,instance_config.encryption);
348+
FIO_BACKUP_HOST,current_backup->encrypted);
349349
if (gz_in==NULL)
350350
elog(ERROR,"Cannot open compressed WAL file \"%s\": %s",
351351
gz_from_path,strerror(errno));
@@ -500,7 +500,7 @@ fileEqualCRC(const char *path1, const char *path2, bool path2_is_compressed)
500500
gzFilegz_in=NULL;
501501

502502
INIT_FILE_CRC32(true,crc2);
503-
gz_in=fio_gzopen(path2,PG_BINARY_R,Z_DEFAULT_COMPRESSION,FIO_BACKUP_HOST,instance_config.encryption);
503+
gz_in=fio_gzopen(path2,PG_BINARY_R,Z_DEFAULT_COMPRESSION,FIO_BACKUP_HOST,current_backup->encrypted);
504504
if (gz_in==NULL)
505505
/* File cannot be read */
506506
elog(ERROR,
@@ -531,7 +531,7 @@ fileEqualCRC(const char *path1, const char *path2, bool path2_is_compressed)
531531
else
532532
#endif
533533
{
534-
crc2=pgFileGetCRC(path2, true, true,NULL,FIO_BACKUP_HOST,instance_config.encryption);
534+
crc2=pgFileGetCRC(path2, true, true,NULL,FIO_BACKUP_HOST,current_backup->encrypted);
535535
}
536536

537537
/* Get checksum of original file */

‎src/catalog.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
518518
fio_fprintf(out,"#Configuration\n");
519519
fio_fprintf(out,"backup-mode = %s\n",pgBackupGetBackupMode(backup));
520520
fio_fprintf(out,"stream = %s\n",backup->stream ?"true" :"false");
521+
fio_fprintf(out,"encrypted = %s\n",backup->encrypted ?"true" :"false");
521522
fio_fprintf(out,"compress-alg = %s\n",
522523
deparse_compress_alg(backup->compress_alg));
523524
fio_fprintf(out,"compress-level = %d\n",backup->compress_level);
@@ -702,6 +703,7 @@ readBackupControlFile(const char *path)
702703
{'s',0,"program-version",&program_version,SOURCE_FILE_STRICT},
703704
{'s',0,"server-version",&server_version,SOURCE_FILE_STRICT},
704705
{'b',0,"stream",&backup->stream,SOURCE_FILE_STRICT},
706+
{'b',0,"encrypted",&backup->encrypted,SOURCE_FILE_STRICT},
705707
{'s',0,"status",&status,SOURCE_FILE_STRICT},
706708
{'s',0,"parent-backup-id",&parent_backup,SOURCE_FILE_STRICT},
707709
{'s',0,"compress-alg",&compress_alg,SOURCE_FILE_STRICT},
@@ -933,6 +935,7 @@ pgBackupInit(pgBackup *backup)
933935
backup->checksum_version=0;
934936

935937
backup->stream= false;
938+
backup->encrypted= false;
936939
backup->from_replica= false;
937940
backup->parent_backup=INVALID_BACKUP_ID;
938941
backup->parent_backup_link=NULL;

‎src/data.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ backup_data_file(backup_files_arg* arguments,
598598
nblocks=file->size/BLCKSZ;
599599

600600
/* open backup file for write */
601-
out=fio_fopen(to_path,PG_BINARY_W,FIO_BACKUP_HOST,instance_config.encryption);
601+
out=fio_fopen(to_path,PG_BINARY_W,FIO_BACKUP_HOST,current_backup->encrypted);
602602
if (out==NULL)
603603
{
604604
interrno_tmp=errno;
@@ -727,7 +727,7 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
727727
if (file->write_size!=BYTES_INVALID)
728728
{
729729
/* open backup mode file for read */
730-
in=fio_fopen(file->path,PG_BINARY_R,FIO_LOCAL_HOST,file->is_datafile&&instance_config.encryption);
730+
in=fio_fopen(file->path,PG_BINARY_R,FIO_LOCAL_HOST,file->is_datafile&&current_backup->encrypted);
731731
if (in==NULL)
732732
{
733733
elog(ERROR,"Cannot open backup file \"%s\": %s",file->path,
@@ -963,7 +963,7 @@ copy_file(fio_location from_location, const char *to_root,
963963
file->write_size=0;
964964

965965
/* open backup mode file for read */
966-
in=fio_fopen(file->path,PG_BINARY_R,from_location,file->is_datafile&&instance_config.encryption&&from_location==FIO_BACKUP_HOST);
966+
in=fio_fopen(file->path,PG_BINARY_R,from_location,file->is_datafile&&current_backup->encrypted&&from_location==FIO_BACKUP_HOST);
967967
if (in==NULL)
968968
{
969969
FIN_FILE_CRC32(true,crc);
@@ -988,7 +988,7 @@ copy_file(fio_location from_location, const char *to_root,
988988

989989
/* open backup file for write */
990990
join_path_components(to_path,to_root,file->rel_path);
991-
out=fio_fopen(to_path,PG_BINARY_W,to_location,file->is_datafile&&instance_config.encryption&&to_location==FIO_BACKUP_HOST);
991+
out=fio_fopen(to_path,PG_BINARY_W,to_location,file->is_datafile&&current_backup->encrypted&&to_location==FIO_BACKUP_HOST);
992992
if (out==NULL)
993993
{
994994
interrno_tmp=errno;
@@ -1272,7 +1272,7 @@ check_file_pages(pgFile *file, XLogRecPtr stop_lsn, uint32 checksum_version,
12721272

12731273
elog(VERBOSE,"Validate relation blocks for file %s",file->path);
12741274

1275-
in=fio_fopen(file->path,PG_BINARY_R,FIO_BACKUP_HOST,instance_config.encryption);
1275+
in=fio_fopen(file->path,PG_BINARY_R,FIO_BACKUP_HOST,current_backup->encrypted);
12761276
if (in==NULL)
12771277
{
12781278
if (errno==ENOENT)

‎src/merge.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ merge_files(void *arg)
513513
* Recalculate crc for backup prior to 2.0.25.
514514
*/
515515
if (parse_program_version(from_backup->program_version)<20025)
516-
file->crc=pgFileGetCRC(to_file_path, true, true,NULL,FIO_LOCAL_HOST,instance_config.encryption);
516+
file->crc=pgFileGetCRC(to_file_path, true, true,NULL,FIO_LOCAL_HOST,to_backup->encrypted);
517517
/* Otherwise just get it from the previous file */
518518
else
519519
file->crc=to_file->crc;
@@ -637,7 +637,7 @@ merge_files(void *arg)
637637
* do that.
638638
*/
639639
file->write_size=pgFileSize(to_file_path);
640-
file->crc=pgFileGetCRC(to_file_path, true, true,NULL,FIO_LOCAL_HOST,instance_config.encryption);
640+
file->crc=pgFileGetCRC(to_file_path, true, true,NULL,FIO_LOCAL_HOST,to_backup->encrypted);
641641
}
642642
}
643643
elseif (file->external_dir_num)

‎src/parsexlog.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
736736
return-1;
737737
}
738738
reader_data->xlogfile=fio_fdopen(reader_data->xlogpath,fd,"rb",
739-
instance_config.encryption&& !stream_wal);
739+
current_backup->encrypted&& !current_backup->stream);
740740
}
741741
#ifdefHAVE_LIBZ
742742
/* Try to open compressed WAL segment */
@@ -752,7 +752,7 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr,
752752
reader_data->xlogexists= true;
753753
reader_data->gz_xlogfile=fio_gzopen(reader_data->gz_xlogpath,
754754
"rb",-1,FIO_BACKUP_HOST,
755-
instance_config.encryption&& !stream_wal);
755+
current_backup->encrypted&& !current_backup->stream);
756756
if (reader_data->gz_xlogfile==NULL)
757757
{
758758
elog(WARNING,"Thread [%d]: Could not open compressed WAL segment \"%s\": %s",

‎src/pg_probackup.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ ShowFormat show_format = SHOW_PLAIN;
127127

128128
/* current settings */
129129
pgBackupcurrent;
130+
pgBackup*current_backup=&current;
130131
staticProbackupSubcmdbackup_subcmd=NO_CMD;
131132

132133
staticboolhelp_opt= false;
@@ -197,8 +198,6 @@ static ConfigOption cmd_options[] =
197198
{'b',152,"overwrite",&file_overwrite,SOURCE_CMD_STRICT },
198199
/* show options */
199200
{'f',153,"format",opt_show_format,SOURCE_CMD_STRICT },
200-
/* encryption options */
201-
{'b',158,"encryption",&encryption_shortcut,SOURCE_CMD_STRICT },
202201

203202
/* options for backward compatibility */
204203
{'s',136,"time",&target_time,SOURCE_CMD_STRICT },
@@ -725,8 +724,13 @@ static void encryption_init(void)
725724
if (instance_config.encryption)
726725
{
727726
if (!instance_config.remote.host)
728-
elog(ERROR,"Encryp;tion isupported only for remote backups");
727+
elog(ERROR,"Encryption issupported only for remote backups");
729728

729+
current.encrypted= true;
730+
}
731+
732+
if (current.encrypted)
733+
{
730734
fio_crypto_init();
731735
}
732736
}

‎src/pg_probackup.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ struct pgBackup
302302
boolstream;/* Was this backup taken in stream mode?
303303
* i.e. does it include all needed WAL files? */
304304
boolfrom_replica;/* Was this backup taken from replica */
305+
boolencrypted;/* Was this backup encrypted */
305306
time_tparent_backup;/* Identifier of the previous backup.
306307
* Which is basic backup for this
307308
* incremental backup. */
@@ -466,6 +467,9 @@ extern bool heapallindexed;
466467
/* current settings */
467468
externpgBackupcurrent;
468469

470+
/* current backup */
471+
externpgBackup*current_backup;
472+
469473
/* argv of the process */
470474
externchar**commands_args;
471475

‎src/restore.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,8 @@ restore_backup(pgBackup *backup, parray *dest_external_dirs, parray *dest_files)
522522
restore_files_arg*threads_args;
523523
boolrestore_isok= true;
524524

525+
current_backup=backup;
526+
525527
if (backup->status!=BACKUP_STATUS_OK&&
526528
backup->status!=BACKUP_STATUS_DONE)
527529
elog(ERROR,"Backup %s cannot be restored because it is not valid",

‎src/validate.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ pgBackupValidate(pgBackup *backup)
5454
validate_files_arg*threads_args;
5555
inti;
5656

57+
current_backup=backup;
58+
5759
/* Check backup version */
5860
if (parse_program_version(backup->program_version)>parse_program_version(PROGRAM_VERSION))
5961
elog(ERROR,"pg_probackup binary version is %s, but backup %s version is %s. "
@@ -257,7 +259,7 @@ pgBackupValidateFiles(void *arg)
257259
crc=pgFileGetCRC(file->path,
258260
arguments->backup_version <=20021||
259261
arguments->backup_version >=20025,
260-
true,NULL,FIO_LOCAL_HOST,file->is_datafile&&instance_config.encryption);
262+
true,NULL,FIO_LOCAL_HOST,file->is_datafile&&current_backup->encrypted);
261263
if (crc!=file->crc)
262264
{
263265
elog(WARNING,"Invalid CRC of backup file \"%s\" : %X. Expected %X",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp