2015-06-14 00:25:49 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# BACKUP INFO MODULE
|
|
|
|
####################################################################################################################################
|
|
|
|
package BackRest::BackupInfo;
|
2015-08-29 20:20:46 +02:00
|
|
|
use parent 'BackRest::Common::Ini';
|
2015-06-14 00:25:49 +02:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
|
|
|
|
use Exporter qw(import);
|
2015-08-29 20:20:46 +02:00
|
|
|
our @EXPORT = qw();
|
2015-06-14 00:25:49 +02:00
|
|
|
use File::Basename qw(dirname basename);
|
|
|
|
use File::stat;
|
|
|
|
|
|
|
|
use lib dirname($0);
|
2015-08-29 20:20:46 +02:00
|
|
|
use BackRest::Common::Exception;
|
|
|
|
use BackRest::Common::Ini;
|
|
|
|
use BackRest::Common::Log;
|
2015-09-08 13:31:24 +02:00
|
|
|
use BackRest::Config::Config;
|
2015-06-14 00:25:49 +02:00
|
|
|
use BackRest::File;
|
|
|
|
use BackRest::Manifest;
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Operation constants
|
|
|
|
####################################################################################################################################
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant OP_BACKUP_INFO => 'BackupInfo';
|
2015-06-14 00:25:49 +02:00
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant OP_INFO_BACKUP_ADD => OP_BACKUP_INFO . "->add";
|
|
|
|
use constant OP_INFO_BACKUP_CHECK => OP_BACKUP_INFO . "->check";
|
|
|
|
use constant OP_INFO_BACKUP_DELETE => OP_BACKUP_INFO . "->delete";
|
|
|
|
use constant OP_INFO_BACKUP_NEW => OP_BACKUP_INFO . "->new";
|
2015-06-14 00:25:49 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# File/path constants
|
|
|
|
####################################################################################################################################
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant FILE_BACKUP_INFO => 'backup.info';
|
|
|
|
push @EXPORT, qw(FILE_BACKUP_INFO);
|
2015-06-14 00:25:49 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
2015-08-29 20:20:46 +02:00
|
|
|
# Backup info constants
|
2015-06-14 00:25:49 +02:00
|
|
|
####################################################################################################################################
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_SECTION_BACKUP => MANIFEST_SECTION_BACKUP;
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_SECTION_BACKUP);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_SECTION_BACKUP_CURRENT => INFO_BACKUP_SECTION_BACKUP . ':current';
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_SECTION_BACKUP_CURRENT);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_SECTION_BACKUP_HISTORY => INFO_BACKUP_SECTION_BACKUP . ':history';
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_SECTION_BACKUP_HISTORY);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_SECTION_DB => 'db';
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_SECTION_DB);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_SECTION_DB_HISTORY => INFO_BACKUP_SECTION_DB . ':history';
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_SECTION_DB_HISTORY);
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_ARCHIVE_CHECK => MANIFEST_KEY_ARCHIVE_CHECK;
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_ARCHIVE_CHECK);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_ARCHIVE_COPY => MANIFEST_KEY_ARCHIVE_COPY;
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_ARCHIVE_COPY);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_ARCHIVE_START => MANIFEST_KEY_ARCHIVE_START;
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_ARCHIVE_START);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_ARCHIVE_STOP => MANIFEST_KEY_ARCHIVE_STOP;
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_ARCHIVE_STOP);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_BACKUP_REPO_SIZE => 'backup-info-repo-size';
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_BACKUP_REPO_SIZE);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_BACKUP_REPO_SIZE_DELTA => 'backup-info-repo-size-delta';
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_BACKUP_REPO_SIZE_DELTA);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_BACKUP_SIZE => 'backup-info-size';
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_BACKUP_SIZE);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_BACKUP_SIZE_DELTA => 'backup-info-size-delta';
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_BACKUP_SIZE_DELTA);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_CATALOG => MANIFEST_KEY_CATALOG;
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_CATALOG);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_CONTROL => MANIFEST_KEY_CONTROL;
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_CONTROL);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_COMPRESS => MANIFEST_KEY_COMPRESS;
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_COMPRESS);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_CHECKSUM => INI_KEY_CHECKSUM;
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_CHECKSUM);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_DB_VERSION => MANIFEST_KEY_DB_VERSION;
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_DB_VERSION);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_FORMAT => INI_KEY_FORMAT;
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_FORMAT);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_HARDLINK => MANIFEST_KEY_HARDLINK;
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_HARDLINK);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_HISTORY_ID => 'db-id';
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_HISTORY_ID);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_LABEL => MANIFEST_KEY_LABEL;
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_LABEL);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_PRIOR => MANIFEST_KEY_PRIOR;
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_PRIOR);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_REFERENCE => 'backup-reference';
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_REFERENCE);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_START_STOP => MANIFEST_KEY_START_STOP;
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_START_STOP);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_SYSTEM_ID => MANIFEST_KEY_SYSTEM_ID;
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_SYSTEM_ID);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_TIMESTAMP_START => MANIFEST_KEY_TIMESTAMP_START;
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_TIMESTAMP_START);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_TIMESTAMP_STOP => MANIFEST_KEY_TIMESTAMP_STOP;
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_TIMESTAMP_STOP);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_TYPE => MANIFEST_KEY_TYPE;
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_TYPE);
|
2015-08-29 20:20:46 +02:00
|
|
|
use constant INFO_BACKUP_KEY_VERSION => INI_KEY_VERSION;
|
2015-06-14 00:25:49 +02:00
|
|
|
push @EXPORT, qw(INFO_BACKUP_KEY_VERSION);
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# CONSTRUCTOR
|
|
|
|
####################################################################################################################################
|
|
|
|
sub new
|
|
|
|
{
|
2015-08-29 20:20:46 +02:00
|
|
|
my $class = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strBackupClusterPath # Backup cluster path
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
OP_INFO_BACKUP_NEW, \@_,
|
|
|
|
{name => 'strBackupClusterPath'}
|
|
|
|
);
|
2015-06-14 00:25:49 +02:00
|
|
|
|
|
|
|
# Build the backup info path/file name
|
|
|
|
my $strBackupInfoFile = "${strBackupClusterPath}/" . FILE_BACKUP_INFO;
|
|
|
|
my $bExists = -e $strBackupInfoFile ? true : false;
|
|
|
|
|
|
|
|
# Init object and store variables
|
|
|
|
my $self = $class->SUPER::new($strBackupInfoFile, $bExists);
|
|
|
|
|
|
|
|
$self->{bExists} = $bExists;
|
|
|
|
$self->{strBackupClusterPath} = $strBackupClusterPath;
|
|
|
|
|
|
|
|
# Validate the backup info
|
|
|
|
$self->validate();
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
{name => 'self', value => $self}
|
|
|
|
);
|
2015-06-14 00:25:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# validate
|
|
|
|
#
|
|
|
|
# Compare the backup info against the actual backups on disk.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub validate
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
OP_INFO_BACKUP_NEW
|
|
|
|
);
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
# Remove backups that no longer exist on disk
|
|
|
|
foreach my $strBackup ($self->keys(INFO_BACKUP_SECTION_BACKUP_CURRENT))
|
|
|
|
{
|
|
|
|
if (!-e "$self->{strBackupClusterPath}/${strBackup}")
|
|
|
|
{
|
|
|
|
&log(WARN, "backup ${strBackup} is missing from the repository - removed from " . FILE_BACKUP_INFO);
|
2015-08-29 20:20:46 +02:00
|
|
|
$self->delete($strBackup);
|
2015-06-14 00:25:49 +02:00
|
|
|
}
|
|
|
|
}
|
2015-08-29 20:20:46 +02:00
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation
|
|
|
|
);
|
2015-06-14 00:25:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# check
|
|
|
|
#
|
|
|
|
# Check db info and make it is compatible.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub check
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
2015-09-02 01:05:10 +02:00
|
|
|
$strDbVersion,
|
|
|
|
$iControlVersion,
|
|
|
|
$iCatalogVersion,
|
|
|
|
$ullDbSysId,
|
2015-08-29 20:20:46 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
OP_INFO_BACKUP_CHECK, \@_,
|
2015-09-02 01:05:10 +02:00
|
|
|
{name => 'strDbVersion', trace => true},
|
|
|
|
{name => 'iControlVersion', trace => true},
|
|
|
|
{name => 'iCatalogVersion', trace => true},
|
|
|
|
{name => 'ullDbSysId', trace => true}
|
2015-08-29 20:20:46 +02:00
|
|
|
);
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
if (!$self->test(INFO_BACKUP_SECTION_DB))
|
|
|
|
{
|
|
|
|
my $iHistoryId = 1;
|
|
|
|
|
|
|
|
# Fill db section
|
2015-08-29 20:20:46 +02:00
|
|
|
$self->numericSet(INFO_BACKUP_SECTION_DB, INFO_BACKUP_KEY_CATALOG, undef, $iCatalogVersion);
|
|
|
|
$self->numericSet(INFO_BACKUP_SECTION_DB, INFO_BACKUP_KEY_CONTROL, undef, $iControlVersion);
|
|
|
|
$self->numericSet(INFO_BACKUP_SECTION_DB, INFO_BACKUP_KEY_SYSTEM_ID, undef, $ullDbSysId);
|
2015-06-14 00:25:49 +02:00
|
|
|
$self->set(INFO_BACKUP_SECTION_DB, INFO_BACKUP_KEY_DB_VERSION, undef, $strDbVersion);
|
2015-08-29 20:20:46 +02:00
|
|
|
$self->numericSet(INFO_BACKUP_SECTION_DB, INFO_BACKUP_KEY_HISTORY_ID, undef, $iHistoryId);
|
2015-06-14 00:25:49 +02:00
|
|
|
|
|
|
|
# Fill db history
|
2015-08-29 20:20:46 +02:00
|
|
|
$self->numericSet(INFO_BACKUP_SECTION_DB_HISTORY, $iHistoryId, INFO_BACKUP_KEY_CATALOG, $iCatalogVersion);
|
|
|
|
$self->numericSet(INFO_BACKUP_SECTION_DB_HISTORY, $iHistoryId, INFO_BACKUP_KEY_CONTROL, $iControlVersion);
|
|
|
|
$self->numericSet(INFO_BACKUP_SECTION_DB_HISTORY, $iHistoryId, INFO_BACKUP_KEY_SYSTEM_ID, $ullDbSysId);
|
2015-06-14 00:25:49 +02:00
|
|
|
$self->set(INFO_BACKUP_SECTION_DB_HISTORY, $iHistoryId, INFO_BACKUP_KEY_DB_VERSION, $strDbVersion);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!$self->test(INFO_BACKUP_SECTION_DB, INFO_BACKUP_KEY_SYSTEM_ID, undef, $ullDbSysId) ||
|
|
|
|
!$self->test(INFO_BACKUP_SECTION_DB, INFO_BACKUP_KEY_DB_VERSION, undef, $strDbVersion))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "database version = ${strDbVersion}, system-id ${ullDbSysId} does not match backup version = " .
|
|
|
|
$self->get(INFO_BACKUP_SECTION_DB, INFO_BACKUP_KEY_DB_VERSION) . ", system-id = " .
|
|
|
|
$self->get(INFO_BACKUP_SECTION_DB, INFO_BACKUP_KEY_SYSTEM_ID) .
|
|
|
|
"\nHINT: are you backing up to the correct stanza?", ERROR_BACKUP_MISMATCH);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$self->test(INFO_BACKUP_SECTION_DB, INFO_BACKUP_KEY_CATALOG, undef, $iCatalogVersion) ||
|
|
|
|
!$self->test(INFO_BACKUP_SECTION_DB, INFO_BACKUP_KEY_CONTROL, undef, $iControlVersion))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "database control-version = ${iControlVersion}, catalog-version ${iCatalogVersion}" .
|
|
|
|
" does not match backup control-version = " .
|
|
|
|
$self->get(INFO_BACKUP_SECTION_DB, INFO_BACKUP_KEY_CONTROL) . ", catalog-version = " .
|
|
|
|
$self->get(INFO_BACKUP_SECTION_DB, INFO_BACKUP_KEY_CATALOG) .
|
|
|
|
"\nHINT: this may be a symptom of database or repository corruption!", ERROR_BACKUP_MISMATCH);
|
|
|
|
}
|
|
|
|
}
|
2015-08-29 20:20:46 +02:00
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation
|
|
|
|
);
|
2015-06-14 00:25:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2015-08-29 20:20:46 +02:00
|
|
|
# add
|
2015-06-14 00:25:49 +02:00
|
|
|
#
|
|
|
|
# Add a backup to the info file.
|
|
|
|
####################################################################################################################################
|
2015-08-29 20:20:46 +02:00
|
|
|
sub add
|
2015-06-14 00:25:49 +02:00
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$oFile,
|
|
|
|
$oBackupManifest
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
OP_INFO_BACKUP_ADD, \@_,
|
|
|
|
{name => 'oFile', trace => true},
|
|
|
|
{name => 'oBackupManifest', trace => true}
|
|
|
|
);
|
|
|
|
|
|
|
|
# !!! How best to log these follow-on cases?
|
2015-06-14 00:25:49 +02:00
|
|
|
my $strBackupLabel = $oBackupManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_LABEL);
|
|
|
|
|
|
|
|
# Calculate backup sizes and references
|
|
|
|
my $lBackupSize = 0;
|
|
|
|
my $lBackupSizeDelta = 0;
|
|
|
|
my $lBackupRepoSize = 0;
|
|
|
|
my $lBackupRepoSizeDelta = 0;
|
|
|
|
my $oReferenceHash = undef;
|
|
|
|
|
|
|
|
my $bCompress = $oBackupManifest->get(MANIFEST_SECTION_BACKUP_OPTION, MANIFEST_KEY_COMPRESS);
|
|
|
|
|
|
|
|
foreach my $strPathKey ($oBackupManifest->keys(MANIFEST_SECTION_BACKUP_PATH))
|
|
|
|
{
|
|
|
|
my $strFileSection = "${strPathKey}:" . MANIFEST_FILE;
|
|
|
|
my $strPath = $strPathKey;
|
|
|
|
$strPath =~ s/\:/\//g;
|
|
|
|
|
|
|
|
foreach my $strFileKey ($oBackupManifest->keys($strFileSection))
|
|
|
|
{
|
|
|
|
my $lFileSize = $oBackupManifest->get($strFileSection, $strFileKey, MANIFEST_SUBKEY_SIZE);
|
|
|
|
my $strFileReference = $oBackupManifest->get($strFileSection, $strFileKey, MANIFEST_SUBKEY_REFERENCE, false);
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
my $strFile = $oFile->pathGet(PATH_BACKUP_CLUSTER,
|
2015-06-14 00:25:49 +02:00
|
|
|
(defined($strFileReference) ? "${strFileReference}" : $strBackupLabel) .
|
|
|
|
"/${strPath}/${strFileKey}" .
|
|
|
|
($bCompress ? '.' . $oFile->{strCompressExtension} : ''));
|
|
|
|
|
|
|
|
my $oStat = lstat($strFile);
|
|
|
|
|
|
|
|
# Check for errors in stat
|
|
|
|
defined($oStat)
|
|
|
|
or confess &log(ERROR, "unable to lstat ${strFile}");
|
|
|
|
|
|
|
|
$lBackupSize += $lFileSize;
|
|
|
|
$lBackupRepoSize += $oStat->size;
|
|
|
|
|
|
|
|
if (defined($strFileReference))
|
|
|
|
{
|
|
|
|
$$oReferenceHash{$strFileReference} = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$lBackupSizeDelta += $lFileSize;
|
|
|
|
$lBackupRepoSizeDelta += $oStat->size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Add the manifest.backup size
|
2015-08-29 20:20:46 +02:00
|
|
|
my $strManifestFile = $oFile->pathGet(PATH_BACKUP_CLUSTER, "/${strBackupLabel}/" . FILE_MANIFEST);
|
2015-06-14 00:25:49 +02:00
|
|
|
my $oStat = lstat($strManifestFile);
|
|
|
|
|
|
|
|
# Check for errors in stat
|
|
|
|
defined($oStat)
|
|
|
|
or confess &log(ERROR, "unable to lstat ${strManifestFile}");
|
|
|
|
|
|
|
|
$lBackupRepoSize += $oStat->size;
|
|
|
|
$lBackupRepoSizeDelta += $oStat->size;
|
|
|
|
|
|
|
|
# Set backup size info
|
2015-08-29 20:20:46 +02:00
|
|
|
$self->numericSet(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel, INFO_BACKUP_KEY_BACKUP_SIZE, $lBackupSize);
|
|
|
|
$self->numericSet(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel, INFO_BACKUP_KEY_BACKUP_SIZE_DELTA, $lBackupSizeDelta);
|
|
|
|
$self->numericSet(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel, INFO_BACKUP_KEY_BACKUP_REPO_SIZE, $lBackupRepoSize);
|
|
|
|
$self->numericSet(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel, INFO_BACKUP_KEY_BACKUP_REPO_SIZE_DELTA,
|
2015-06-14 00:25:49 +02:00
|
|
|
$lBackupRepoSizeDelta);
|
|
|
|
|
|
|
|
# Store information about the backup into the backup section
|
2015-08-29 20:20:46 +02:00
|
|
|
$self->boolSet(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel, INFO_BACKUP_KEY_ARCHIVE_CHECK,
|
|
|
|
$oBackupManifest->boolGet(MANIFEST_SECTION_BACKUP_OPTION, MANIFEST_KEY_ARCHIVE_CHECK));
|
|
|
|
$self->boolSet(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel, INFO_BACKUP_KEY_ARCHIVE_COPY,
|
|
|
|
$oBackupManifest->boolGet(MANIFEST_SECTION_BACKUP_OPTION, MANIFEST_KEY_ARCHIVE_COPY));
|
2015-06-14 00:25:49 +02:00
|
|
|
$self->set(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel, INFO_BACKUP_KEY_ARCHIVE_START,
|
|
|
|
$oBackupManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_ARCHIVE_START, undef, false));
|
|
|
|
$self->set(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel, INFO_BACKUP_KEY_ARCHIVE_STOP,
|
|
|
|
$oBackupManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_ARCHIVE_STOP, undef, false));
|
2015-08-29 20:20:46 +02:00
|
|
|
$self->boolSet(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel, INFO_BACKUP_KEY_COMPRESS,
|
|
|
|
$oBackupManifest->boolGet(MANIFEST_SECTION_BACKUP_OPTION, MANIFEST_KEY_COMPRESS));
|
|
|
|
$self->numericSet(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel, INFO_BACKUP_KEY_FORMAT,
|
|
|
|
$oBackupManifest->numericGet(INI_SECTION_BACKREST, INI_KEY_FORMAT));
|
|
|
|
$self->boolSet(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel, INFO_BACKUP_KEY_HARDLINK,
|
|
|
|
$oBackupManifest->boolGet(MANIFEST_SECTION_BACKUP_OPTION, MANIFEST_KEY_HARDLINK));
|
|
|
|
$self->boolSet(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel, INFO_BACKUP_KEY_START_STOP,
|
|
|
|
$oBackupManifest->boolGet(MANIFEST_SECTION_BACKUP_OPTION, MANIFEST_KEY_START_STOP));
|
|
|
|
$self->numericSet(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel, INFO_BACKUP_KEY_TIMESTAMP_START,
|
|
|
|
$oBackupManifest->numericGet(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_TIMESTAMP_START));
|
|
|
|
$self->numericSet(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel, INFO_BACKUP_KEY_TIMESTAMP_STOP,
|
|
|
|
$oBackupManifest->numericGet(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_TIMESTAMP_STOP));
|
2015-06-14 00:25:49 +02:00
|
|
|
$self->set(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel, INFO_BACKUP_KEY_TYPE,
|
|
|
|
$oBackupManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_TYPE));
|
|
|
|
$self->set(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel, INFO_BACKUP_KEY_VERSION,
|
|
|
|
$oBackupManifest->get(INI_SECTION_BACKREST, INI_KEY_VERSION));
|
|
|
|
$self->set(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel, INFO_BACKUP_KEY_HISTORY_ID,
|
|
|
|
$self->get(INFO_BACKUP_SECTION_DB, INFO_BACKUP_KEY_HISTORY_ID));
|
|
|
|
|
|
|
|
if (!$oBackupManifest->test(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_TYPE, undef, BACKUP_TYPE_FULL))
|
|
|
|
{
|
2015-06-21 18:06:13 +02:00
|
|
|
my @stryReference = sort(keys(%$oReferenceHash));
|
2015-06-14 00:25:49 +02:00
|
|
|
|
|
|
|
$self->set(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel, INFO_BACKUP_KEY_PRIOR,
|
|
|
|
$oBackupManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_PRIOR));
|
|
|
|
$self->set(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel, INFO_BACKUP_KEY_REFERENCE,
|
|
|
|
\@stryReference);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Copy backup info to the history
|
|
|
|
$self->set(INFO_BACKUP_SECTION_BACKUP_HISTORY, $strBackupLabel, undef,
|
|
|
|
$self->get(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel));
|
|
|
|
|
|
|
|
$self->save();
|
2015-08-29 20:20:46 +02:00
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation
|
|
|
|
);
|
2015-06-14 00:25:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2015-08-29 20:20:46 +02:00
|
|
|
# Delete
|
2015-06-14 00:25:49 +02:00
|
|
|
#
|
2015-08-29 20:20:46 +02:00
|
|
|
# Delete a backup from the info file.
|
2015-06-14 00:25:49 +02:00
|
|
|
####################################################################################################################################
|
2015-08-29 20:20:46 +02:00
|
|
|
sub delete
|
2015-06-14 00:25:49 +02:00
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strBackupLabel
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
OP_INFO_BACKUP_DELETE, \@_,
|
|
|
|
{name => 'strBackupLabel'}
|
|
|
|
);
|
2015-06-14 00:25:49 +02:00
|
|
|
|
|
|
|
$self->remove(INFO_BACKUP_SECTION_BACKUP_CURRENT, $strBackupLabel);
|
|
|
|
$self->save();
|
2015-08-29 20:20:46 +02:00
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation
|
|
|
|
);
|
2015-06-14 00:25:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|