You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2026-05-22 10:15:16 +02:00
Auto-select backup set on restore when time target is specified.
Auto-selection is performed only when --set is not specified. If a backup set for the given target time cannot not be found, the latest (default) backup set will be used. Currently a limited number of date formats are recognized and timezone names are not allowed, only timezone offsets.
This commit is contained in:
committed by
David Steele
parent
f46d1fa74c
commit
856980ae99
@@ -464,6 +464,10 @@ sub regExpReplaceAll
|
||||
$strLine = $self->regExpReplace($strLine, 'TIMESTAMP-TARGET', " \\-\\-target\\=\\\".*UTC", "[^\\\"]+UTC\$");
|
||||
$strLine = $self->regExpReplace($strLine, 'TIMESTAMP-TARGET', "^recovery_target_time \\= \\'.*UTC", "[^\\']+UTC\$");
|
||||
|
||||
$strLine = $self->regExpReplace($strLine, 'TIMESTAMP-TARGET', "\\, target \\'.*\\+00", "[^\\']+\\+00\$");
|
||||
$strLine = $self->regExpReplace($strLine, 'TIMESTAMP-TARGET', " \\-\\-target\\=\\\".*\\+00", "[^\\\"]+\\+00\$");
|
||||
$strLine = $self->regExpReplace($strLine, 'TIMESTAMP-TARGET', "^recovery_target_time \\= \\'.*\\+00", "[^\\']+\\+00\$");
|
||||
|
||||
# Full test xid-based recovery (this expressions only work when time-based expressions above have already been applied
|
||||
$strLine = $self->regExpReplace($strLine, 'XID-TARGET', "\\, target \\'[0-9]+", "[0-9]+\$");
|
||||
$strLine = $self->regExpReplace($strLine, 'XID-TARGET', " \\-\\-target\\=\\\"[0-9]+", "[0-9]+\$");
|
||||
|
||||
@@ -1537,6 +1537,7 @@ sub restore
|
||||
$strOptionalParam,
|
||||
$bTablespace,
|
||||
$strUser,
|
||||
$strBackupExpected,
|
||||
) =
|
||||
logDebugParam
|
||||
(
|
||||
@@ -1557,6 +1558,7 @@ sub restore
|
||||
{name => 'strOptionalParam', optional => true},
|
||||
{name => 'bTablespace', optional => true},
|
||||
{name => 'strUser', optional => true},
|
||||
{name => 'strBackupExpected', optional => true},
|
||||
);
|
||||
|
||||
# Build link map options
|
||||
@@ -1593,10 +1595,15 @@ sub restore
|
||||
|
||||
if (!defined($rhExpectedManifest))
|
||||
{
|
||||
if (!defined($strBackupExpected))
|
||||
{
|
||||
$strBackupExpected = $strBackup eq 'latest' ? $oHostBackup->backupLast() : $strBackup;
|
||||
}
|
||||
|
||||
# Load the manifest
|
||||
my $oExpectedManifest = new pgBackRest::Manifest(
|
||||
storageRepo()->pathGet(
|
||||
STORAGE_REPO_BACKUP . qw{/} . ($strBackup eq 'latest' ? $oHostBackup->backupLast() : $strBackup) . qw{/} .
|
||||
STORAGE_REPO_BACKUP . qw{/} . $strBackupExpected. qw{/} .
|
||||
FILE_MANIFEST),
|
||||
{strCipherPass => $oHostBackup->cipherPassManifest()});
|
||||
|
||||
|
||||
@@ -543,11 +543,11 @@ sub run
|
||||
$oHostDbMaster->start();
|
||||
}
|
||||
|
||||
# Setup the time target
|
||||
# Setup the time targets
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
$oHostDbMaster->sqlExecute("update test set message = '$strTimeMessage'");
|
||||
$oHostDbMaster->sqlWalRotate();
|
||||
my $strTimeTarget = $oHostDbMaster->sqlSelectOne("select to_char(current_timestamp, 'YYYY-MM-DD HH24:MI:SS.US TZ')");
|
||||
my $strTimeTarget = $oHostDbMaster->sqlSelectOne("select current_timestamp");
|
||||
&log(INFO, " time target is ${strTimeTarget}");
|
||||
|
||||
# Incr backup - fail on archive_mode=always when version >= 9.5
|
||||
@@ -904,18 +904,19 @@ sub run
|
||||
$oHostDbMaster->sqlExecute("update test set message = '$strTimelineMessage'");
|
||||
}
|
||||
|
||||
# Restore (restore type = time, inclusive) - there is no exclusive time test because I can't find a way to find the
|
||||
# exact commit time of a transaction.
|
||||
# Restore (restore type = time, inclusive, automatically select backup) - there is no exclusive time test because I can't
|
||||
# find a way to find the exact commit time of a transaction.
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
&log(INFO, ' testing recovery type = ' . CFGOPTVAL_RESTORE_TYPE_TIME);
|
||||
|
||||
$oHostDbMaster->clusterStop();
|
||||
|
||||
$oHostDbMaster->restore(
|
||||
undef, $strFullBackup,
|
||||
undef, cfgDefOptionDefault(CFGCMD_RESTORE, CFGOPT_SET),
|
||||
{bDelta => true, strType => CFGOPTVAL_RESTORE_TYPE_TIME, strTarget => $strTimeTarget,
|
||||
strTargetAction => $oHostDbMaster->pgVersion() >= PG_VERSION_91 ? 'promote' : undef,
|
||||
strTargetTimeline => $oHostDbMaster->pgVersion() >= PG_VERSION_12 ? 'current' : undef});
|
||||
strTargetTimeline => $oHostDbMaster->pgVersion() >= PG_VERSION_12 ? 'current' : undef,
|
||||
strBackupExpected => $strFullBackup});
|
||||
|
||||
$oHostDbMaster->clusterStart();
|
||||
$oHostDbMaster->sqlSelectOneTest('select message from test', $strTimeMessage);
|
||||
|
||||
Reference in New Issue
Block a user