mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2025-01-09 14:45:47 +02:00
partial_restore_type as separate type
This commit is contained in:
parent
454eeac8f8
commit
0ae5a66bfb
@ -609,6 +609,7 @@ main(int argc, char *argv[])
|
||||
restore_params->skip_block_validation = skip_block_validation;
|
||||
restore_params->skip_external_dirs = skip_external_dirs;
|
||||
restore_params->partial_db_list = NULL;
|
||||
restore_params->partial_restore_type = NONE;
|
||||
|
||||
/* handle partial restore parameters */
|
||||
if (datname_exclude_list && datname_include_list)
|
||||
@ -616,16 +617,21 @@ main(int argc, char *argv[])
|
||||
|
||||
if (datname_exclude_list)
|
||||
{
|
||||
restore_params->is_include_list = false;
|
||||
restore_params->partial_restore_type = EXCLUDE;
|
||||
restore_params->partial_db_list = datname_exclude_list;
|
||||
}
|
||||
else if (datname_include_list)
|
||||
{
|
||||
restore_params->is_include_list = true;
|
||||
restore_params->partial_restore_type = INCLUDE;
|
||||
restore_params->partial_db_list = datname_include_list;
|
||||
}
|
||||
}
|
||||
|
||||
/* sanity */
|
||||
if (backup_subcmd == VALIDATE_CMD && restore_params->no_validate)
|
||||
elog(ERROR, "You cannot specify \"--no-validate\" option with the \"%s\" command",
|
||||
command_name);
|
||||
|
||||
if (num_threads < 1)
|
||||
num_threads = 1;
|
||||
|
||||
@ -663,8 +669,15 @@ main(int argc, char *argv[])
|
||||
restore_params);
|
||||
case VALIDATE_CMD:
|
||||
if (current.backup_id == 0 && target_time == 0 && target_xid == 0 && !target_lsn)
|
||||
{
|
||||
/* sanity */
|
||||
if (datname_exclude_list || datname_include_list)
|
||||
elog(ERROR, "You must specify parameter (-i, --backup-id) for partial validation");
|
||||
|
||||
return do_validate_all();
|
||||
}
|
||||
else
|
||||
/* PITR validation and, optionally, partial validation */
|
||||
return do_restore_or_validate(current.backup_id,
|
||||
recovery_target_options,
|
||||
restore_params);
|
||||
@ -797,7 +810,10 @@ opt_datname_include_list(ConfigOption *opt, const char *arg)
|
||||
|
||||
dbname = pgut_malloc(strlen(arg) + 1);
|
||||
|
||||
/* TODO add sanity for database name */
|
||||
if (strcmp(dbname, "tempate0") == 0 ||
|
||||
strcmp(dbname, "tempate1") == 0)
|
||||
elog(ERROR, "Databases 'template0' and 'template1' cannot be used for partial restore or validation");
|
||||
|
||||
strcpy(dbname, arg);
|
||||
|
||||
parray_append(datname_include_list, dbname);
|
||||
|
@ -91,6 +91,13 @@ typedef struct db_map_entry
|
||||
char *datname;
|
||||
} db_map_entry;
|
||||
|
||||
typedef enum PartialRestoreType
|
||||
{
|
||||
NONE,
|
||||
INCLUDE,
|
||||
EXCLUDE,
|
||||
} PartialRestoreType;
|
||||
|
||||
typedef enum CompressAlg
|
||||
{
|
||||
NOT_DEFINED_COMPRESS = 0,
|
||||
@ -348,7 +355,7 @@ typedef struct pgRestoreParams
|
||||
bool skip_block_validation;
|
||||
|
||||
/* options for partial restore */
|
||||
bool is_include_list;
|
||||
PartialRestoreType partial_restore_type;
|
||||
parray *partial_db_list;
|
||||
} pgRestoreParams;
|
||||
|
||||
@ -512,8 +519,9 @@ extern pgRecoveryTarget *parseRecoveryTargetOptions(
|
||||
const char *target_inclusive, TimeLineID target_tli, const char* target_lsn,
|
||||
const char *target_stop, const char *target_name,
|
||||
const char *target_action);
|
||||
|
||||
extern parray *get_dbOid_exclude_list(pgBackup *backup, parray *files,
|
||||
parray *datname_list, bool partial_restore_type);
|
||||
parray *datname_list, PartialRestoreType partial_restore_type);
|
||||
|
||||
/* in merge.c */
|
||||
extern void do_merge(time_t backup_id);
|
||||
|
@ -459,7 +459,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
|
||||
*/
|
||||
if (params->partial_db_list)
|
||||
dbOid_exclude_list = get_dbOid_exclude_list(dest_backup, dest_files, params->partial_db_list,
|
||||
params->is_include_list);
|
||||
params->partial_restore_type);
|
||||
|
||||
/*
|
||||
* Restore dest_backup internal directories.
|
||||
@ -1183,7 +1183,7 @@ parseRecoveryTargetOptions(const char *target_time,
|
||||
*/
|
||||
parray *
|
||||
get_dbOid_exclude_list(pgBackup *backup, parray *files,
|
||||
parray *datname_list, bool is_include_list)
|
||||
parray *datname_list, PartialRestoreType partial_restore_type)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
@ -1233,9 +1233,9 @@ get_dbOid_exclude_list(pgBackup *backup, parray *files,
|
||||
* So we have a list of datnames and a database_map for it.
|
||||
* We must construct a list of dbOids to exclude.
|
||||
*/
|
||||
if (is_include_list)
|
||||
if (partial_restore_type == INCLUDE)
|
||||
{
|
||||
/* For 'include' keep dbOid of every datname NOT specified by user */
|
||||
/* For 'include', keep dbOid of every datname NOT specified by user */
|
||||
for (i = 0; i < parray_num(datname_list); i++)
|
||||
{
|
||||
bool found_match = false;
|
||||
@ -1270,9 +1270,9 @@ get_dbOid_exclude_list(pgBackup *backup, parray *files,
|
||||
parray_append(dbOid_exclude_list, &db_entry->dbOid);
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (partial_restore_type == EXCLUDE)
|
||||
{
|
||||
/* For exclude job is easier, find dbOid for every specified datname */
|
||||
/* For exclude, job is easier - find dbOid for every specified datname */
|
||||
for (i = 0; i < parray_num(datname_list); i++)
|
||||
{
|
||||
bool found_match = false;
|
||||
|
@ -109,7 +109,7 @@ pgBackupValidate(pgBackup *backup, pgRestoreParams *params)
|
||||
|
||||
if (params && params->partial_db_list)
|
||||
dbOid_exclude_list = get_dbOid_exclude_list(backup, files, params->partial_db_list,
|
||||
params->is_include_list);
|
||||
params->partial_restore_type);
|
||||
|
||||
/* setup threads */
|
||||
for (i = 0; i < parray_num(files); i++)
|
||||
|
Loading…
Reference in New Issue
Block a user