Skip to content

Commit 77bb254

Browse files
committed
Issue 52: --no-validate flag for 'backup' command, also allow DONE backup to be a parent of incremental backup
1 parent df0cd65 commit 77bb254

File tree

6 files changed

+23
-20
lines changed

6 files changed

+23
-20
lines changed

src/backup.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ do_backup_instance(void)
922922
* Entry point of pg_probackup BACKUP subcommand.
923923
*/
924924
int
925-
do_backup(time_t start_time)
925+
do_backup(time_t start_time, bool no_validate)
926926
{
927927
/* PGDATA and BACKUP_MODE are always required */
928928
if (instance_config.pgdata == NULL)
@@ -1060,7 +1060,8 @@ do_backup(time_t start_time)
10601060
//elog(LOG, "Backup completed. Total bytes : " INT64_FORMAT "",
10611061
// current.data_bytes);
10621062

1063-
pgBackupValidate(&current);
1063+
if (!no_validate)
1064+
pgBackupValidate(&current);
10641065

10651066
elog(INFO, "Backup %s completed", base36enc(current.start_time));
10661067

src/catalog.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,8 @@ catalog_get_last_data_backup(parray *backup_list, TimeLineID tli)
453453
{
454454
backup = (pgBackup *) parray_get(backup_list, (size_t) i);
455455

456-
if (backup->status == BACKUP_STATUS_OK && backup->tli == tli)
456+
if ((backup->status == BACKUP_STATUS_OK ||
457+
backup->status == BACKUP_STATUS_DONE) && backup->tli == tli)
457458
return backup;
458459
}
459460

src/help.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ help_pg_probackup(void)
118118
printf(_(" [--master-db=db_name] [--master-host=host_name]\n"));
119119
printf(_(" [--master-port=port] [--master-user=user_name]\n"));
120120
printf(_(" [--replica-timeout=timeout]\n"));
121-
printf(_(" [--skip-block-validation]\n"));
121+
printf(_(" [--no-validate] [--skip-block-validation]\n"));
122122
printf(_(" [--external-dirs=external-directory-path]\n"));
123123

124124
printf(_("\n %s restore -B backup-path --instance=instance_name\n"), PROGRAM_NAME);
@@ -212,7 +212,7 @@ help_backup(void)
212212
printf(_(" [--master-db=db_name] [--master-host=host_name]\n"));
213213
printf(_(" [--master-port=port] [--master-user=user_name]\n"));
214214
printf(_(" [--replica-timeout=timeout]\n"));
215-
printf(_(" [--skip-block-validation]\n"));
215+
printf(_(" [--no-validate] [--skip-block-validation]\n"));
216216
printf(_(" [-E external-dirs=external-directory-path]\n\n"));
217217

218218
printf(_(" -B, --backup-path=backup-path location of the backup storage area\n"));
@@ -226,6 +226,7 @@ help_backup(void)
226226
printf(_(" -j, --threads=NUM number of parallel threads\n"));
227227
printf(_(" --archive-timeout=timeout wait timeout for WAL segment archiving (default: 5min)\n"));
228228
printf(_(" --progress show progress\n"));
229+
printf(_(" --no-validate disable validation after backup\n"));
229230
printf(_(" --skip-block-validation set to validate only file-level checksum\n"));
230231
printf(_(" -E --external-dirs=external-directory-path\n"));
231232
printf(_(" backup some directories not from pgdata \n"));

src/pg_probackup.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static char *target_action = NULL;
8585
static pgRecoveryTarget *recovery_target_options = NULL;
8686

8787
bool restore_as_replica = false;
88-
bool restore_no_validate = false;
88+
bool no_validate = false;
8989

9090
bool skip_block_validation = false;
9191
bool skip_external_dirs = false;
@@ -158,7 +158,7 @@ static ConfigOption cmd_options[] =
158158
{ 's', 141, "recovery-target-name", &target_name, SOURCE_CMD_STRICT },
159159
{ 's', 142, "recovery-target-action", &target_action, SOURCE_CMD_STRICT },
160160
{ 'b', 'R', "restore-as-replica", &restore_as_replica, SOURCE_CMD_STRICT },
161-
{ 'b', 143, "no-validate", &restore_no_validate, SOURCE_CMD_STRICT },
161+
{ 'b', 143, "no-validate", &no_validate, SOURCE_CMD_STRICT },
162162
{ 's', 144, "lsn", &target_lsn, SOURCE_CMD_STRICT },
163163
{ 'b', 154, "skip-block-validation", &skip_block_validation, SOURCE_CMD_STRICT },
164164
{ 'b', 156, "skip-external-dirs", &skip_external_dirs, SOURCE_CMD_STRICT },
@@ -474,7 +474,7 @@ main(int argc, char *argv[])
474474
/* parse all recovery target options into recovery_target_options structure */
475475
recovery_target_options = parseRecoveryTargetOptions(target_time, target_xid,
476476
target_inclusive, target_tli, target_lsn, target_immediate,
477-
target_name, target_action, restore_no_validate);
477+
target_name, target_action, no_validate);
478478
}
479479

