2015-01-07 17:59:43 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# MANIFEST MODULE
|
|
|
|
####################################################################################################################################
|
2016-04-14 15:30:54 +02:00
|
|
|
package pgBackRest::Manifest;
|
|
|
|
use parent 'pgBackRest::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);
|
2016-04-14 15:30:54 +02:00
|
|
|
use pgBackRest::Common::Exception;
|
|
|
|
use pgBackRest::Common::Ini;
|
|
|
|
use pgBackRest::Common::Log;
|
|
|
|
use pgBackRest::File;
|
2016-04-15 04:50:02 +02:00
|
|
|
use pgBackRest::FileCommon;
|
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
|
|
|
|
####################################################################################################################################
|
2016-04-15 04:50:02 +02:00
|
|
|
use constant PATH_BACKUP_HISTORY => 'backup.history';
|
|
|
|
push @EXPORT, qw(PATH_BACKUP_HISTORY);
|
2015-06-14 00:25:49 +02:00
|
|
|
use constant FILE_MANIFEST => 'backup.manifest';
|
|
|
|
push @EXPORT, qw(FILE_MANIFEST);
|
2016-04-15 04:50:02 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Default match factor
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant MANIFEST_DEFAULT_MATCH_FACTOR => 0.1;
|
|
|
|
push @EXPORT, qw(MANIFEST_DEFAULT_MATCH_FACTOR);
|
2015-03-12 18:15:19 +02:00
|
|
|
|
2015-01-07 17:59:43 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# MANIFEST Constants
|
|
|
|
####################################################################################################################################
|
2016-04-15 04:50:02 +02:00
|
|
|
use constant MANIFEST_TARGET_PGDATA => 'pg_data';
|
|
|
|
push @EXPORT, qw(MANIFEST_TARGET_PGDATA);
|
|
|
|
use constant MANIFEST_TARGET_PGTBLSPC => 'pg_tblspc';
|
|
|
|
push @EXPORT, qw(MANIFEST_TARGET_PGTBLSPC);
|
2015-06-14 00:25:49 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
use constant MANIFEST_VALUE_PATH => 'path';
|
|
|
|
push @EXPORT, qw(MANIFEST_VALUE_PATH);
|
|
|
|
use constant MANIFEST_VALUE_LINK => 'link';
|
|
|
|
push @EXPORT, qw(MANIFEST_VALUE_LINK);
|
2015-06-14 00:25:49 +02:00
|
|
|
|
|
|
|
# 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);
|
2016-04-15 04:50:02 +02:00
|
|
|
use constant MANIFEST_SECTION_BACKUP_TARGET => 'backup:target';
|
|
|
|
push @EXPORT, qw(MANIFEST_SECTION_BACKUP_TARGET);
|
2016-05-11 15:21:39 +02:00
|
|
|
use constant MANIFEST_SECTION_DB => 'db';
|
|
|
|
push @EXPORT, qw(MANIFEST_SECTION_DB);
|
2016-04-15 04:50:02 +02:00
|
|
|
use constant MANIFEST_SECTION_TARGET_PATH => 'target:path';
|
|
|
|
push @EXPORT, qw(MANIFEST_SECTION_TARGET_PATH);
|
|
|
|
use constant MANIFEST_SECTION_TARGET_FILE => 'target:file';
|
|
|
|
push @EXPORT, qw(MANIFEST_SECTION_TARGET_FILE);
|
|
|
|
use constant MANIFEST_SECTION_TARGET_LINK => 'target:link';
|
|
|
|
push @EXPORT, qw(MANIFEST_SECTION_TARGET_LINK);
|
2015-06-14 00:25:49 +02:00
|
|
|
|
|
|
|
# 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);
|
2016-02-20 02:32:02 +02:00
|
|
|
use constant MANIFEST_KEY_ONLINE => 'option-online';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_ONLINE);
|
2015-06-14 00:25:49 +02:00
|
|
|
|
|
|
|
# Information about the database that was backed up
|
2016-04-15 04:50:02 +02:00
|
|
|
use constant MANIFEST_KEY_DB_ID => 'db-id';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_DB_ID);
|
2015-06-14 00:25:49 +02:00
|
|
|
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);
|
2016-05-11 15:21:39 +02:00
|
|
|
use constant MANIFEST_KEY_DB_LAST_SYSTEM_ID => 'db-last-system-id';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_DB_LAST_SYSTEM_ID);
|
2015-06-14 00:25:49 +02:00
|
|
|
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);
|
2016-04-15 04:50:02 +02:00
|
|
|
use constant MANIFEST_SUBKEY_FILE => 'file';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_FILE);
|
2015-06-14 00:25:49 +02:00
|
|
|
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_MODE => 'mode';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_MODE);
|
|
|
|
use constant MANIFEST_SUBKEY_TIMESTAMP => 'timestamp';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_TIMESTAMP);
|
2016-04-15 04:50:02 +02:00
|
|
|
use constant MANIFEST_SUBKEY_TYPE => 'type';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_TYPE);
|
2015-06-14 00:25:49 +02:00
|
|
|
use constant MANIFEST_SUBKEY_PATH => 'path';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_PATH);
|
|
|
|
use constant MANIFEST_SUBKEY_REFERENCE => 'reference';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_REFERENCE);
|
2016-04-15 04:50:02 +02:00
|
|
|
use constant MANIFEST_SUBKEY_REPO_SIZE => 'repo-size';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_REPO_SIZE);
|
2015-06-14 00:25:49 +02:00
|
|
|
use constant MANIFEST_SUBKEY_SIZE => 'size';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_SIZE);
|
2016-04-15 04:50:02 +02:00
|
|
|
use constant MANIFEST_SUBKEY_TABLESPACE_ID => 'tablespace-id';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_TABLESPACE_ID);
|
|
|
|
use constant MANIFEST_SUBKEY_TABLESPACE_NAME => 'tablespace-name';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_TABLESPACE_NAME);
|
2015-06-14 00:25:49 +02:00
|
|
|
use constant MANIFEST_SUBKEY_USER => 'user';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_USER);
|
2015-01-07 17:59:43 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Database locations for important files/paths
|
|
|
|
####################################################################################################################################
|
2016-05-14 16:33:12 +02:00
|
|
|
use constant DB_PATH_GLOBAL => 'global';
|
|
|
|
push @EXPORT, qw(DB_PATH_GLOBAL);
|
2016-04-15 04:50:02 +02:00
|
|
|
use constant DB_PATH_PGTBLSPC => 'pg_tblspc';
|
|
|
|
push @EXPORT, qw(DB_PATH_PGTBLSPC);
|
2016-05-14 16:33:12 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
use constant DB_FILE_POSTMASTERPID => 'postmaster.pid';
|
|
|
|
push @EXPORT, qw(DB_FILE_POSTMASTERPID);
|
|
|
|
|
|
|
|
use constant DB_FILE_BACKUPLABEL => 'backup_label';
|
|
|
|
push @EXPORT, qw(DB_FILE_BACKUPLABEL);
|
|
|
|
use constant DB_FILE_BACKUPLABELOLD => DB_FILE_BACKUPLABEL . '.old';
|
|
|
|
push @EXPORT, qw(DB_FILE_BACKUPLABELOLD);
|
|
|
|
use constant DB_FILE_PGCONTROL => DB_PATH_GLOBAL . '/pg_control';
|
|
|
|
push @EXPORT, qw(DB_FILE_PGCONTROL);
|
|
|
|
use constant DB_FILE_PGVERSION => 'PG_VERSION';
|
|
|
|
push @EXPORT, qw(DB_FILE_PGVERSION);
|
|
|
|
use constant DB_FILE_RECOVERYCONF => 'recovery.conf';
|
|
|
|
push @EXPORT, qw(DB_FILE_RECOVERYCONF);
|
|
|
|
use constant DB_FILE_RECOVERYDONE => 'recovery.done';
|
|
|
|
push @EXPORT, qw(DB_FILE_RECOVERYDONE);
|
|
|
|
use constant DB_FILE_TABLESPACEMAP => 'tablespace_map';
|
|
|
|
push @EXPORT, qw(DB_FILE_TABLESPACEMAP);
|
2016-04-15 04:50:02 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Manifest locations for important files/paths
|
|
|
|
####################################################################################################################################
|
2016-05-14 16:33:12 +02:00
|
|
|
use constant MANIFEST_FILE_PGCONTROL => MANIFEST_TARGET_PGDATA . '/' . DB_FILE_PGCONTROL;
|
2016-04-15 04:50:02 +02:00
|
|
|
push @EXPORT, qw(MANIFEST_FILE_PGCONTROL);
|
2016-05-14 16:33:12 +02:00
|
|
|
use constant MANIFEST_FILE_TABLESPACEMAP => MANIFEST_TARGET_PGDATA . '/' . DB_FILE_TABLESPACEMAP;
|
|
|
|
push @EXPORT, qw(MANIFEST_FILE_TABLESPACEMAP);
|
2016-04-15 04:50:02 +02:00
|
|
|
|
2016-05-11 15:21:39 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Minimum ID for a user object in postgres
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant DB_USER_OBJECT_MINIMUM_ID => 16384;
|
|
|
|
push @EXPORT, qw(DB_USER_OBJECT_MINIMUM_ID);
|
|
|
|
|
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
|
|
|
# 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
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
|
2015-01-07 17:59:43 +02:00
|
|
|
####################################################################################################################################
|
2016-04-15 04:50:02 +02:00
|
|
|
# get
|
2015-01-08 19:04:56 +02:00
|
|
|
#
|
2016-04-15 04:50:02 +02:00
|
|
|
# Get a value.
|
2015-01-08 19:04:56 +02:00
|
|
|
####################################################################################################################################
|
2016-04-15 04:50:02 +02:00
|
|
|
sub get
|
2015-01-08 19:04:56 +02:00
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $strSection = shift;
|
|
|
|
my $strKey = shift;
|
|
|
|
my $strSubKey = shift;
|
2016-04-15 04:50:02 +02:00
|
|
|
my $bRequired = shift;
|
|
|
|
my $oDefault = shift;
|
2015-01-08 19:04:56 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
my $oValue = $self->SUPER::get($strSection, $strKey, $strSubKey, false);
|
2015-01-08 19:04:56 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
if (!defined($oValue) && defined($strKey) && defined($strSubKey) &&
|
|
|
|
($strSection eq MANIFEST_SECTION_TARGET_FILE || $strSection eq MANIFEST_SECTION_TARGET_PATH ||
|
|
|
|
$strSection eq MANIFEST_SECTION_TARGET_LINK) &&
|
|
|
|
($strSubKey eq MANIFEST_SUBKEY_USER || $strSubKey eq MANIFEST_SUBKEY_GROUP ||
|
|
|
|
$strSubKey eq MANIFEST_SUBKEY_MODE) &&
|
|
|
|
$self->test($strSection, $strKey))
|
|
|
|
{
|
|
|
|
$oValue = $self->SUPER::get("${strSection}:default", $strSubKey, undef, $bRequired, $oDefault);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$oValue = $self->SUPER::get($strSection, $strKey, $strSubKey, $bRequired, $oDefault);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $oValue;
|
2015-01-08 19:04:56 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 23:05:15 +02:00
|
|
|
####################################################################################################################################
|
2016-04-15 04:50:02 +02:00
|
|
|
# boolGet
|
2015-01-20 23:05:15 +02:00
|
|
|
#
|
2016-04-15 04:50:02 +02:00
|
|
|
# Get a numeric value.
|
2015-01-20 23:05:15 +02:00
|
|
|
####################################################################################################################################
|
2016-04-15 04:50:02 +02:00
|
|
|
sub boolGet
|
2015-01-20 23:05:15 +02:00
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $strSection = shift;
|
|
|
|
my $strValue = shift;
|
2016-04-15 04:50:02 +02:00
|
|
|
my $strSubValue = shift;
|
|
|
|
my $bRequired = shift;
|
|
|
|
my $bDefault = shift;
|
2015-01-20 23:05:15 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
return $self->get($strSection, $strValue, $strSubValue, $bRequired,
|
|
|
|
defined($bDefault) ? ($bDefault ? INI_TRUE : INI_FALSE) : undef) ? true : false;
|
2015-01-20 23:05:15 +02:00
|
|
|
}
|
|
|
|
|
2015-01-08 19:04:56 +02:00
|
|
|
####################################################################################################################################
|
2016-04-15 04:50:02 +02:00
|
|
|
# numericGet
|
2015-01-08 19:04:56 +02:00
|
|
|
#
|
2016-04-15 04:50:02 +02:00
|
|
|
# Get a numeric value.
|
2015-01-08 19:04:56 +02:00
|
|
|
####################################################################################################################################
|
2016-04-15 04:50:02 +02:00
|
|
|
sub numericGet
|
2015-01-08 19:04:56 +02:00
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $strSection = shift;
|
2015-01-21 20:57:58 +02:00
|
|
|
my $strValue = shift;
|
2016-04-15 04:50:02 +02:00
|
|
|
my $strSubValue = shift;
|
|
|
|
my $bRequired = shift;
|
|
|
|
my $nDefault = shift;
|
2015-01-08 19:04:56 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
return $self->get($strSection, $strValue, $strSubValue, $bRequired,
|
|
|
|
defined($nDefault) ? $nDefault + 0 : undef) + 0;
|
|
|
|
}
|
2015-01-08 19:04:56 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# tablespacePathGet
|
|
|
|
#
|
|
|
|
# Get the unique path assigned by Postgres for the tablespace.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub tablespacePathGet
|
|
|
|
{
|
|
|
|
my $self = shift;
|
2015-01-21 20:57:58 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
return('PG_' . $self->get(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_DB_VERSION) .
|
|
|
|
'_' . $self->get(MANIFEST_SECTION_BACKUP_DB, MANIFEST_KEY_CATALOG));
|
|
|
|
}
|
2015-01-21 20:57:58 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# dbPathGet
|
|
|
|
#
|
|
|
|
# Convert a repo path to where the file actually belongs in the db.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub dbPathGet
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $strDbPath = shift;
|
|
|
|
my $strFile = shift;
|
2015-01-21 02:04:45 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
my $strDbFile = defined($strDbPath) ? "${strDbPath}/" : '';
|
2015-01-23 03:11:33 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
if (index($strFile, MANIFEST_TARGET_PGDATA . '/') == 0)
|
|
|
|
{
|
|
|
|
$strDbFile .= substr($strFile, length(MANIFEST_TARGET_PGDATA) + 1);
|
2015-01-21 02:04:45 +02:00
|
|
|
}
|
2016-04-15 04:50:02 +02:00
|
|
|
else
|
2015-06-14 00:25:49 +02:00
|
|
|
{
|
2016-04-15 04:50:02 +02:00
|
|
|
$strDbFile .= $strFile;
|
2015-06-14 00:25:49 +02:00
|
|
|
}
|
2016-04-15 04:50:02 +02:00
|
|
|
|
|
|
|
return $strDbFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# repoPathGet
|
|
|
|
#
|
|
|
|
# Convert a database path to where to file is located in the repo.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub repoPathGet
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $strTarget = shift;
|
|
|
|
my $strFile = shift;
|
|
|
|
|
|
|
|
my $strRepoFile = $strTarget;
|
|
|
|
|
|
|
|
if ($self->isTargetTablespace($strTarget))
|
2015-01-20 23:05:15 +02:00
|
|
|
{
|
2016-04-15 04:50:02 +02:00
|
|
|
$strRepoFile .= '/' . $self->tablespacePathGet();
|
2015-01-20 23:05:15 +02:00
|
|
|
}
|
2016-04-15 04:50:02 +02:00
|
|
|
|
|
|
|
if (defined($strFile))
|
2015-01-21 01:00:03 +02:00
|
|
|
{
|
2016-04-15 04:50:02 +02:00
|
|
|
$strRepoFile .= "/${strFile}";
|
2015-01-21 01:00:03 +02:00
|
|
|
}
|
2016-04-15 04:50:02 +02:00
|
|
|
|
|
|
|
return $strRepoFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# isTargetValid
|
|
|
|
#
|
|
|
|
# Determine if a target is valid.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub isTargetValid
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $strTarget = shift;
|
|
|
|
my $bError = shift;
|
|
|
|
|
|
|
|
if (!defined($strTarget))
|
2015-01-23 03:11:33 +02:00
|
|
|
{
|
2016-04-15 04:50:02 +02:00
|
|
|
confess &log(ASSERT, 'target is not defined');
|
2015-01-23 03:11:33 +02:00
|
|
|
}
|
2016-04-15 04:50:02 +02:00
|
|
|
|
|
|
|
if (!$self->test(MANIFEST_SECTION_BACKUP_TARGET, $strTarget))
|
2015-01-08 19:04:56 +02:00
|
|
|
{
|
2016-04-15 04:50:02 +02:00
|
|
|
if (defined($bError) && $bError)
|
2015-01-08 19:04:56 +02:00
|
|
|
{
|
2016-04-15 04:50:02 +02:00
|
|
|
confess &log(ASSERT, "${strTarget} is not a valid target");
|
2015-01-08 19:04:56 +02:00
|
|
|
}
|
2015-01-07 17:59:43 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
return false;
|
2015-01-07 17:59:43 +02:00
|
|
|
}
|
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
return true;
|
2015-01-07 17:59:43 +02:00
|
|
|
}
|
|
|
|
|
2016-02-02 21:33:15 +02:00
|
|
|
####################################################################################################################################
|
2016-04-15 04:50:02 +02:00
|
|
|
# isTargetLink
|
2016-02-02 21:33:15 +02:00
|
|
|
#
|
2016-04-15 04:50:02 +02:00
|
|
|
# Determine if a target is a link.
|
2016-02-02 21:33:15 +02:00
|
|
|
####################################################################################################################################
|
2016-04-15 04:50:02 +02:00
|
|
|
sub isTargetLink
|
2016-02-02 21:33:15 +02:00
|
|
|
{
|
|
|
|
my $self = shift;
|
2016-04-15 04:50:02 +02:00
|
|
|
my $strTarget = shift;
|
2016-02-02 21:33:15 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
$self->isTargetValid($strTarget, true);
|
|
|
|
|
|
|
|
return $self->test(MANIFEST_SECTION_BACKUP_TARGET, $strTarget, MANIFEST_SUBKEY_TYPE, MANIFEST_VALUE_LINK);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# isTargetFile
|
|
|
|
#
|
|
|
|
# Determine if a target is a file link.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub isTargetFile
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $strTarget = shift;
|
|
|
|
|
|
|
|
$self->isTargetValid($strTarget, true);
|
|
|
|
|
|
|
|
return $self->test(MANIFEST_SECTION_BACKUP_TARGET, $strTarget, MANIFEST_SUBKEY_FILE);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# isTargetTablespace
|
|
|
|
#
|
|
|
|
# Determine if a target is a tablespace.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub isTargetTablespace
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
my $strTarget = shift;
|
|
|
|
|
|
|
|
$self->isTargetValid($strTarget, true);
|
|
|
|
|
|
|
|
return $self->test(MANIFEST_SECTION_BACKUP_TARGET, $strTarget, MANIFEST_SUBKEY_TABLESPACE_ID);
|
2016-02-02 21:33:15 +02:00
|
|
|
}
|
|
|
|
|
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,
|
2016-04-15 04:50:02 +02:00
|
|
|
$strPath,
|
2015-08-29 20:20:46 +02:00
|
|
|
$oLastManifest,
|
2016-02-20 02:32:02 +02:00
|
|
|
$bOnline,
|
2015-08-29 20:20:46 +02:00
|
|
|
$oTablespaceMapRef,
|
2016-05-11 15:21:39 +02:00
|
|
|
$oDatabaseMapRef,
|
2016-04-15 04:50:02 +02:00
|
|
|
$strLevel,
|
|
|
|
$bTablespace,
|
|
|
|
$strParentPath,
|
|
|
|
$strFilter
|
2015-08-29 20:20:46 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
OP_MANIFEST_BUILD, \@_,
|
|
|
|
{name => 'oFile'},
|
2016-04-15 04:50:02 +02:00
|
|
|
{name => 'strPath'},
|
2015-08-29 20:20:46 +02:00
|
|
|
{name => 'oLastManifest', required => false},
|
2016-02-20 02:32:02 +02:00
|
|
|
{name => 'bOnline'},
|
2015-08-29 20:20:46 +02:00
|
|
|
{name => 'oTablespaceMapRef', required => false},
|
2016-05-11 15:21:39 +02:00
|
|
|
{name => 'oDatabaseMapRef', required => false},
|
2016-04-15 04:50:02 +02:00
|
|
|
{name => 'strLevel', required => false},
|
|
|
|
{name => 'bTablespace', required => false},
|
|
|
|
{name => 'strParentPath', required => false},
|
|
|
|
{name => 'strFilter', required => false}
|
2015-08-29 20:20:46 +02:00
|
|
|
);
|
2015-02-03 01:33:11 +02:00
|
|
|
|
2015-02-01 01:15:08 +02:00
|
|
|
if (!defined($strLevel))
|
|
|
|
{
|
2016-04-15 04:50:02 +02:00
|
|
|
$strLevel = MANIFEST_TARGET_PGDATA;
|
2015-02-03 01:33:11 +02:00
|
|
|
|
2016-02-20 02:32:02 +02:00
|
|
|
# If not online then build the tablespace map from pg_tblspc path
|
|
|
|
if (!$bOnline && !defined($oTablespaceMapRef))
|
2015-02-01 01:23:37 +02:00
|
|
|
{
|
|
|
|
$oTablespaceMapRef = {};
|
|
|
|
|
|
|
|
my %oTablespaceManifestHash;
|
2016-04-15 04:50:02 +02:00
|
|
|
$oFile->manifest(PATH_DB_ABSOLUTE, $strPath . '/' . DB_PATH_PGTBLSPC, \%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
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
${$oTablespaceMapRef}{oid}{$strName}{name} = "ts${strName}";
|
2015-02-01 01:23:37 +02:00
|
|
|
}
|
|
|
|
}
|
2015-02-01 01:15:08 +02:00
|
|
|
}
|
2016-04-15 04:50:02 +02:00
|
|
|
|
|
|
|
$self->set(MANIFEST_SECTION_BACKUP_TARGET, $strLevel, MANIFEST_SUBKEY_PATH, $strPath);
|
|
|
|
$self->set(MANIFEST_SECTION_BACKUP_TARGET, $strLevel, MANIFEST_SUBKEY_TYPE,
|
|
|
|
$strLevel eq MANIFEST_TARGET_PGDATA ? MANIFEST_VALUE_PATH : MANIFEST_VALUE_LINK);
|
|
|
|
|
|
|
|
if ($bTablespace)
|
|
|
|
{
|
|
|
|
my $iTablespaceId = (split('\/', $strLevel))[1];
|
|
|
|
|
|
|
|
if (!defined(${$oTablespaceMapRef}{oid}{$iTablespaceId}{name}))
|
|
|
|
{
|
|
|
|
confess &log(ASSERT, "tablespace with oid ${iTablespaceId} not found in tablespace map\n" .
|
|
|
|
"HINT: was a tablespace created or dropped during the backup?");
|
|
|
|
}
|
|
|
|
|
|
|
|
$self->set(MANIFEST_SECTION_BACKUP_TARGET, $strLevel, MANIFEST_SUBKEY_TABLESPACE_ID, $iTablespaceId);
|
|
|
|
$self->set(MANIFEST_SECTION_BACKUP_TARGET, $strLevel, MANIFEST_SUBKEY_TABLESPACE_NAME,
|
|
|
|
${$oTablespaceMapRef}{oid}{$iTablespaceId}{name});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index($strPath, '/') != 0)
|
2016-02-02 21:33:15 +02:00
|
|
|
{
|
2016-04-15 04:50:02 +02:00
|
|
|
if (!defined($strParentPath))
|
|
|
|
{
|
|
|
|
confess &log(ASSERT, "cannot get manifest for '${strPath}' when no parent path is specified");
|
|
|
|
}
|
|
|
|
|
|
|
|
$strPath = pathAbsolute($strParentPath, $strPath);
|
2016-02-02 21:33:15 +02:00
|
|
|
}
|
2015-02-01 01:15:08 +02:00
|
|
|
|
|
|
|
# Get the manifest for this level
|
|
|
|
my %oManifestHash;
|
2016-04-15 04:50:02 +02:00
|
|
|
$oFile->manifest(PATH_DB_ABSOLUTE, $strPath, \%oManifestHash);
|
|
|
|
my $strManifestType = MANIFEST_VALUE_LINK;
|
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
|
|
|
{
|
2016-04-15 04:50:02 +02:00
|
|
|
my $strFile = $strLevel;
|
|
|
|
|
|
|
|
if ($strName ne '.')
|
|
|
|
{
|
|
|
|
# Make sure the current file matches the filter or any files under the filter
|
|
|
|
if (defined($strFilter) && $strName ne $strFilter && index($strName, "${strFilter}/") != 0)
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($strManifestType eq MANIFEST_VALUE_LINK)
|
|
|
|
{
|
|
|
|
if ($oManifestHash{name}{$strName}{type} eq 'l')
|
|
|
|
{
|
|
|
|
confess &log(ERROR, 'link ' .
|
|
|
|
$self->dbPathGet(
|
|
|
|
$self->get(MANIFEST_SECTION_BACKUP_TARGET, MANIFEST_TARGET_PGDATA, MANIFEST_SUBKEY_PATH), $strLevel) .
|
|
|
|
' (' . $self->get(MANIFEST_SECTION_BACKUP_TARGET, $strLevel, MANIFEST_SUBKEY_PATH) . ')' .
|
|
|
|
' cannot reference another link', ERROR_LINK_DESTINATION);
|
|
|
|
}
|
|
|
|
|
|
|
|
$strFile = dirname($strFile);
|
|
|
|
$self->set(MANIFEST_SECTION_BACKUP_TARGET, $strLevel, MANIFEST_SUBKEY_PATH,
|
|
|
|
dirname($self->get(MANIFEST_SECTION_BACKUP_TARGET, $strLevel, MANIFEST_SUBKEY_PATH)));
|
|
|
|
$self->set(MANIFEST_SECTION_BACKUP_TARGET, $strLevel, MANIFEST_SUBKEY_FILE, $strName);
|
|
|
|
}
|
|
|
|
|
|
|
|
$strFile .= "/${strName}";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strManifestType = MANIFEST_VALUE_PATH;
|
|
|
|
}
|
|
|
|
|
2015-02-01 01:15:08 +02:00
|
|
|
# Skip certain files during backup
|
2016-04-15 04:50:02 +02:00
|
|
|
if ($strLevel eq MANIFEST_TARGET_PGDATA &&
|
|
|
|
(($strName =~ /^pg\_xlog\/.*/ && $bOnline) || # pg_xlog/ - this will be reconstructed
|
2016-05-14 16:33:12 +02:00
|
|
|
$strName eq DB_FILE_BACKUPLABELOLD || # backup_label.old - old backup labels are not useful
|
|
|
|
$strName eq DB_FILE_POSTMASTERPID || # postmaster.pid - to avoid confusing postgres after restore
|
|
|
|
$strName eq DB_FILE_RECOVERYCONF || # recovery.conf - doesn't make sense to backup this file
|
|
|
|
$strName eq DB_FILE_RECOVERYDONE)) # recovery.done - doesn't make sense to backup this file
|
2015-02-01 01:15:08 +02:00
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2016-01-15 14:07:00 +02:00
|
|
|
my $cType = $oManifestHash{name}{$strName}{type};
|
2016-04-15 04:50:02 +02:00
|
|
|
my $strSection = MANIFEST_SECTION_TARGET_PATH;
|
2015-02-01 01:15:08 +02:00
|
|
|
|
|
|
|
if ($cType eq 'f')
|
|
|
|
{
|
2016-04-15 04:50:02 +02:00
|
|
|
$strSection = MANIFEST_SECTION_TARGET_FILE;
|
2015-02-01 01:15:08 +02:00
|
|
|
}
|
|
|
|
elsif ($cType eq 'l')
|
|
|
|
{
|
2016-04-15 04:50:02 +02:00
|
|
|
$strSection = MANIFEST_SECTION_TARGET_LINK;
|
2015-02-01 01:15:08 +02:00
|
|
|
}
|
|
|
|
elsif ($cType ne 'd')
|
|
|
|
{
|
|
|
|
confess &log(ASSERT, "unrecognized file type $cType for file $strName");
|
|
|
|
}
|
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
# Make sure that DB_PATH_PGTBLSPC contains only absolute links that do not point inside PGDATA
|
|
|
|
my $bTablespace = false;
|
|
|
|
|
|
|
|
if (index($strName, DB_PATH_PGTBLSPC . '/') == 0 && $strLevel eq MANIFEST_TARGET_PGDATA)
|
2016-01-15 14:07:00 +02:00
|
|
|
{
|
2016-04-15 04:50:02 +02:00
|
|
|
$bTablespace = true;
|
|
|
|
$strFile = MANIFEST_TARGET_PGDATA . '/' . $strName;
|
2016-01-15 14:07:00 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
# Check for files in DB_PATH_PGTBLSPC that are not links
|
|
|
|
if ($oManifestHash{name}{$strName}{type} ne 'l')
|
2016-01-15 14:07:00 +02:00
|
|
|
{
|
2016-04-15 04:50:02 +02:00
|
|
|
confess &log(ERROR, "${strName} is not a symlink - " . DB_PATH_PGTBLSPC . ' should contain only symlinks',
|
|
|
|
ERROR_LINK_EXPECTED);
|
2016-01-15 14:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Check for tablespaces in PGDATA
|
2016-04-15 04:50:02 +02:00
|
|
|
if (index($oManifestHash{name}{$strName}{link_destination}, $strPath) == 0 ||
|
|
|
|
(index($oManifestHash{name}{$strName}{link_destination}, '/') != 0 &&
|
|
|
|
index(pathAbsolute($strPath . '/' . DB_PATH_PGTBLSPC,
|
|
|
|
$oManifestHash{name}{$strName}{link_destination}), $strPath) == 0))
|
2016-01-15 14:07:00 +02:00
|
|
|
{
|
|
|
|
confess &log(ERROR, 'tablespace symlink ' . $oManifestHash{name}{$strName}{link_destination} .
|
2016-04-15 04:50:02 +02:00
|
|
|
' destination 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-04-15 04:50:02 +02:00
|
|
|
$self->set($strSection, $strFile, MANIFEST_SUBKEY_USER, $oManifestHash{name}{$strName}{user});
|
|
|
|
$self->set($strSection, $strFile, 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-04-15 04:50:02 +02:00
|
|
|
$self->set($strSection, $strFile, 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')
|
|
|
|
{
|
2016-04-15 04:50:02 +02:00
|
|
|
$self->set($strSection, $strFile, MANIFEST_SUBKEY_TIMESTAMP,
|
2016-01-15 14:07:00 +02:00
|
|
|
$oManifestHash{name}{$strName}{modification_time} + 0);
|
2016-04-15 04:50:02 +02:00
|
|
|
$self->set($strSection, $strFile, 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')
|
|
|
|
{
|
2016-04-15 04:50:02 +02:00
|
|
|
my $strLinkDestination = $oManifestHash{name}{$strName}{link_destination};
|
|
|
|
$self->set($strSection, $strFile, MANIFEST_SUBKEY_DESTINATION, $strLinkDestination);
|
|
|
|
|
|
|
|
# If this is a tablespace then set the filter to use for the next level
|
|
|
|
my $strFilter;
|
2015-02-01 01:15:08 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
if ($bTablespace)
|
2015-02-01 01:15:08 +02:00
|
|
|
{
|
2016-04-15 04:50:02 +02:00
|
|
|
$strFilter = $self->tablespacePathGet();
|
2015-02-01 01:15:08 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
$self->set(MANIFEST_SECTION_TARGET_PATH, MANIFEST_TARGET_PGTBLSPC, undef,
|
|
|
|
$self->get(MANIFEST_SECTION_TARGET_PATH, MANIFEST_TARGET_PGDATA));
|
2015-02-01 01:15:08 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
# PGDATA prefix was only needed for the link so strip it off before recursing
|
|
|
|
$strFile = substr($strFile, length(MANIFEST_TARGET_PGDATA) + 1);
|
2015-02-01 01:15:08 +02:00
|
|
|
}
|
2016-04-15 04:50:02 +02:00
|
|
|
|
|
|
|
$strPath = dirname("${strPath}/${strName}");
|
|
|
|
|
2016-05-11 15:21:39 +02:00
|
|
|
$self->build($oFile, $strLinkDestination, undef, $bOnline, $oTablespaceMapRef, $oDatabaseMapRef,
|
2016-04-15 04:50:02 +02:00
|
|
|
$strFile, $bTablespace, $strPath, $strFilter, $strLinkDestination);
|
2015-02-01 01:15:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# If this is the base level then do post-processing
|
2016-04-15 04:50:02 +02:00
|
|
|
if ($strLevel eq MANIFEST_TARGET_PGDATA)
|
2015-02-01 01:15:08 +02:00
|
|
|
{
|
|
|
|
my $bTimeInFuture = false;
|
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
# Wait for the remainder of the second when doing online backups. This is done because most filesystems only have a one
|
|
|
|
# second resolution and Postgres will still be modifying files during the second that the manifest is built and this could
|
|
|
|
# lead to an invalid diff/incr backup later when using timestamps to determine which files have changed. Offline backups do
|
|
|
|
# not wait because it makes testing much faster and Postgres should not be running (if it is the backup will not be
|
|
|
|
# consistent anyway and the one-second resolution problem is the least of our worries).
|
|
|
|
my $lTimeBegin = $oFile->wait(PATH_DB_ABSOLUTE, $bOnline);
|
|
|
|
|
|
|
|
# Check that links are valid
|
|
|
|
$self->linkCheck();
|
2015-02-01 01:15:08 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
if (defined($oLastManifest))
|
2015-02-01 01:15:08 +02:00
|
|
|
{
|
2016-04-15 04:50:02 +02:00
|
|
|
$self->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_PRIOR, undef,
|
|
|
|
$oLastManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_LABEL));
|
|
|
|
}
|
2015-02-01 01:15:08 +02:00
|
|
|
|
2016-05-11 15:21:39 +02:00
|
|
|
# Store database map information when provided during an online backup.
|
|
|
|
foreach my $strDbName (sort(keys(%{${$oDatabaseMapRef}{name}})))
|
|
|
|
{
|
|
|
|
$self->numericSet(MANIFEST_SECTION_DB, $strDbName, MANIFEST_KEY_DB_ID,
|
|
|
|
${$oDatabaseMapRef}{'name'}{$strDbName}{&MANIFEST_KEY_DB_ID});
|
|
|
|
$self->numericSet(MANIFEST_SECTION_DB, $strDbName, MANIFEST_KEY_DB_LAST_SYSTEM_ID,
|
|
|
|
${$oDatabaseMapRef}{'name'}{$strDbName}{&MANIFEST_KEY_DB_LAST_SYSTEM_ID});
|
|
|
|
}
|
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
# Loop though all files
|
|
|
|
foreach my $strName ($self->keys(MANIFEST_SECTION_TARGET_FILE))
|
|
|
|
{
|
|
|
|
# If modification time is in the future (in this backup OR the last backup) set warning flag and do not
|
|
|
|
# allow a reference
|
|
|
|
if ($self->numericGet(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_TIMESTAMP) > $lTimeBegin ||
|
|
|
|
(defined($oLastManifest) &&
|
|
|
|
$oLastManifest->test(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_FUTURE, 'y')))
|
2015-02-01 01:15:08 +02:00
|
|
|
{
|
2016-04-15 04:50:02 +02:00
|
|
|
$bTimeInFuture = true;
|
|
|
|
|
|
|
|
# Only mark as future if still in the future in the current backup
|
|
|
|
if ($self->numericGet(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_TIMESTAMP) > $lTimeBegin)
|
2015-02-01 01:15:08 +02:00
|
|
|
{
|
2016-04-15 04:50:02 +02:00
|
|
|
$self->set(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_FUTURE, 'y');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# Else check if modification time and size are unchanged since last backup
|
|
|
|
elsif (defined($oLastManifest) && $oLastManifest->test(MANIFEST_SECTION_TARGET_FILE, $strName) &&
|
|
|
|
$self->numericGet(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_SIZE) ==
|
|
|
|
$oLastManifest->get(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_SIZE) &&
|
|
|
|
$self->numericGet(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_TIMESTAMP) ==
|
|
|
|
$oLastManifest->get(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_TIMESTAMP))
|
|
|
|
{
|
|
|
|
# Copy reference from previous backup if possible
|
|
|
|
if ($oLastManifest->test(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_REFERENCE))
|
|
|
|
{
|
|
|
|
$self->set(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_REFERENCE,
|
|
|
|
$oLastManifest->get(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_REFERENCE));
|
|
|
|
}
|
|
|
|
# Otherwise the reference is to the previous backup
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$self->set(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_REFERENCE,
|
|
|
|
$oLastManifest->get(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_LABEL));
|
|
|
|
}
|
2015-02-01 01:15:08 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
# Copy the checksum from previous manifest
|
|
|
|
if ($oLastManifest->test(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_CHECKSUM))
|
|
|
|
{
|
|
|
|
$self->set(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_CHECKSUM,
|
|
|
|
$oLastManifest->get(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_CHECKSUM));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($oLastManifest->test(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_REPO_SIZE))
|
|
|
|
{
|
|
|
|
$self->set(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_REPO_SIZE,
|
|
|
|
$oLastManifest->get(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_REPO_SIZE));
|
2015-02-01 01:15:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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
|
2016-04-15 04:50:02 +02:00
|
|
|
$self->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_TIMESTAMP_COPY_START, undef, $lTimeBegin + ($bOnline ? 1 : 0));
|
2015-02-01 01:15:08 +02:00
|
|
|
}
|
2015-08-29 20:20:46 +02:00
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
$self->buildDefault();
|
|
|
|
|
2015-08-29 20:20:46 +02:00
|
|
|
# Return from function and log return values if any
|
2016-04-15 04:50:02 +02:00
|
|
|
return logDebugReturn($strOperation);
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# linkCheck
|
|
|
|
#
|
|
|
|
# Check all link targets and make sure none of them are a subset of another link. In theory it would be possible to resolve the
|
|
|
|
# dependencies and generate a valid backup/restore but it's really complicated and there don't seem to be any compelling use cases.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub linkCheck
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my ($strOperation) = logDebugParam(OP_MANIFEST . '->linkCheck');
|
|
|
|
|
|
|
|
# Working variable
|
|
|
|
my $strBasePath = $self->get(MANIFEST_SECTION_BACKUP_TARGET, MANIFEST_TARGET_PGDATA, MANIFEST_SUBKEY_PATH);
|
|
|
|
|
|
|
|
foreach my $strTargetParent ($self->keys(MANIFEST_SECTION_BACKUP_TARGET))
|
|
|
|
{
|
|
|
|
if ($self->isTargetLink($strTargetParent))
|
|
|
|
{
|
|
|
|
my $strParentPath = $self->get(MANIFEST_SECTION_BACKUP_TARGET, $strTargetParent, MANIFEST_SUBKEY_PATH);
|
|
|
|
|
|
|
|
foreach my $strTargetChild ($self->keys(MANIFEST_SECTION_BACKUP_TARGET))
|
|
|
|
{
|
|
|
|
if ($self->isTargetLink($strTargetChild) && $strTargetParent ne $strTargetChild)
|
|
|
|
{
|
|
|
|
my $strChildPath = $self->get(MANIFEST_SECTION_BACKUP_TARGET, $strTargetChild, MANIFEST_SUBKEY_PATH);
|
|
|
|
|
|
|
|
if (index(pathAbsolute($strBasePath, $strChildPath), pathAbsolute($strBasePath, $strParentPath)) == 0)
|
|
|
|
{
|
|
|
|
confess &log(ERROR, 'link ' . $self->dbPathGet($strBasePath, $strTargetChild) .
|
|
|
|
" (${strChildPath}) references a subdirectory of or" .
|
|
|
|
" the same directory as link " . $self->dbPathGet($strBasePath, $strTargetParent) .
|
|
|
|
" (${strParentPath})", ERROR_LINK_DESTINATION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-14 16:39:56 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# fileAdd
|
|
|
|
#
|
|
|
|
# Add files to the manifest that were generated after the initial manifest build, e.g. backup_label, tablespace_map, and copied WAL
|
|
|
|
# files. Since the files were not in the original cluster the user, group, and mode must be defaulted.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub fileAdd
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my
|
|
|
|
(
|
|
|
|
$strOperation,
|
|
|
|
$strManifestFile,
|
|
|
|
$lModificationTime,
|
|
|
|
$lSize,
|
|
|
|
$strChecksum
|
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->fileAdd', \@_,
|
|
|
|
{name => 'strManifestFile'},
|
|
|
|
{name => 'lModificationTime'},
|
|
|
|
{name => 'lSize'},
|
|
|
|
{name => 'lChecksum'}
|
|
|
|
);
|
|
|
|
|
|
|
|
# Set manifest values
|
|
|
|
$self->set(MANIFEST_SECTION_TARGET_FILE, $strManifestFile, MANIFEST_SUBKEY_USER,
|
|
|
|
$self->get(MANIFEST_SECTION_TARGET_PATH, MANIFEST_TARGET_PGDATA, MANIFEST_SUBKEY_USER));
|
|
|
|
$self->set(MANIFEST_SECTION_TARGET_FILE, $strManifestFile, MANIFEST_SUBKEY_GROUP,
|
|
|
|
$self->get(MANIFEST_SECTION_TARGET_PATH, MANIFEST_TARGET_PGDATA, MANIFEST_SUBKEY_GROUP));
|
|
|
|
$self->set(MANIFEST_SECTION_TARGET_FILE, $strManifestFile, MANIFEST_SUBKEY_MODE, '0600');
|
|
|
|
$self->set(MANIFEST_SECTION_TARGET_FILE, $strManifestFile, MANIFEST_SUBKEY_TIMESTAMP, $lModificationTime);
|
|
|
|
$self->set(MANIFEST_SECTION_TARGET_FILE, $strManifestFile, MANIFEST_SUBKEY_SIZE, $lSize);
|
|
|
|
$self->set(MANIFEST_SECTION_TARGET_FILE, $strManifestFile, MANIFEST_SUBKEY_CHECKSUM, $strChecksum);
|
|
|
|
$self->buildDefault();
|
|
|
|
}
|
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# buildDefault
|
|
|
|
#
|
|
|
|
# Builds the default section.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub buildDefault
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my ($strOperation) = logDebugParam(OP_MANIFEST . '->buildDefault');
|
|
|
|
|
|
|
|
# Set defaults for subkeys that tend to repeat
|
|
|
|
foreach my $strSection (&MANIFEST_SECTION_TARGET_FILE, &MANIFEST_SECTION_TARGET_PATH, &MANIFEST_SECTION_TARGET_LINK)
|
|
|
|
{
|
|
|
|
foreach my $strSubKey (&MANIFEST_SUBKEY_USER, &MANIFEST_SUBKEY_GROUP, &MANIFEST_SUBKEY_MODE)
|
|
|
|
{
|
|
|
|
my %oDefault;
|
|
|
|
my $iSectionTotal = 0;
|
|
|
|
|
|
|
|
foreach my $strFile ($self->keys($strSection))
|
|
|
|
{
|
|
|
|
my $strValue = $self->get($strSection, $strFile, $strSubKey, false);
|
|
|
|
|
|
|
|
if (defined($strValue))
|
|
|
|
{
|
|
|
|
if (defined($oDefault{$strValue}))
|
|
|
|
{
|
|
|
|
$oDefault{$strValue}++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$oDefault{$strValue} = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$iSectionTotal++;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $strMaxValue;
|
|
|
|
my $iMaxValueTotal = 0;
|
|
|
|
|
|
|
|
foreach my $strValue (keys(%oDefault))
|
|
|
|
{
|
|
|
|
if ($oDefault{$strValue} > $iMaxValueTotal)
|
|
|
|
{
|
|
|
|
$iMaxValueTotal = $oDefault{$strValue};
|
|
|
|
$strMaxValue = $strValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined($strMaxValue) > 0 && $iMaxValueTotal > $iSectionTotal * MANIFEST_DEFAULT_MATCH_FACTOR)
|
|
|
|
{
|
|
|
|
$self->set("${strSection}:default", $strSubKey, undef, $strMaxValue);
|
|
|
|
|
|
|
|
foreach my $strFile ($self->keys($strSection))
|
|
|
|
{
|
|
|
|
if ($self->test($strSection, $strFile, $strSubKey, $strMaxValue))
|
|
|
|
{
|
|
|
|
$self->remove($strSection, $strFile, $strSubKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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;
|