Skip to content

Commit 7eb06cb

Browse files
author
Michael Paquier
committed
Add backup option --validate
This permits to validate a backup that has just been taken. Other backups taken previously are ignored.
1 parent 342496e commit 7eb06cb

File tree

3 files changed

+50
-30
lines changed

3 files changed

+50
-30
lines changed

doc/pg_rman.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ absolute paths; relative paths are not allowed.
243243
do smooth checkpoint then. See also the second argument for
244244
pg_start_backup().
245245

246+
*--validate*::
247+
Validate a backup just after taking it. Other backups taken
248+
previously are ignored.
249+
246250
*--keep-data-generations*=_NUMBER_ / *--keep-data-days*=_DAYS_::
247251
Specify how long backuped data files will be kept.
248252
--keep-data-generations means number of backup generations.
@@ -359,6 +363,7 @@ variables or in configuration file as follows:
359363
-s --with-serverlog WITH_SERVERLOG Yes
360364
-Z --compress-data COMPRESS_DATA Yes
361365
-C --smooth-checkpoint SMOOTH_CHECKPOINT Yes
366+
--validate VALIDATE Yes
362367
--keep-data-generations KEEP_DATA_GENERATIONS Yes
363368
--keep-data-days KEEP_DATA_DAYS Yes
364369
--keep-srvlog-files KEEP_SRVLOG_FILES Yes

expected/option.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Backup options:
2222
-s, --with-serverlog also backup server log files
2323
-Z, --compress-data compress data backup with zlib
2424
-C, --smooth-checkpoint do smooth checkpoint before backup
25+
--validate validate backup after taking it
2526
--keep-data-generations=N keep GENERATION of full data backup
2627
--keep-data-days=DAY keep enough data backup to recover to DAY days age
2728
--keep-arclog-files=NUM keep NUM of archived WAL

pg_rman.c

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static char *target_xid;
4646
static char *target_inclusive;
4747
static TimeLineID target_tli;
4848
static bool is_hard_copy = false;
49+
static bool backup_validate = false;
4950

