You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-09-02 12:41:14 +03:00
Allow restores to be run against a read-only repository.
Two things needed to be changed: 1) Don't open a log file when log-level-file=off 2) New --no-lock option to suppress lock file creation for restores.
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
<changelog-release date="XXXX-XX-XX" version="0.90" title="UNDER DEVELOPMENT">
|
<changelog-release date="XXXX-XX-XX" version="0.90" title="UNDER DEVELOPMENT">
|
||||||
<release-feature-bullet-list>
|
<release-feature-bullet-list>
|
||||||
<release-feature>
|
<release-feature>
|
||||||
<text></text>
|
<text>Allow restores to be performed on a read-only repository by using <setting>--no-lock</setting> and <setting>--log-level-file=off</setting>. The <setting>--no-lock</setting> option can only be used with restores.</text>
|
||||||
</release-feature>
|
</release-feature>
|
||||||
</release-feature-bullet-list>
|
</release-feature-bullet-list>
|
||||||
</changelog-release>
|
</changelog-release>
|
||||||
|
@@ -594,6 +594,15 @@
|
|||||||
<example>y</example>
|
<example>y</example>
|
||||||
</option>
|
</option>
|
||||||
|
|
||||||
|
<!-- OPERATION - RESTORE COMMAND - LOCK OPTION -->
|
||||||
|
<option id="lock" name="Lock">
|
||||||
|
<summary>Create a lock so restores on a stanza cannot run simultaneously.</summary>
|
||||||
|
|
||||||
|
<text>Locking during restores is enabled by default but can be disabled using --no-lock. Be <i>very</i> careful when disabling this option because simultaneous restores to a single path might result in a corrupt cluster.</text>
|
||||||
|
|
||||||
|
<example>--no-lock</example>
|
||||||
|
</option>
|
||||||
|
|
||||||
<!-- OPERATION - RESTORE COMMAND - TYPE OPTION -->
|
<!-- OPERATION - RESTORE COMMAND - TYPE OPTION -->
|
||||||
<option id="type" name="Type">
|
<option id="type" name="Type">
|
||||||
<summary>Recovery type.</summary>
|
<summary>Recovery type.</summary>
|
||||||
|
@@ -105,6 +105,12 @@ sub lockAcquire
|
|||||||
{name => 'iProcessIdx', required => false}
|
{name => 'iProcessIdx', required => false}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
my $bResult = true;
|
||||||
|
|
||||||
|
# Acquire if locking is enabled
|
||||||
|
if (!optionTest(OPTION_LOCK) || optionGet(OPTION_LOCK))
|
||||||
|
{
|
||||||
|
$bResult = false;
|
||||||
my $strRepoPath = optionGet(OPTION_REPO_PATH);
|
my $strRepoPath = optionGet(OPTION_REPO_PATH);
|
||||||
|
|
||||||
# Cannot proceed if a lock is currently held
|
# Cannot proceed if a lock is currently held
|
||||||
@@ -126,8 +132,6 @@ sub lockAcquire
|
|||||||
or confess &log(ERROR, "unable to open lock file ${strCurrentLockFile}", ERROR_FILE_OPEN);
|
or confess &log(ERROR, "unable to open lock file ${strCurrentLockFile}", ERROR_FILE_OPEN);
|
||||||
|
|
||||||
# Attempt to lock the lock file
|
# Attempt to lock the lock file
|
||||||
my $bResult = false;
|
|
||||||
|
|
||||||
if (!flock($hCurrentLockHandle, LOCK_EX | LOCK_NB))
|
if (!flock($hCurrentLockHandle, LOCK_EX | LOCK_NB))
|
||||||
{
|
{
|
||||||
close($hCurrentLockHandle);
|
close($hCurrentLockHandle);
|
||||||
@@ -149,6 +153,7 @@ sub lockAcquire
|
|||||||
# Lock was successful
|
# Lock was successful
|
||||||
$bResult = true;
|
$bResult = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Return from function and log return values if any
|
# Return from function and log return values if any
|
||||||
return logDebugReturn
|
return logDebugReturn
|
||||||
@@ -177,6 +182,9 @@ sub lockRelease
|
|||||||
{name => 'bFailOnNoLock', default => true}
|
{name => 'bFailOnNoLock', default => true}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# Release if locking is enabled
|
||||||
|
if (!optionTest(OPTION_LOCK) || optionGet(OPTION_LOCK))
|
||||||
|
{
|
||||||
# Fail if there is no lock
|
# Fail if there is no lock
|
||||||
if (!defined($strCurrentLockType))
|
if (!defined($strCurrentLockType))
|
||||||
{
|
{
|
||||||
@@ -201,6 +209,7 @@ sub lockRelease
|
|||||||
undef($strCurrentLockType);
|
undef($strCurrentLockType);
|
||||||
undef($hCurrentLockHandle);
|
undef($hCurrentLockHandle);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Return from function and log return values if any
|
# Return from function and log return values if any
|
||||||
logDebugReturn($strOperation);
|
logDebugReturn($strOperation);
|
||||||
|
@@ -99,6 +99,9 @@ sub logFileSet
|
|||||||
{
|
{
|
||||||
my $strFile = shift;
|
my $strFile = shift;
|
||||||
|
|
||||||
|
# Only open the log file if file logging is enabled
|
||||||
|
if ($strLogLevelFile ne OFF)
|
||||||
|
{
|
||||||
unless (-e dirname($strFile))
|
unless (-e dirname($strFile))
|
||||||
{
|
{
|
||||||
mkdir(dirname($strFile), oct('0770'))
|
mkdir(dirname($strFile), oct('0770'))
|
||||||
@@ -122,6 +125,7 @@ sub logFileSet
|
|||||||
}
|
}
|
||||||
|
|
||||||
syswrite($hLogFile, "-------------------PROCESS START-------------------\n");
|
syswrite($hLogFile, "-------------------PROCESS START-------------------\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
push @EXPORT, qw(logFileSet);
|
push @EXPORT, qw(logFileSet);
|
||||||
|
@@ -218,6 +218,8 @@ use constant OPTION_TYPE => 'type';
|
|||||||
push @EXPORT, qw(OPTION_TYPE);
|
push @EXPORT, qw(OPTION_TYPE);
|
||||||
use constant OPTION_OUTPUT => 'output';
|
use constant OPTION_OUTPUT => 'output';
|
||||||
push @EXPORT, qw(OPTION_OUTPUT);
|
push @EXPORT, qw(OPTION_OUTPUT);
|
||||||
|
use constant OPTION_LOCK => 'lock';
|
||||||
|
push @EXPORT, qw(OPTION_LOCK);
|
||||||
|
|
||||||
# Command-line only help/version
|
# Command-line only help/version
|
||||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -363,6 +365,8 @@ use constant OPTION_DEFAULT_RESTORE_TARGET_RESUME => false;
|
|||||||
push @EXPORT, qw(OPTION_DEFAULT_RESTORE_TARGET_RESUME);
|
push @EXPORT, qw(OPTION_DEFAULT_RESTORE_TARGET_RESUME);
|
||||||
use constant OPTION_DEFAULT_RESTORE_TYPE => RECOVERY_TYPE_DEFAULT;
|
use constant OPTION_DEFAULT_RESTORE_TYPE => RECOVERY_TYPE_DEFAULT;
|
||||||
push @EXPORT, qw(OPTION_DEFAULT_RESTORE_TYPE);
|
push @EXPORT, qw(OPTION_DEFAULT_RESTORE_TYPE);
|
||||||
|
use constant OPTION_DEFAULT_LOCK => true;
|
||||||
|
push @EXPORT, qw(OPTION_DEFAULT_LOCK);
|
||||||
|
|
||||||
# Command-line only test
|
# Command-line only test
|
||||||
#-----------------------------------------------------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -545,6 +549,17 @@ my %oOptionRule =
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
&OPTION_LOCK =>
|
||||||
|
{
|
||||||
|
&OPTION_RULE_TYPE => OPTION_TYPE_BOOLEAN,
|
||||||
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_LOCK,
|
||||||
|
&OPTION_RULE_NEGATE => true,
|
||||||
|
&OPTION_RULE_COMMAND =>
|
||||||
|
{
|
||||||
|
&CMD_RESTORE => true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
&OPTION_NO_START_STOP =>
|
&OPTION_NO_START_STOP =>
|
||||||
{
|
{
|
||||||
&OPTION_RULE_TYPE => OPTION_TYPE_BOOLEAN,
|
&OPTION_RULE_TYPE => OPTION_TYPE_BOOLEAN,
|
||||||
|
@@ -853,6 +853,18 @@ my $oConfigHelpData =
|
|||||||
"combination with --delta a timestamp/size delta will be performed instead of using checksums."
|
"combination with --delta a timestamp/size delta will be performed instead of using checksums."
|
||||||
},
|
},
|
||||||
|
|
||||||
|
# LOCK Option Help
|
||||||
|
#-------------------------------------------------------------------------------------------------------------------
|
||||||
|
'lock' =>
|
||||||
|
{
|
||||||
|
summary =>
|
||||||
|
"Create a lock so restores on a stanza cannot run simultaneously.",
|
||||||
|
description =>
|
||||||
|
"Locking during restores is enabled by default but can be disabled using --no-lock. Be very careful " .
|
||||||
|
"when disabling this option because simultaneous restores to a single path might result in a " .
|
||||||
|
"corrupt cluster."
|
||||||
|
},
|
||||||
|
|
||||||
'log-level-console' => 'section',
|
'log-level-console' => 'section',
|
||||||
'log-level-file' => 'section',
|
'log-level-file' => 'section',
|
||||||
'neutral-umask' => 'section',
|
'neutral-umask' => 'section',
|
||||||
|
Reference in New Issue
Block a user