1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-14 10:13:05 +02:00

In the end it was a single non-undefed reference holding up the show. The Backup file should be split into Archive, Backup, Expire, and made into objects. That would cut down on this kind of nastiness.

This commit is contained in:
David Steele 2015-01-30 20:16:21 -05:00
parent 50e015a838
commit 11c257296a
5 changed files with 211 additions and 191 deletions

View File

@ -551,6 +551,7 @@ if (operation_get() eq OP_EXPIRE)
lock_file_remove();
}
backup_uninit();
remote_exit(0);
};

View File

@ -23,7 +23,7 @@ use BackRest::Db;
use Exporter qw(import);
our @EXPORT = qw(backup_init backup_thread_kill archive_push archive_xfer archive_get archive_compress
our @EXPORT = qw(backup_init backup_uninit backup_thread_kill archive_push archive_xfer archive_get archive_compress
backup backup_expire archive_list_get);
my $oDb;
@ -93,6 +93,14 @@ sub backup_init
}
}
####################################################################################################################################
# BACKUP_UNINIT
####################################################################################################################################
sub backup_uninit
{
undef($oFile);
}
####################################################################################################################################
# THREAD_INIT
####################################################################################################################################
@ -1675,24 +1683,32 @@ sub backup
my $strFileLog = "pg_xlog/${strArchive}";
# Get the checksum and compare against the one already on log log file (if there is one)
my $strChecksum = $oFile->hash(PATH_BACKUP_TMP, $strDestinationFile, $bCompress);
my $strChecksum = undef;
if ($stryArchiveFile[0] =~ "^${strArchive}-[0-f]+(\\.$oFile->{strCompressExtension}){0,1}\$" &&
$stryArchiveFile[0] !~ "^${strArchive}-${strChecksum}(\\.$oFile->{strCompressExtension}){0,1}\$")
if (!$bNoChecksum)
{
confess &log(ERROR, "error copying log '$stryArchiveFile[0]' to backup - checksum recored with file does " .
"not match actual checksum of '${strChecksum}'", ERROR_CHECKSUM);
$strChecksum = $oFile->hash(PATH_BACKUP_TMP, $strDestinationFile, $bCompress);
if ($stryArchiveFile[0] =~ "^${strArchive}-[0-f]+(\\.$oFile->{strCompressExtension}){0,1}\$" &&
$stryArchiveFile[0] !~ "^${strArchive}-${strChecksum}(\\.$oFile->{strCompressExtension}){0,1}\$")
{
confess &log(ERROR, "error copying log '$stryArchiveFile[0]' to backup - checksum recored with file does " .
"not match actual checksum of '${strChecksum}'", ERROR_CHECKSUM);
}
}
# Set manifest values
$oBackupManifest->set($strFileSection, $strFileLog, MANIFEST_SUBKEY_USER,
$oBackupManifest->get($strPathSection, $strPathLog, MANIFEST_SUBKEY_USER));
$oBackupManifest->set($strFileSection, $strFileLog, MANIFEST_SUBKEY_GROUP,
$oBackupManifest->get($strPathSection, $strPathLog, MANIFEST_SUBKEY_GROUP));
$oBackupManifest->set($strFileSection, $strFileLog, MANIFEST_SUBKEY_MODE, '0700');
$oBackupManifest->set($strFileSection, $strFileLog, MANIFEST_SUBKEY_MODIFICATION_TIME, $lModificationTime);
$oBackupManifest->set($strFileSection, $strFileLog, MANIFEST_SUBKEY_SIZE, 16777216);
$oBackupManifest->set($strFileSection, $strFileLog, MANIFEST_SUBKEY_CHECKSUM, $strChecksum);
if (defined($strChecksum))
{
# Set manifest values
$oBackupManifest->set($strFileSection, $strFileLog, MANIFEST_SUBKEY_USER,
$oBackupManifest->get($strPathSection, $strPathLog, MANIFEST_SUBKEY_USER));
$oBackupManifest->set($strFileSection, $strFileLog, MANIFEST_SUBKEY_GROUP,
$oBackupManifest->get($strPathSection, $strPathLog, MANIFEST_SUBKEY_GROUP));
$oBackupManifest->set($strFileSection, $strFileLog, MANIFEST_SUBKEY_MODE, '0700');
$oBackupManifest->set($strFileSection, $strFileLog, MANIFEST_SUBKEY_MODIFICATION_TIME, $lModificationTime);
$oBackupManifest->set($strFileSection, $strFileLog, MANIFEST_SUBKEY_SIZE, 16777216);
$oBackupManifest->set($strFileSection, $strFileLog, MANIFEST_SUBKEY_CHECKSUM, $strChecksum);
}
}
}

View File