5051
/* show configuration */
5152
static bool show_all = false;
@@ -56,33 +57,34 @@ static void parse_range(pgBackupRange *range, const char *arg1, const char *arg2
5657
static pgut_option options[] =
5758
{
5859
/* directory options */
59-
{ 's', 'D', "pgdata" , &pgdata , SOURCE_ENV },
60-
{ 's', 'A', "arclog-path" , &arclog_path , SOURCE_ENV },
61-
{ 's', 'B', "backup-path" , &backup_path , SOURCE_ENV },
62-
{ 's', 'S', "srvlog-path" , &srvlog_path , SOURCE_ENV },
60+
{ 's', 'D', "pgdata", &pgdata, SOURCE_ENV },
61+
{ 's', 'A', "arclog-path", &arclog_path, SOURCE_ENV },
62+
{ 's', 'B', "backup-path", &backup_path, SOURCE_ENV },
63+
{ 's', 'S', "srvlog-path", &srvlog_path, SOURCE_ENV },
6364
/* common options */
64-
{ 'b', 'v', "verbose" , &verbose },
65-
{ 'b', 'c', "check" , &check },
65+
{ 'b', 'v', "verbose", &verbose },
66+
{ 'b', 'c', "check", &check },
6667
/* backup options */
67-
{ 'f', 'b', "backup-mode" , opt_backup_mode , SOURCE_ENV },
68-
{ 'b', 's', "with-serverlog" , &current.with_serverlog , SOURCE_ENV },
69-
{ 'b', 'Z', "compress-data" , &current.compress_data , SOURCE_ENV },
70-
{ 'b', 'C', "smooth-checkpoint" , &smooth_checkpoint , SOURCE_ENV },
68+
{ 'f', 'b', "backup-mode", opt_backup_mode, SOURCE_ENV },
69+
{ 'b', 's', "with-serverlog", &current.with_serverlog, SOURCE_ENV },
70+
{ 'b', 'Z', "compress-data", &current.compress_data, SOURCE_ENV },
71+
{ 'b', 'C', "smooth-checkpoint", &smooth_checkpoint, SOURCE_ENV },
7172
/* options with only long name (keep-xxx) */
72-
{ 'i', 1, "keep-data-generations" , &keep_data_generations, SOURCE_ENV },
73-
{ 'i', 2, "keep-data-days" , &keep_data_days , SOURCE_ENV },
74-
{ 'i', 3, "keep-arclog-files" , &keep_arclog_files , SOURCE_ENV },
75-
{ 'i', 4, "keep-arclog-days" , &keep_arclog_days , SOURCE_ENV },
76-
{ 'i', 5, "keep-srvlog-files" , &keep_srvlog_files , SOURCE_ENV },
77-
{ 'i', 6, "keep-srvlog-days" , &keep_srvlog_days , SOURCE_ENV },
73+
{ 'i', 1, "keep-data-generations", &keep_data_generations, SOURCE_ENV },
74+
{ 'i', 2, "keep-data-days", &keep_data_days, SOURCE_ENV },
75+
{ 'i', 3, "keep-arclog-files", &keep_arclog_files, SOURCE_ENV },
76+
{ 'i', 4, "keep-arclog-days", &keep_arclog_days, SOURCE_ENV },
77+
{ 'i', 5, "keep-srvlog-files", &keep_srvlog_files, SOURCE_ENV },
78+
{ 'i', 6, "keep-srvlog-days", &keep_srvlog_days, SOURCE_ENV },
7879
/* restore options */
79-
{ 's', 7, "recovery-target-time" , &target_time , SOURCE_ENV },
80-
{ 's', 8, "recovery-target-xid" , &target_xid , SOURCE_ENV },
81-
{ 's', 9, "recovery-target-inclusive" , &target_inclusive , SOURCE_ENV },
82-
{ 'u', 10, "recovery-target-timeline" , &target_tli , SOURCE_ENV },
83-
{ 'b', 11, "hard-copy" , &is_hard_copy , SOURCE_ENV },
80+
{ 's', 7, "recovery-target-time", &target_time, SOURCE_ENV },
81+
{ 's', 8, "recovery-target-xid", &target_xid, SOURCE_ENV },
82+
{ 's', 9, "recovery-target-inclusive", &target_inclusive, SOURCE_ENV },
83+
{ 'u', 10, "recovery-target-timeline", &target_tli, SOURCE_ENV },
84+
{ 'b', 11, "hard-copy", &is_hard_copy, SOURCE_ENV },
85+
{ 'b', 12, "validate", &backup_validate, SOURCE_ENV },
8486
/* catalog options */
85-
{ 'b', 'a', "show-all" , &show_all },
87+
{ 'b', 'a', "show-all", &show_all },
8688
{ 0 }
8789
};
8890

@@ -178,14 +180,25 @@ main(int argc, char *argv[])
178180
else if (pg_strcasecmp(cmd, "backup") == 0)
179181
{
180182
pgBackupOption bkupopt;
181-
bkupopt.smooth_checkpoint = smooth_checkpoint;
182-
bkupopt.keep_arclog_files = keep_arclog_files;
183-
bkupopt.keep_arclog_days = keep_arclog_days;
184-
bkupopt.keep_srvlog_files = keep_srvlog_files;
185-
bkupopt.keep_srvlog_days = keep_srvlog_days;
186-
bkupopt.keep_data_generations = keep_data_generations;
187-
bkupopt.keep_data_days = keep_data_days;
188-
return do_backup(bkupopt);
183+
int res;
184+
bkupopt.smooth_checkpoint = smooth_checkpoint;
185+
bkupopt.keep_arclog_files = keep_arclog_files;
186+
bkupopt.keep_arclog_days = keep_arclog_days;
187+
bkupopt.keep_srvlog_files = keep_srvlog_files;
188+
bkupopt.keep_srvlog_days = keep_srvlog_days;
189+
bkupopt.keep_data_generations = keep_data_generations;
190+
bkupopt.keep_data_days = keep_data_days;
191+
192+
/* Do the backup */
193+
res = do_backup(bkupopt);
194+
if (res != 0)
195+
return res;
196+
197+
/* If validation has been requested, do it */
198+
range.begin = current.start_time;
199+
range.end = current.start_time + 1;
200+
if (backup_validate)
201+
do_validate(&range);
189202
}
190203
else if (pg_strcasecmp(cmd, "restore") == 0){
191204
return do_restore(target_time, target_xid,
@@ -230,6 +243,7 @@ pgut_help(bool details)
230243
printf(_(" -s, --with-serverlog also backup server log files\n"));
231244
printf(_(" -Z, --compress-data compress data backup with zlib\n"));
232245
printf(_(" -C, --smooth-checkpoint do smooth checkpoint before backup\n"));
246+
printf(_(" --validate validate backup after taking it\n"));
233247
printf(_(" --keep-data-generations=N keep GENERATION of full data backup\n"));
234248
printf(_(" --keep-data-days=DAY keep enough data backup to recover to DAY days age\n"));
235249
printf(_(" --keep-arclog-files=NUM keep NUM of archived WAL\n"));

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