2015-01-07 17:59:43 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# MANIFEST MODULE
|
|
|
|
####################################################################################################################################
|
|
|
|
package BackRest::Manifest;
|
2015-08-29 20:20:46 +02:00
|
|
|
use parent 'BackRest::Common::Ini';
|
2015-01-07 17:59:43 +02:00
|
|
|
|
|
|
|
use strict;
|
2015-03-03 07:57:20 +02:00
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
2015-01-07 17:59:43 +02:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
use Exporter qw(import);
|
2015-08-29 20:20:46 +02:00
|
|
|
our @EXPORT = qw();
|
2015-02-01 01:15:08 +02:00
|
|
|
use File::Basename qw(dirname basename);
|
2015-01-20 23:05:15 +02:00
|
|
|
use Digest::SHA;
|
2015-06-14 00:25:49 +02:00
|
|
|
use Time::Local qw(timelocal);
|
2015-01-07 17:59:43 +02:00
|
|
|
|
|
|
|
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-02-01 01:15:08 +02:00
|
|
|
use BackRest::File;
|
2015-01-07 17:59:43 +02:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Operation constants
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant OP_MANIFEST => 'Manifest';
|
2015-08-29 20:20:46 +02:00
|
|
|
|
|
|
|
use constant OP_MANIFEST_BUILD => OP_MANIFEST . '->build';
|
|
|
|
use constant OP_MANIFEST_NEW => OP_MANIFEST . '->new';
|
2015-06-14 00:25:49 +02:00
|
|
|
use constant OP_MANIFEST_SAVE => OP_MANIFEST . '->save';
|
2015-01-07 17:59:43 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# File/path constants
|
|
|
|
####################################################################################################################################
|
2015-06-14 00:25:49 +02:00
|
|
|
use constant FILE_MANIFEST => 'backup.manifest';
|
|
|
|
push @EXPORT, qw(FILE_MANIFEST);
|
|
|
|
use constant PATH_PG_TBLSPC => 'pg_tblspc';
|
|
|
|
push @EXPORT, qw(PATH_PG_TBLSPC);
|
2015-07-16 17:12:48 +02:00
|
|
|
use constant FILE_PG_CONTROL => 'global/pg_control';
|
|
|
|
push @EXPORT, qw(FILE_PG_CONTROL);
|
2015-03-12 18:15:19 +02:00
|
|
|
|
2015-01-07 17:59:43 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# MANIFEST Constants
|
|
|
|
####################################################################################################################################
|
2015-06-14 00:25:49 +02:00
|
|
|
use constant MANIFEST_PATH => 'path';
|
|
|
|
push @EXPORT, qw(MANIFEST_PATH);
|
|
|
|
use constant MANIFEST_FILE => 'file';
|
|
|
|
push @EXPORT, qw(MANIFEST_FILE);
|
|
|
|
use constant MANIFEST_LINK => 'link';
|
|
|
|
push @EXPORT, qw(MANIFEST_LINK);
|
|
|
|
use constant MANIFEST_TABLESPACE => 'tablespace';
|
|
|
|
push @EXPORT, qw(MANIFEST_TABLESPACE);
|
|
|
|
|
|
|
|
use constant MANIFEST_KEY_BASE => 'base';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_BASE);
|
|
|
|
|
|
|
|
# Manifest sections
|
|
|
|
use constant MANIFEST_SECTION_BACKUP => 'backup';
|
|
|
|
push @EXPORT, qw(MANIFEST_SECTION_BACKUP);
|
|
|
|
use constant MANIFEST_SECTION_BACKUP_DB => 'backup:db';
|
|
|
|
push @EXPORT, qw(MANIFEST_SECTION_BACKUP_DB);
|
|
|
|
use constant MANIFEST_SECTION_BACKUP_INFO => 'backup:info';
|
|
|
|
push @EXPORT, qw(MANIFEST_SECTION_BACKUP_INFO);
|
|
|
|
use constant MANIFEST_SECTION_BACKUP_OPTION => 'backup:option';
|
|
|
|
push @EXPORT, qw(MANIFEST_SECTION_BACKUP_OPTION);
|
|
|
|
use constant MANIFEST_SECTION_BACKUP_PATH => 'backup:path';
|
|
|
|
push @EXPORT, qw(MANIFEST_SECTION_BACKUP_PATH);
|
|
|
|
|
|
|
|
# Backup metadata required for restores
|
|
|
|
use constant MANIFEST_KEY_ARCHIVE_START => 'backup-archive-start';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_ARCHIVE_START);
|
|
|
|
use constant MANIFEST_KEY_ARCHIVE_STOP => 'backup-archive-stop';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_ARCHIVE_STOP);
|
|
|
|
use constant MANIFEST_KEY_LABEL => 'backup-label';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_LABEL);
|
|
|
|
use constant MANIFEST_KEY_PRIOR => 'backup-prior';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_PRIOR);
|
|
|
|
use constant MANIFEST_KEY_TIMESTAMP_COPY_START => 'backup-timestamp-copy-start';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_TIMESTAMP_COPY_START);
|
|
|
|
use constant MANIFEST_KEY_TIMESTAMP_START => 'backup-timestamp-start';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_TIMESTAMP_START);
|
|
|
|
use constant MANIFEST_KEY_TIMESTAMP_STOP => 'backup-timestamp-stop';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_TIMESTAMP_STOP);
|
|
|
|
use constant MANIFEST_KEY_TYPE => 'backup-type';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_TYPE);
|
|
|
|
|
|
|
|
# Options that were set when the backup was made
|
|
|
|
use constant MANIFEST_KEY_HARDLINK => 'option-hardlink';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_HARDLINK);
|
|
|
|
use constant MANIFEST_KEY_ARCHIVE_CHECK => 'option-archive-check';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_ARCHIVE_CHECK);
|
|
|
|
use constant MANIFEST_KEY_ARCHIVE_COPY => 'option-archive-copy';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_ARCHIVE_COPY);
|
|
|
|
use constant MANIFEST_KEY_COMPRESS => 'option-compress';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_COMPRESS);
|
|
|
|
use constant MANIFEST_KEY_START_STOP => 'option-start-stop';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_START_STOP);
|
|
|
|
|
|
|
|
# Information about the database that was backed up
|
|
|
|
use constant MANIFEST_KEY_SYSTEM_ID => 'db-system-id';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_SYSTEM_ID);
|
|
|
|
use constant MANIFEST_KEY_CATALOG => 'db-catalog-version';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_CATALOG);
|
|
|
|
use constant MANIFEST_KEY_CONTROL => 'db-control-version';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_CONTROL);
|
|
|
|
use constant MANIFEST_KEY_DB_VERSION => 'db-version';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_DB_VERSION);
|
|
|
|
|
|
|
|
# Subkeys used for path/file/link info
|
|
|
|
use constant MANIFEST_SUBKEY_CHECKSUM => 'checksum';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_CHECKSUM);
|
|
|
|
use constant MANIFEST_SUBKEY_DESTINATION => 'destination';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_DESTINATION);
|
|
|
|
use constant MANIFEST_SUBKEY_FUTURE => 'future';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_FUTURE);
|
|
|
|
use constant MANIFEST_SUBKEY_GROUP => 'group';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_GROUP);
|
|
|
|
use constant MANIFEST_SUBKEY_LINK => 'link';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_LINK);
|
|
|
|
use constant MANIFEST_SUBKEY_MODE => 'mode';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_MODE);
|
|
|
|
use constant MANIFEST_SUBKEY_TIMESTAMP => 'timestamp';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_TIMESTAMP);
|
|
|
|
use constant MANIFEST_SUBKEY_PATH => 'path';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_PATH);
|
|
|
|
use constant MANIFEST_SUBKEY_REFERENCE => 'reference';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_REFERENCE);
|
|
|
|
use constant MANIFEST_SUBKEY_SIZE => 'size';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_SIZE);
|
|
|
|
use constant MANIFEST_SUBKEY_USER => 'user';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_USER);
|
2015-01-07 17:59:43 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
2015-06-14 00:25:49 +02:00
|
|
|
# new
|
2015-01-07 17:59:43 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
sub new
|
|
|
|
{
|
2015-08-29 20:20:46 +02:00
|
|
|
my $class = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strFileName, # Manifest filename
|
|
|
|
$bLoad # Load the manifest?
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
OP_MANIFEST_NEW, \@_,
|
|
|
|
{name => 'strFileName', trace => true},
|
|
|
|
{name => 'bLoad', required => false, trace => true}
|
|
|
|
);
|
2015-01-07 17:59:43 +02:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
# Set defaults
|
|
|
|
$bLoad = defined($bLoad) ? $bLoad : true;
|
2015-03-04 04:21:07 +02:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
# Init object and store variables
|
|
|
|
my $self = $class->SUPER::new($strFileName, $bLoad);
|
2015-01-20 21:13:35 +02:00
|
|
|
|
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-01-07 17:59:43 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 21:13:35 +02:00
|
|
|
####################################################################################################################################
|
2015-06-14 00:25:49 +02:00
|
|
|
# save
|
2015-01-20 21:13:35 +02:00
|
|
|
#
|
2015-01-20 21:42:22 +02:00
|
|
|
# Save the manifest.
|
2015-01-20 21:13:35 +02:00
|
|
|
####################################################################################################################################
|
2015-01-20 21:42:22 +02:00
|
|
|
sub save
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
OP_MANIFEST_SAVE
|
|
|
|
);
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
# !!! Add section comments here
|
2015-08-29 20:20:46 +02:00
|
|
|
# $self->commentSet(MANIFEST_SECTION_BACKUP_INFO,
|
2015-06-14 00:25:49 +02:00
|
|
|
# #################################################################################
|
|
|
|
# "Information about the backup:\n" .
|
|
|
|
# " backup-size = total size of original files.\n" .
|
|
|
|
# " backup-size-delta = difference in total file size from the prior backup.\n".
|
|
|
|
# " backup-size-delta will be equal to backup-size when\n" .
|
|
|
|
# " backup-type = full, otherwise this is not possible\n" .
|
|
|
|
# " unless option-start-stop = true.\n" .
|
|
|
|
# "\n" .
|
|
|
|
# "Human-readable output:\n" .
|
2015-08-29 20:20:46 +02:00
|
|
|
# " backup-repo-size = " . fileSizeFormat($lBackupRepoSize) . "\n" .
|
|
|
|
# " backup-repo-size-delta = " . fileSizeFormat($lBackupRepoSizeDelta) . "\n" .
|
|
|
|
# " backup-size = " . fileSizeFormat($lBackupSize) . "\n" .
|
|
|
|
# " backup-size-delta = " . fileSizeFormat($lBackupSizeDelta)
|
2015-06-14 00:25:49 +02:00
|
|
|
# );
|
|
|
|
|
|
|
|
# Call inherited save
|
|
|
|
$self->SUPER::save();
|
2015-08-29 20:20:46 +02:00
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation
|
|
|
|
);
|
2015-01-20 21:42:22 +02:00
|
|
|
}
|
2015-01-20 21:13:35 +02:00
|
|
|
|
2015-01-07 17:59:43 +02:00
|
|
|
####################################################################################################################################
|
2015-06-14 00:25:49 +02:00
|
|
|
# set
|
2015-01-08 19:04:56 +02:00
|
|
|
#
|
|
|
|
# Set a value.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub set
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $strSection = shift;
|
|
|
|
my $strKey = shift;
|
|
|
|
my $strSubKey = shift;
|
|
|
|
my $strValue = shift;
|
|
|
|
|
|
|
|
# Make sure the keys are valid
|
2015-01-20 23:05:15 +02:00
|
|
|
$self->valid($strSection, $strKey, $strSubKey);
|
2015-01-08 19:04:56 +02:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
# Call inherited set
|
|
|
|
$self->SUPER::set($strSection, $strKey, $strSubKey, $strValue);
|
2015-01-08 19:04:56 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 23:05:15 +02:00
|
|
|
####################################################################################################################################
|
2015-06-14 00:25:49 +02:00
|
|
|
# remove
|
2015-01-20 23:05:15 +02:00
|
|
|
#
|
|
|
|
# Remove a value.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub remove
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $strSection = shift;
|
|
|
|
my $strKey = shift;
|
|
|
|
my $strSubKey = shift;
|
|
|
|
my $strValue = shift;
|
|
|
|
|
|
|
|
# Make sure the keys are valid
|
2015-01-21 20:57:58 +02:00
|
|
|
$self->valid($strSection, $strKey, $strSubKey, undef, true);
|
2015-01-20 23:05:15 +02:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
# Call inherited remove
|
|
|
|
$self->SUPER::remove($strSection, $strKey, $strSubKey, $strValue);
|
2015-01-20 23:05:15 +02:00
|
|
|
}
|
|
|
|
|
2015-01-08 19:04:56 +02:00
|
|
|
####################################################################################################################################
|
2015-06-14 00:25:49 +02:00
|
|
|
# valid
|
2015-01-08 19:04:56 +02:00
|
|
|
#
|
|
|
|
# Determine if section, key, subkey combination is valid.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub valid
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $strSection = shift;
|
|
|
|
my $strKey = shift;
|
|
|
|
my $strSubKey = shift;
|
2015-01-21 20:57:58 +02:00
|
|
|
my $strValue = shift;
|
|
|
|
my $bDelete = shift;
|
2015-01-08 19:04:56 +02:00
|
|
|
|
|
|
|
# Section and key must always be defined
|
|
|
|
if (!defined($strSection) || !defined($strKey))
|
|
|
|
{
|
|
|
|
confess &log(ASSERT, 'section or key is not defined');
|
|
|
|
}
|
|
|
|
|
2015-01-21 20:57:58 +02:00
|
|
|
# Default bDelete
|
|
|
|
$bDelete = defined($bDelete) ? $bDelete : false;
|
|
|
|
|
2015-01-21 02:04:45 +02:00
|
|
|
if ($strSection =~ /^.*\:(file|path|link)$/ && $strSection !~ /^backup\:path$/)
|
|
|
|
{
|
2015-01-21 20:57:58 +02:00
|
|
|
if (!defined($strSubKey) && $bDelete)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-21 02:04:45 +02:00
|
|
|
my $strPath = (split(':', $strSection))[0];
|
|
|
|
my $strType = (split(':', $strSection))[1];
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
if ($strPath eq MANIFEST_TABLESPACE)
|
2015-01-23 03:11:33 +02:00
|
|
|
{
|
|
|
|
$strPath = (split(':', $strSection))[1];
|
|
|
|
$strType = (split(':', $strSection))[2];
|
|
|
|
}
|
|
|
|
|
2015-01-21 02:04:45 +02:00
|
|
|
if (($strType eq 'path' || $strType eq 'file' || $strType eq 'link') &&
|
|
|
|
($strSubKey eq MANIFEST_SUBKEY_USER ||
|
|
|
|
$strSubKey eq MANIFEST_SUBKEY_GROUP))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
elsif (($strType eq 'path' || $strType eq 'file') &&
|
|
|
|
($strSubKey eq MANIFEST_SUBKEY_MODE))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
elsif ($strType eq 'file' &&
|
|
|
|
($strSubKey eq MANIFEST_SUBKEY_CHECKSUM ||
|
|
|
|
$strSubKey eq MANIFEST_SUBKEY_FUTURE ||
|
2015-06-14 00:25:49 +02:00
|
|
|
$strSubKey eq MANIFEST_SUBKEY_TIMESTAMP ||
|
2015-01-21 02:04:45 +02:00
|
|
|
$strSubKey eq MANIFEST_SUBKEY_REFERENCE ||
|
|
|
|
$strSubKey eq MANIFEST_SUBKEY_SIZE))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
elsif ($strType eq 'link' &&
|
|
|
|
$strSubKey eq MANIFEST_SUBKEY_DESTINATION)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-06-14 00:25:49 +02:00
|
|
|
elsif ($strSection eq INI_SECTION_BACKREST)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
elsif ($strSection eq MANIFEST_SECTION_BACKUP)
|
2015-01-20 23:05:15 +02:00
|
|
|
{
|
2015-01-21 01:00:03 +02:00
|
|
|
if ($strKey eq MANIFEST_KEY_ARCHIVE_START ||
|
|
|
|
$strKey eq MANIFEST_KEY_ARCHIVE_STOP ||
|
|
|
|
$strKey eq MANIFEST_KEY_LABEL ||
|
|
|
|
$strKey eq MANIFEST_KEY_PRIOR ||
|
2015-01-21 02:04:45 +02:00
|
|
|
$strKey eq MANIFEST_KEY_TIMESTAMP_COPY_START ||
|
2015-01-21 01:00:03 +02:00
|
|
|
$strKey eq MANIFEST_KEY_TIMESTAMP_START ||
|
|
|
|
$strKey eq MANIFEST_KEY_TIMESTAMP_STOP ||
|
2015-06-14 00:25:49 +02:00
|
|
|
$strKey eq MANIFEST_KEY_TYPE)
|
2015-01-20 23:05:15 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-06-14 00:25:49 +02:00
|
|
|
elsif ($strSection eq MANIFEST_SECTION_BACKUP_DB)
|
2015-01-21 01:00:03 +02:00
|
|
|
{
|
2015-06-14 00:25:49 +02:00
|
|
|
if ($strKey eq MANIFEST_KEY_CATALOG ||
|
|
|
|
$strKey eq MANIFEST_KEY_CONTROL ||
|
|
|
|
$strKey eq MANIFEST_KEY_SYSTEM_ID ||
|
|
|
|
$strKey eq MANIFEST_KEY_DB_VERSION)
|
2015-01-21 01:00:03 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-06-14 00:25:49 +02:00
|
|
|
elsif ($strSection eq MANIFEST_SECTION_BACKUP_OPTION)
|
2015-01-23 03:11:33 +02:00
|
|
|
{
|
2015-06-14 00:25:49 +02:00
|
|
|
if ($strKey eq MANIFEST_KEY_ARCHIVE_CHECK ||
|
|
|
|
$strKey eq MANIFEST_KEY_ARCHIVE_COPY ||
|
|
|
|
$strKey eq MANIFEST_KEY_COMPRESS ||
|
|
|
|
$strKey eq MANIFEST_KEY_HARDLINK ||
|
|
|
|
$strKey eq MANIFEST_KEY_START_STOP)
|
2015-01-23 03:11:33 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-01-21 01:00:03 +02:00
|
|
|
elsif ($strSection eq MANIFEST_SECTION_BACKUP_PATH)
|
2015-01-08 19:04:56 +02:00
|
|
|
{
|
2015-06-14 00:25:49 +02:00
|
|
|
if ($strKey eq MANIFEST_KEY_BASE &&
|
|
|
|
$strSubKey eq MANIFEST_SUBKEY_PATH)
|
2015-01-08 19:04:56 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2015-01-07 17:59:43 +02:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
if ($strKey =~ /^tablespace\// &&
|
|
|
|
($strSubKey eq MANIFEST_SUBKEY_LINK ||
|
|
|
|
$strSubKey eq MANIFEST_SUBKEY_PATH))
|
2015-01-07 17:59:43 +02:00
|
|
|
{
|
2015-06-14 00:25:49 +02:00
|
|
|
return true;
|
2015-01-07 17:59:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
confess &log(ASSERT, "manifest section '${strSection}', key '${strKey}'" .
|
|
|
|
(defined($strSubKey) ? ", subkey '$strSubKey'" : '') . ' is not valid');
|
2015-01-07 17:59:43 +02:00
|
|
|
}
|
|
|
|
|
2016-02-02 21:33:15 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# tablespacePathGet
|
|
|
|
#
|
|
|
|
# Get the unique path assigned by Postgres for the tablespace.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub tablespacePathGet
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return('PG_' . $self->get(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_DB_VERSION) .
|
|
|
|
'_' . $self->get(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_CATALOG));
|
|
|
|
}
|
|
|
|
|
2015-02-01 01:15:08 +02:00
|
|
|
####################################################################################################################################
|
2015-06-14 00:25:49 +02:00
|
|
|
# build
|
2015-02-01 01:23:37 +02:00
|
|
|
#
|
|
|
|
# Build the manifest object.
|
2015-02-01 01:15:08 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
sub build
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$oFile,
|
|
|
|
$strDbClusterPath,
|
|
|
|
$oLastManifest,
|
|
|
|
$bNoStartStop,
|
|
|
|
$oTablespaceMapRef,
|
|
|
|
$strLevel
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
OP_MANIFEST_BUILD, \@_,
|
|
|
|
{name => 'oFile'},
|
|
|
|
{name => 'strDbClusterPath'},
|
|
|
|
{name => 'oLastManifest', required => false},
|
|
|
|
{name => 'bNoStartStop'},
|
|
|
|
{name => 'oTablespaceMapRef', required => false},
|
|
|
|
{name => 'strLevel', required => false}
|
|
|
|
);
|
2015-02-03 01:33:11 +02:00
|
|
|
|
2015-02-01 01:15:08 +02:00
|
|
|
# If no level is defined then it must be base
|
2016-02-02 21:33:15 +02:00
|
|
|
my $strTablespacePath;
|
|
|
|
|
2015-02-01 01:15:08 +02:00
|
|
|
if (!defined($strLevel))
|
|
|
|
{
|
2015-06-14 00:25:49 +02:00
|
|
|
$strLevel = MANIFEST_KEY_BASE;
|
2015-02-01 01:23:37 +02:00
|
|
|
|
2015-02-03 01:33:11 +02:00
|
|
|
if (defined($oLastManifest))
|
|
|
|
{
|
|
|
|
$self->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_PRIOR, undef,
|
|
|
|
$oLastManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_LABEL));
|
|
|
|
}
|
|
|
|
|
2015-02-01 01:23:37 +02:00
|
|
|
# If bNoStartStop then build the tablespace map from pg_tblspc path
|
2015-05-22 20:49:14 +02:00
|
|
|
if ($bNoStartStop && !defined($oTablespaceMapRef))
|
2015-02-01 01:23:37 +02:00
|
|
|
{
|
|
|
|
$oTablespaceMapRef = {};
|
|
|
|
|
|
|
|
my %oTablespaceManifestHash;
|
2015-06-14 00:25:49 +02:00
|
|
|
$oFile->manifest(PATH_DB_ABSOLUTE, $strDbClusterPath . '/' . PATH_PG_TBLSPC, \%oTablespaceManifestHash);
|
2015-02-01 01:23:37 +02:00
|
|
|
|
2015-06-21 18:06:13 +02:00
|
|
|
foreach my $strName (sort(CORE::keys(%{$oTablespaceManifestHash{name}})))
|
2015-02-01 01:23:37 +02:00
|
|
|
{
|
|
|
|
if ($strName eq '.' or $strName eq '..')
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
logDebugMisc($strOperation, "found tablespace ${strName}");
|
2015-02-01 01:23:37 +02:00
|
|
|
|
2015-02-03 01:33:11 +02:00
|
|
|
${$oTablespaceMapRef}{oid}{$strName}{name} = $strName;
|
2015-02-01 01:23:37 +02:00
|
|
|
}
|
|
|
|
}
|
2015-02-01 01:15:08 +02:00
|
|
|
}
|
2016-02-02 21:33:15 +02:00
|
|
|
elsif ($self->numericGet(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_DB_VERSION) >= 9.0)
|
|
|
|
{
|
|
|
|
$strTablespacePath = $self->tablespacePathGet();
|
|
|
|
}
|
2015-02-01 01:15:08 +02:00
|
|
|
|
|
|
|
# Get the manifest for this level
|
|
|
|
my %oManifestHash;
|
2016-02-02 21:33:15 +02:00
|
|
|
$oFile->manifest(PATH_DB_ABSOLUTE, $strDbClusterPath .
|
|
|
|
(defined($strTablespacePath) ? "/${strTablespacePath}" : ''), \%oManifestHash);
|
2015-02-01 01:15:08 +02:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
$self->set(MANIFEST_SECTION_BACKUP_PATH, $strLevel, MANIFEST_SUBKEY_PATH, $strDbClusterPath);
|
2015-02-01 01:15:08 +02:00
|
|
|
|
|
|
|
# Loop though all paths/files/links in the manifest
|
2015-06-21 18:06:13 +02:00
|
|
|
foreach my $strName (sort(CORE::keys(%{$oManifestHash{name}})))
|
2015-02-01 01:15:08 +02:00
|
|
|
{
|
|
|
|
# Skip certain files during backup
|
|
|
|
if (($strName =~ /^pg\_xlog\/.*/ && !$bNoStartStop) || # pg_xlog/ - this will be reconstructed
|
|
|
|
$strName =~ /^postmaster\.pid$/ || # postmaster.pid - to avoid confusing postgres when restoring
|
2015-10-28 11:10:36 +02:00
|
|
|
$strName =~ /^backup\_label\.old$/ || # backup_label.old - old backup labels are not useful
|
|
|
|
$strName =~ /^recovery\.done$/ || # recovery.done - doesn't make sense to backup this file
|
2015-02-01 01:15:08 +02:00
|
|
|
$strName =~ /^recovery\.conf$/) # recovery.conf - doesn't make sense to backup this file
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2016-01-15 14:07:00 +02:00
|
|
|
my $cType = $oManifestHash{name}{$strName}{type};
|
|
|
|
my $strLinkDestination = $oManifestHash{name}{$strName}{link_destination};
|
2015-02-01 01:15:08 +02:00
|
|
|
my $strSection = "${strLevel}:path";
|
|
|
|
|
|
|
|
if ($cType eq 'f')
|
|
|
|
{
|
|
|
|
$strSection = "${strLevel}:file";
|
|
|
|
}
|
|
|
|
elsif ($cType eq 'l')
|
|
|
|
{
|
|
|
|
$strSection = "${strLevel}:link";
|
|
|
|
}
|
|
|
|
elsif ($cType ne 'd')
|
|
|
|
{
|
|
|
|
confess &log(ASSERT, "unrecognized file type $cType for file $strName");
|
|
|
|
}
|
|
|
|
|
2016-01-15 14:07:00 +02:00
|
|
|
# Make sure that pg_tblspc contains only absolute links that do not point inside PGDATA
|
|
|
|
if (index($strName, PATH_PG_TBLSPC . '/') == 0 && $strLevel eq MANIFEST_KEY_BASE)
|
|
|
|
{
|
|
|
|
# Check for files in pg_tblspc that are not links
|
|
|
|
if ($oManifestHash{name}{$strName}{type} ne 'l')
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "/${strName} is not a symlink - pg_tblspc should contain only symlinks", ERROR_LINK_EXPECTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check for relative link targets
|
|
|
|
if (index($oManifestHash{name}{$strName}{link_destination}, '/') != 0)
|
|
|
|
{
|
|
|
|
confess &log(ERROR, 'tablespace symlink ' . $oManifestHash{name}{$strName}{link_destination} .
|
|
|
|
' must be absolute', ERROR_ABSOLUTE_LINK_EXPECTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check for tablespaces in PGDATA
|
|
|
|
if (index($oManifestHash{name}{$strName}{link_destination}, $strDbClusterPath) == 0)
|
|
|
|
{
|
|
|
|
confess &log(ERROR, 'tablespace symlink ' . $oManifestHash{name}{$strName}{link_destination} .
|
2016-01-16 03:31:29 +02:00
|
|
|
' must not be in $PGDATA', ERROR_TABLESPACE_IN_PGDATA);
|
2016-01-15 14:07:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-01 01:15:08 +02:00
|
|
|
# User and group required for all types
|
2016-01-15 14:07:00 +02:00
|
|
|
$self->set($strSection, $strName, MANIFEST_SUBKEY_USER, $oManifestHash{name}{$strName}{user});
|
|
|
|
$self->set($strSection, $strName, MANIFEST_SUBKEY_GROUP, $oManifestHash{name}{$strName}{group});
|
2015-02-01 01:15:08 +02:00
|
|
|
|
|
|
|
# Mode for required file and path type only
|
|
|
|
if ($cType eq 'f' || $cType eq 'd')
|
|
|
|
{
|
2016-01-15 14:07:00 +02:00
|
|
|
$self->set($strSection, $strName, MANIFEST_SUBKEY_MODE, $oManifestHash{name}{$strName}{mode});
|
2015-02-01 01:15:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Modification time and size required for file type only
|
|
|
|
if ($cType eq 'f')
|
|
|
|
{
|
2015-06-14 00:25:49 +02:00
|
|
|
$self->set($strSection, $strName, MANIFEST_SUBKEY_TIMESTAMP,
|
2016-01-15 14:07:00 +02:00
|
|
|
$oManifestHash{name}{$strName}{modification_time} + 0);
|
|
|
|
$self->set($strSection, $strName, MANIFEST_SUBKEY_SIZE, $oManifestHash{name}{$strName}{size} + 0);
|
2015-02-01 01:15:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Link destination required for link type only
|
|
|
|
if ($cType eq 'l')
|
|
|
|
{
|
|
|
|
$self->set($strSection, $strName, MANIFEST_SUBKEY_DESTINATION,
|
2016-01-15 14:07:00 +02:00
|
|
|
$oManifestHash{name}{$strName}{link_destination});
|
2015-02-01 01:15:08 +02:00
|
|
|
|
|
|
|
# If this is a tablespace then follow the link
|
2015-06-14 00:25:49 +02:00
|
|
|
if (index($strName, PATH_PG_TBLSPC . '/') == 0 && $strLevel eq MANIFEST_KEY_BASE)
|
2015-02-01 01:15:08 +02:00
|
|
|
{
|
|
|
|
my $strTablespaceOid = basename($strName);
|
2015-06-14 00:25:49 +02:00
|
|
|
my $strTablespaceName = MANIFEST_TABLESPACE . '/' . ${$oTablespaceMapRef}{oid}{$strTablespaceOid}{name};
|
2015-02-01 01:15:08 +02:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
$self->set(MANIFEST_SECTION_BACKUP_PATH, $strTablespaceName,
|
2015-02-01 01:15:08 +02:00
|
|
|
MANIFEST_SUBKEY_LINK, $strTablespaceOid);
|
2015-06-14 00:25:49 +02:00
|
|
|
$self->set(MANIFEST_SECTION_BACKUP_PATH, $strTablespaceName,
|
2015-02-01 01:15:08 +02:00
|
|
|
MANIFEST_SUBKEY_PATH, $strLinkDestination);
|
|
|
|
|
|
|
|
$self->build($oFile, $strLinkDestination, $oLastManifest, $bNoStartStop, $oTablespaceMapRef,
|
2015-06-14 00:25:49 +02:00
|
|
|
$strTablespaceName);
|
2015-02-01 01:15:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# If this is the base level then do post-processing
|
2015-06-14 00:25:49 +02:00
|
|
|
if ($strLevel eq MANIFEST_KEY_BASE)
|
2015-02-01 01:15:08 +02:00
|
|
|
{
|
|
|
|
my $bTimeInFuture = false;
|
|
|
|
|
|
|
|
my $lTimeBegin = $oFile->wait(PATH_DB_ABSOLUTE);
|
|
|
|
|
|
|
|
# Loop through all backup paths (base and tablespaces)
|
|
|
|
foreach my $strPathKey ($self->keys(MANIFEST_SECTION_BACKUP_PATH))
|
|
|
|
{
|
|
|
|
my $strSection = "${strPathKey}:file";
|
|
|
|
|
|
|
|
# Make sure file section exists
|
|
|
|
if ($self->test($strSection))
|
|
|
|
{
|
|
|
|
# Loop though all files
|
|
|
|
foreach my $strName ($self->keys($strSection))
|
|
|
|
{
|
|
|
|
# If modification time is in the future (in this backup OR the last backup) set warning flag and do not
|
|
|
|
# allow a reference
|
2015-08-29 20:20:46 +02:00
|
|
|
if ($self->numericGet($strSection, $strName, MANIFEST_SUBKEY_TIMESTAMP) > $lTimeBegin ||
|
2015-02-01 01:15:08 +02:00
|
|
|
(defined($oLastManifest) && $oLastManifest->test($strSection, $strName, MANIFEST_SUBKEY_FUTURE, 'y')))
|
|
|
|
{
|
|
|
|
$bTimeInFuture = true;
|
|
|
|
|
|
|
|
# Only mark as future if still in the future in the current backup
|
2015-08-29 20:20:46 +02:00
|
|
|
if ($self->numericGet($strSection, $strName, MANIFEST_SUBKEY_TIMESTAMP) > $lTimeBegin)
|
2015-02-01 01:15:08 +02:00
|
|
|
{
|
|
|
|
$self->set($strSection, $strName, MANIFEST_SUBKEY_FUTURE, 'y');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# Else check if modification time and size are unchanged since last backup
|
|
|
|
elsif (defined($oLastManifest) && $oLastManifest->test($strSection, $strName) &&
|
2015-08-29 20:20:46 +02:00
|
|
|
$self->numericGet($strSection, $strName, MANIFEST_SUBKEY_SIZE) ==
|
2015-02-01 01:15:08 +02:00
|
|
|
$oLastManifest->get($strSection, $strName, MANIFEST_SUBKEY_SIZE) &&
|
2015-08-29 20:20:46 +02:00
|
|
|
$self->numericGet($strSection, $strName, MANIFEST_SUBKEY_TIMESTAMP) ==
|
2015-06-14 00:25:49 +02:00
|
|
|
$oLastManifest->get($strSection, $strName, MANIFEST_SUBKEY_TIMESTAMP))
|
2015-02-01 01:15:08 +02:00
|
|
|
{
|
|
|
|
# Copy reference from previous backup if possible
|
|
|
|
if ($oLastManifest->test($strSection, $strName, MANIFEST_SUBKEY_REFERENCE))
|
|
|
|
{
|
|
|
|
$self->set($strSection, $strName, MANIFEST_SUBKEY_REFERENCE,
|
|
|
|
$oLastManifest->get($strSection, $strName, MANIFEST_SUBKEY_REFERENCE));
|
|
|
|
}
|
|
|
|
# Otherwise the reference is to the previous backup
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$self->set($strSection, $strName, MANIFEST_SUBKEY_REFERENCE,
|
|
|
|
$oLastManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_LABEL));
|
|
|
|
}
|
|
|
|
|
|
|
|
# Copy the checksum from previous manifest
|
|
|
|
if ($oLastManifest->test($strSection, $strName, MANIFEST_SUBKEY_CHECKSUM))
|
|
|
|
{
|
|
|
|
$self->set($strSection, $strName, MANIFEST_SUBKEY_CHECKSUM,
|
|
|
|
$oLastManifest->get($strSection, $strName, MANIFEST_SUBKEY_CHECKSUM));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Warn if any files in the current backup are in the future
|
|
|
|
if ($bTimeInFuture)
|
|
|
|
{
|
|
|
|
&log(WARN, "some files have timestamps in the future - they will be copied to prevent possible race conditions");
|
|
|
|
}
|
|
|
|
|
|
|
|
# Record the time when copying will start
|
2015-06-14 00:25:49 +02:00
|
|
|
$self->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_TIMESTAMP_COPY_START, undef, $lTimeBegin + 1);
|
2015-02-01 01:15:08 +02:00
|
|
|
}
|
2015-08-29 20:20:46 +02:00
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn
|
|
|
|
(
|
|
|
|
$strOperation
|
|
|
|
);
|
2015-02-01 01:15:08 +02:00
|
|
|
}
|
|
|
|
|
2015-01-07 17:59:43 +02:00
|
|
|
1;
|