Skip to content

Commit d92434f

Browse files
committed
Refactoring of restore and validate options.
Collect them into pgRestoreParams structure
1 parent f4790b6 commit d92434f

File tree

3 files changed

+82
-67
lines changed

3 files changed

+82
-67
lines changed

src/pg_probackup.c

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ static char *target_name = NULL;
8989
static char *target_action = NULL;
9090

9191
static pgRecoveryTarget *recovery_target_options = NULL;
92+
static pgRestoreParams *restore_params = NULL;
9293

9394
bool restore_as_replica = false;
9495
bool no_validate = false;
@@ -598,7 +599,32 @@ main(int argc, char *argv[])
598599
target_inclusive, target_tli, target_lsn,
599600
(target_stop != NULL) ? target_stop :
600601
(target_immediate) ? "immediate" : NULL,
601-
target_name, target_action, no_validate);
602+
target_name, target_action);
603+
604+
/* keep all params in one structure */
605+
restore_params = pgut_new(pgRestoreParams);
606+
restore_params->is_restore = (backup_subcmd == RESTORE_CMD);
607+
restore_params->no_validate = no_validate;
608+
restore_params->restore_as_replica = restore_as_replica;
609+
restore_params->skip_block_validation = skip_block_validation;
610+
restore_params->skip_external_dirs = skip_external_dirs;
611+
612+
/* handle partial restore parameters */
613+
if (datname_exclude_list && datname_include_list)
614+
elog(ERROR, "You cannot specify '--db-include' and '--db-exclude' together");
615+
616+
if (datname_exclude_list)
617+
{
618+
restore_params->is_include_list = false;
619+
restore_params->partial_db_list = datname_exclude_list;
620+
}
621+
else if (datname_include_list)
622+
{
623+
restore_params->is_include_list = true;
624+
restore_params->partial_db_list = datname_include_list;
625+
}
626+
627+
602628
}
603629

604630
if (num_threads < 1)
@@ -633,37 +659,16 @@ main(int argc, char *argv[])
633659
return do_backup(start_time, no_validate);
634660
}
635661
case RESTORE_CMD:
636-
{
637-
parray *datname_list = NULL;
638-
/* true for 'include', false for 'exclude' */
639-
bool partial_restore_type = false;
640-
641-
if (datname_exclude_list && datname_include_list)
642-
elog(ERROR, "You cannot specify '--db-include' and '--db-exclude' together");
643-
644-
if (datname_exclude_list)
645-
datname_list = datname_exclude_list;
646-
647-
if (datname_include_list)
648-
{
649-
partial_restore_type = true;
650-
datname_list = datname_include_list;
651-
}
652-
return do_restore_or_validate(current.backup_id,
662+
return do_restore_or_validate(current.backup_id,
653663
recovery_target_options,
654-
true,
655-
datname_list,
656-
partial_restore_type);
657-
}
664+
restore_params);
658665
case VALIDATE_CMD:
659666
if (current.backup_id == 0 && target_time == 0 && target_xid == 0)
660667
return do_validate_all();
661668
else
662669
return do_restore_or_validate(current.backup_id,
663670
recovery_target_options,
664-
false,
665-
NULL,
666-
false);
671+
restore_params);
667672
case SHOW_CMD:
668673
return do_show(current.backup_id);
669674
case DELETE_CMD:

src/pg_probackup.h

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,22 @@ typedef struct pgRecoveryTarget
336336
const char *target_stop;
337337
const char *target_name;
338338
const char *target_action;
339-
bool no_validate;
340339
} pgRecoveryTarget;
341340

341+
/* Options needed for restore and validate commands */
342+
typedef struct pgRestoreParams
343+
{
344+
bool is_restore;
345+
bool no_validate;
346+
bool restore_as_replica;
347+
bool skip_external_dirs;
348+
bool skip_block_validation;
349+
350+
/* options for partial restore */
351+
bool is_include_list;
352+
parray *partial_db_list;
353+
} pgRestoreParams;
354+
342355
typedef struct
343356
{
344357
const char *from_root;
@@ -444,11 +457,6 @@ extern char* remote_agent;
444457
extern bool is_ptrack_support;
445458
extern bool exclusive_backup;
446459

447-
/* restore options */
448-
extern bool restore_as_replica;
449-
extern bool skip_block_validation;
450-
extern bool skip_external_dirs;
451-
452460
/* delete options */
453461
extern bool delete_wal;
454462
extern bool delete_expired;
@@ -467,6 +475,7 @@ extern ShowFormat show_format;
467475

468476
/* checkdb options */
469477
extern bool heapallindexed;
478+
extern bool skip_block_validation;
470479

471480
/* current settings */
472481
extern pgBackup current;
@@ -494,17 +503,15 @@ extern char *pg_ptrack_get_block(ConnectionArgs *arguments,
494503
/* in restore.c */
495504
extern int do_restore_or_validate(time_t target_backup_id,
496505
pgRecoveryTarget *rt,
497-
bool is_restore,
498-
parray * datname_list,
499-
bool partial_restore_type);
506+
pgRestoreParams *params);
500507
extern bool satisfy_timeline(const parray *timelines, const pgBackup *backup);
501508
extern bool satisfy_recovery_target(const pgBackup *backup,
502509
const pgRecoveryTarget *rt);
503510
extern pgRecoveryTarget *parseRecoveryTargetOptions(
504511
const char *target_time, const char *target_xid,
505512
const char *target_inclusive, TimeLineID target_tli, const char* target_lsn,
506513
const char *target_stop, const char *target_name,
507-
const char *target_action, bool no_validate);
514+
const char *target_action);
508515

509516
/* in merge.c */
510517
extern void do_merge(time_t backup_id);

0 commit comments

Comments
 (0)