@ -70,6 +70,9 @@ sub process_thread
{
my $self = shift;
# When a KILL signal is received, immediately abort
$SIG{'KILL'} = sub {threads->exit();};
while (my $strMessage = $self->{oThreadQueue}->dequeue())
{
my @stryMessage = split(':', $strMessage);

View File

@ -1695,181 +1695,181 @@ sub BackRestTestBackup_Test
my $strFullBackup = BackRestTestBackup_BackupEnd($strType, $oFile, $bRemote, undef, undef, $bSynthetic);
# # Setup the time target
# #-----------------------------------------------------------------------------------------------------------------------
# BackRestTestBackup_PgExecute("update test set message = '$strTimeMessage'", false);
# BackRestTestBackup_PgSwitchXlog();
# my $strTimeTarget = BackRestTestBackup_PgSelectOne("select to_char(current_timestamp, 'YYYY-MM-DD HH24:MI:SS.US TZ')");
# &log(INFO, " time target is ${strTimeTarget}");
#
# # Incr backup
# #-----------------------------------------------------------------------------------------------------------------------
# $strType = BACKUP_TYPE_INCR;
# $bTestPoint = true;
#
# BackRestTestBackup_PgExecute("create table test_remove (id int)", false);
# BackRestTestBackup_PgSwitchXlog();
# BackRestTestBackup_PgExecute("update test set message = '$strDefaultMessage'", false);
# BackRestTestBackup_PgSwitchXlog();
#
# BackRestTestBackup_BackupBegin($strType, $strStanza, $bRemote, "update during backup", $bSynthetic, $bTestPoint,
# $fTestDelay);
# BackRestTestCommon_ExecuteEnd(TEST_MANIFEST_BUILD);
#
# BackRestTestBackup_PgExecute("drop table test_remove", false);
# BackRestTestBackup_PgSwitchXlog();
# BackRestTestBackup_PgExecute("update test set message = '$strIncrMessage'", false);
#
# my $strIncrBackup = BackRestTestBackup_BackupEnd($strType, $oFile, $bRemote, undef, undef, $bSynthetic);
#
# # Setup the xid target
# #-----------------------------------------------------------------------------------------------------------------------
# BackRestTestBackup_PgExecute("update test set message = '$strXidMessage'", false, false);
# BackRestTestBackup_PgSwitchXlog();
# my $strXidTarget = BackRestTestBackup_PgSelectOne("select txid_current()");
# BackRestTestBackup_PgCommit();
# &log(INFO, " xid target is ${strXidTarget}");
#
# # Setup the name target
# #-----------------------------------------------------------------------------------------------------------------------
# my $strNameTarget = 'backrest';
#
# BackRestTestBackup_PgExecute("update test set message = '$strNameMessage'", false, true);
# BackRestTestBackup_PgSwitchXlog();
# BackRestTestBackup_PgExecute("select pg_create_restore_point('${strNameTarget}')", false, false);
#
# &log(INFO, " name target is ${strNameTarget}");
#
# # Restore (type = default)
# #-----------------------------------------------------------------------------------------------------------------------
# $strType = RECOVERY_TYPE_DEFAULT;
# $bDelta = false;
# $bForce = false;
#
# &log(INFO, " testing recovery type = ${strType}");
#
# # Expect failure because postmaster.pid exists
# BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
# $strType, undef, undef, undef, undef, undef,
# 'postmaster running', ERROR_POSTMASTER_RUNNING);
#
# BackRestTestBackup_ClusterStop();
#
# # Expect failure because db path is not empty
# BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
# $strType, undef, undef, undef, undef, undef,
# 'path not empty', ERROR_RESTORE_PATH_NOT_EMPTY);
#
# # Drop and recreate db path
# BackRestTestCommon_PathRemove(BackRestTestCommon_DbCommonPathGet());
# BackRestTestCommon_PathCreate(BackRestTestCommon_DbCommonPathGet());
#
# # Now the restore should work
# BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
# $strType, undef, undef, undef, undef, undef);
#
# BackRestTestBackup_ClusterStart();
#
# my $strMessageActual = BackRestTestBackup_PgSelectOne("select message from test");
# my $strMessageExpected = $strNameMessage;
#
# if ($strMessageActual ne $strMessageExpected)
# {
# confess "expected message '${strMessageExpected}' but found '${strMessageActual}'";
# }
#
# # Restore (restore type = xid, inclusive)
# #-----------------------------------------------------------------------------------------------------------------------
# $strType = RECOVERY_TYPE_XID;
# $bDelta = false;
# $bForce = true;
#
# &log(INFO, " testing recovery type = ${strType}");
#
# BackRestTestBackup_ClusterStop();
#
# BackRestTestBackup_Restore($oFile, $strIncrBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
# $strType, $strXidTarget, undef, undef, undef, undef);
#
# BackRestTestBackup_ClusterStart();
#
# $strMessageActual = BackRestTestBackup_PgSelectOne("select message from test");
# $strMessageExpected = $strXidMessage;
#
# if ($strMessageActual ne $strMessageExpected)
# {
# confess "expected message '${strMessageExpected}' but found '${strMessageActual}'";
# }
#
# # 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.
# #-----------------------------------------------------------------------------------------------------------------------
# $strType = RECOVERY_TYPE_TIME;
# $bDelta = true;
# $bForce = false;
#
# &log(INFO, " testing recovery type = ${strType}");
#
# BackRestTestBackup_ClusterStop();
#
# BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
# $strType, $strTimeTarget, undef, undef, undef, undef);
#
# BackRestTestBackup_ClusterStart();
#
# $strMessageActual = BackRestTestBackup_PgSelectOne("select message from test");
# $strMessageExpected = $strTimeMessage;
#
# if ($strMessageActual ne $strMessageExpected)
# {
# confess "expected message '${strMessageExpected}' but found '${strMessageActual}'";
# }
#
# # Restore (restore type = xid, exclusive)
# #-----------------------------------------------------------------------------------------------------------------------
# $strType = RECOVERY_TYPE_XID;
# $bDelta = true;
# $bForce = false;
#
# &log(INFO, " testing recovery type = ${strType}");
#
# BackRestTestBackup_ClusterStop();
#
# BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
# $strType, $strXidTarget, true, undef, undef, undef);
#
# BackRestTestBackup_ClusterStart();
#
# $strMessageActual = BackRestTestBackup_PgSelectOne("select message from test");
# $strMessageExpected = $strIncrMessage;
#
# if ($strMessageActual ne $strMessageExpected)
# {
# confess "expected message '${strMessageExpected}' but found '${strMessageActual}'";
# }
#
# # Restore (restore type = name)
# #-----------------------------------------------------------------------------------------------------------------------
# $strType = RECOVERY_TYPE_NAME;
# $bDelta = true;
# $bForce = true;
#
# &log(INFO, " testing recovery type = ${strType}");
#
# BackRestTestBackup_ClusterStop();
#
# BackRestTestBackup_Restore($oFile, 'latest', $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
# $strType, $strNameTarget, undef, undef, undef, undef);
#
# BackRestTestBackup_ClusterStart();
#
# $strMessageActual = BackRestTestBackup_PgSelectOne("select message from test");
# $strMessageExpected = $strNameMessage;
#
# if ($strMessageActual ne $strMessageExpected)
# {
# confess "expected message '${strMessageExpected}' but found '${strMessageActual}'";
# }
# Setup the time target
#-----------------------------------------------------------------------------------------------------------------------
BackRestTestBackup_PgExecute("update test set message = '$strTimeMessage'", false);
BackRestTestBackup_PgSwitchXlog();
my $strTimeTarget = BackRestTestBackup_PgSelectOne("select to_char(current_timestamp, 'YYYY-MM-DD HH24:MI:SS.US TZ')");
&log(INFO, " time target is ${strTimeTarget}");
# Incr backup
#-----------------------------------------------------------------------------------------------------------------------
$strType = BACKUP_TYPE_INCR;
$bTestPoint = true;
BackRestTestBackup_PgExecute("create table test_remove (id int)", false);
BackRestTestBackup_PgSwitchXlog();
BackRestTestBackup_PgExecute("update test set message = '$strDefaultMessage'", false);
BackRestTestBackup_PgSwitchXlog();
BackRestTestBackup_BackupBegin($strType, $strStanza, $bRemote, "update during backup", $bSynthetic, $bTestPoint,
$fTestDelay);
BackRestTestCommon_ExecuteEnd(TEST_MANIFEST_BUILD);
BackRestTestBackup_PgExecute("drop table test_remove", false);
BackRestTestBackup_PgSwitchXlog();
BackRestTestBackup_PgExecute("update test set message = '$strIncrMessage'", false);
my $strIncrBackup = BackRestTestBackup_BackupEnd($strType, $oFile, $bRemote, undef, undef, $bSynthetic);
# Setup the xid target
#-----------------------------------------------------------------------------------------------------------------------
BackRestTestBackup_PgExecute("update test set message = '$strXidMessage'", false, false);
BackRestTestBackup_PgSwitchXlog();
my $strXidTarget = BackRestTestBackup_PgSelectOne("select txid_current()");
BackRestTestBackup_PgCommit();
&log(INFO, " xid target is ${strXidTarget}");
# Setup the name target
#-----------------------------------------------------------------------------------------------------------------------
my $strNameTarget = 'backrest';
BackRestTestBackup_PgExecute("update test set message = '$strNameMessage'", false, true);
BackRestTestBackup_PgSwitchXlog();
BackRestTestBackup_PgExecute("select pg_create_restore_point('${strNameTarget}')", false, false);
&log(INFO, " name target is ${strNameTarget}");
# Restore (type = default)
#-----------------------------------------------------------------------------------------------------------------------
$strType = RECOVERY_TYPE_DEFAULT;
$bDelta = false;
$bForce = false;
&log(INFO, " testing recovery type = ${strType}");
# Expect failure because postmaster.pid exists
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
$strType, undef, undef, undef, undef, undef,
'postmaster running', ERROR_POSTMASTER_RUNNING);
BackRestTestBackup_ClusterStop();
# Expect failure because db path is not empty
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
$strType, undef, undef, undef, undef, undef,
'path not empty', ERROR_RESTORE_PATH_NOT_EMPTY);
# Drop and recreate db path
BackRestTestCommon_PathRemove(BackRestTestCommon_DbCommonPathGet());
BackRestTestCommon_PathCreate(BackRestTestCommon_DbCommonPathGet());
# Now the restore should work
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
$strType, undef, undef, undef, undef, undef);
BackRestTestBackup_ClusterStart();
my $strMessageActual = BackRestTestBackup_PgSelectOne("select message from test");
my $strMessageExpected = $strNameMessage;
if ($strMessageActual ne $strMessageExpected)
{
confess "expected message '${strMessageExpected}' but found '${strMessageActual}'";
}
# Restore (restore type = xid, inclusive)
#-----------------------------------------------------------------------------------------------------------------------
$strType = RECOVERY_TYPE_XID;
$bDelta = false;
$bForce = true;
&log(INFO, " testing recovery type = ${strType}");
BackRestTestBackup_ClusterStop();
BackRestTestBackup_Restore($oFile, $strIncrBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
$strType, $strXidTarget, undef, undef, undef, undef);
BackRestTestBackup_ClusterStart();
$strMessageActual = BackRestTestBackup_PgSelectOne("select message from test");
$strMessageExpected = $strXidMessage;
if ($strMessageActual ne $strMessageExpected)
{
confess "expected message '${strMessageExpected}' but found '${strMessageActual}'";
}
# 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.
#-----------------------------------------------------------------------------------------------------------------------
$strType = RECOVERY_TYPE_TIME;
$bDelta = true;
$bForce = false;
&log(INFO, " testing recovery type = ${strType}");
BackRestTestBackup_ClusterStop();
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
$strType, $strTimeTarget, undef, undef, undef, undef);
BackRestTestBackup_ClusterStart();
$strMessageActual = BackRestTestBackup_PgSelectOne("select message from test");
$strMessageExpected = $strTimeMessage;
if ($strMessageActual ne $strMessageExpected)
{
confess "expected message '${strMessageExpected}' but found '${strMessageActual}'";
}
# Restore (restore type = xid, exclusive)
#-----------------------------------------------------------------------------------------------------------------------
$strType = RECOVERY_TYPE_XID;
$bDelta = true;
$bForce = false;
&log(INFO, " testing recovery type = ${strType}");
BackRestTestBackup_ClusterStop();
BackRestTestBackup_Restore($oFile, $strFullBackup, $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
$strType, $strXidTarget, true, undef, undef, undef);
BackRestTestBackup_ClusterStart();
$strMessageActual = BackRestTestBackup_PgSelectOne("select message from test");
$strMessageExpected = $strIncrMessage;
if ($strMessageActual ne $strMessageExpected)
{
confess "expected message '${strMessageExpected}' but found '${strMessageActual}'";
}
# Restore (restore type = name)
#-----------------------------------------------------------------------------------------------------------------------
$strType = RECOVERY_TYPE_NAME;
$bDelta = true;
$bForce = true;
&log(INFO, " testing recovery type = ${strType}");
BackRestTestBackup_ClusterStop();
BackRestTestBackup_Restore($oFile, 'latest', $strStanza, $bRemote, undef, undef, $bDelta, $bForce,
$strType, $strNameTarget, undef, undef, undef, undef);
BackRestTestBackup_ClusterStart();
$strMessageActual = BackRestTestBackup_PgSelectOne("select message from test");
$strMessageExpected = $strNameMessage;
if ($strMessageActual ne $strMessageExpected)
{
confess "expected message '${strMessageExpected}' but found '${strMessageActual}'";
}
$bCreate = true;
}

View File

@ -519,7 +519,7 @@ sub BackRestTestCommon_ConfigCreate
}
$oParamHash{'global:log'}{'level-console'} = 'error';
$oParamHash{'global:log'}{'level-file'} = 'debug';
$oParamHash{'global:log'}{'level-file'} = 'trace';
if ($strLocal eq BACKUP)
{