480480
if (num_threads < 1)
@@ -508,7 +508,7 @@ main(int argc, char *argv[])
508508
PROGRAM_VERSION, base36enc(start_time), backup_mode, instance_name,
509509
stream_wal ? "true" : "false", is_remote_backup ? "true" : "false");
510510

511-
return do_backup(start_time);
511+
return do_backup(start_time, no_validate);
512512
}
513513
case RESTORE_CMD:
514514
return do_restore_or_validate(current.backup_id,

src/pg_probackup.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ typedef struct pgRecoveryTarget
291291
bool recovery_target_immediate;
292292
const char *recovery_target_name;
293293
const char *recovery_target_action;
294-
bool restore_no_validate;
294+
bool no_validate;
295295
} pgRecoveryTarget;
296296

297297
typedef struct
@@ -406,7 +406,7 @@ extern pgBackup current;
406406
extern const char *pgdata_exclude_dir[];
407407

408408
/* in backup.c */
409-
extern int do_backup(time_t start_time);
409+
extern int do_backup(time_t start_time, bool no_validate);
410410
extern BackupMode parse_backup_mode(const char *value);
411411
extern const char *deparse_backup_mode(BackupMode mode);
412412
extern void process_block_change(ForkNumber forknum, RelFileNode rnode,
@@ -427,7 +427,7 @@ extern pgRecoveryTarget *parseRecoveryTargetOptions(
427427
const char *target_time, const char *target_xid,
428428
const char *target_inclusive, TimeLineID target_tli, const char* target_lsn,
429429
bool target_immediate, const char *target_name,
430-
const char *target_action, bool restore_no_validate);
430+
const char *target_action, bool no_validate);
431431

432432
/* in merge.c */
433433
extern void do_merge(time_t backup_id);

src/restore.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
125125
current_backup->status == BACKUP_STATUS_ORPHAN ||
126126
current_backup->status == BACKUP_STATUS_CORRUPT ||
127127
current_backup->status == BACKUP_STATUS_RUNNING)
128-
&& !rt->restore_no_validate)
128+
&& !rt->no_validate)
129129
elog(WARNING, "Backup %s has status: %s",
130130
base36enc(current_backup->start_time), status2str(current_backup->status));
131131
else
@@ -308,7 +308,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
308308
parray_append(parent_chain, base_full_backup);
309309

310310
/* for validation or restore with enabled validation */
311-
if (!is_restore || !rt->restore_no_validate)
311+
if (!is_restore || !rt->no_validate)
312312
{
313313
if (dest_backup->backup_mode != BACKUP_MODE_FULL)
314314
elog(INFO, "Validating parents for backup %s", base36enc(dest_backup->start_time));
@@ -395,7 +395,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
395395
*/
396396
if (dest_backup->status == BACKUP_STATUS_OK)
397397
{
398-
if (rt->restore_no_validate)
398+
if (rt->no_validate)
399399
elog(INFO, "Backup %s is used without validation.", base36enc(dest_backup->start_time));
400400
else
401401
elog(INFO, "Backup %s is valid.", base36enc(dest_backup->start_time));
@@ -425,7 +425,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
425425
* Backup was locked during validation if no-validate wasn't
426426
* specified.
427427
*/
428-
if (rt->restore_no_validate && !lock_backup(backup))
428+
if (rt->no_validate && !lock_backup(backup))
429429
elog(ERROR, "Cannot lock backup directory");
430430

431431
restore_backup(backup, dest_backup->external_dir_str);
@@ -993,7 +993,7 @@ parseRecoveryTargetOptions(const char *target_time,
993993
bool target_immediate,
994994
const char *target_name,
995995
const char *target_action,
996-
bool restore_no_validate)
996+
bool no_validate)
997997
{
998998
time_t dummy_time;
999999
TransactionId dummy_xid;
@@ -1022,7 +1022,7 @@ parseRecoveryTargetOptions(const char *target_time,
10221022
rt->recovery_target_immediate = false;
10231023
rt->recovery_target_name = NULL;
10241024
rt->recovery_target_action = NULL;
1025-
rt->restore_no_validate = false;
1025+
rt->no_validate = false;
10261026

10271027
/* parse given options */
10281028
if (target_time)
@@ -1080,9 +1080,9 @@ parseRecoveryTargetOptions(const char *target_time,
10801080
rt->recovery_target_immediate = target_immediate;
10811081
}
10821082

1083-
if (restore_no_validate)
1083+
if (no_validate)
10841084
{
1085-
rt->restore_no_validate = restore_no_validate;
1085+
rt->no_validate = no_validate;
10861086
}
10871087

10881088
if (target_name)

0 commit comments

Comments
 (0)