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
|
|
|
|
2016-08-12 04:35:24 +02:00
|
|
|
use pgBackRest::DbVersion;
|
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;
|
2016-08-25 17:25:46 +02:00
|
|
|
use pgBackRest::Config::Config;
|
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);
|
2016-06-24 14:06:20 +02:00
|
|
|
use constant MANIFEST_KEY_LSN_START => 'backup-lsn-start';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_LSN_START);
|
|
|
|
use constant MANIFEST_KEY_LSN_STOP => 'backup-lsn-stop';
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_LSN_STOP);
|
2015-06-14 00:25:49 +02:00
|
|
|
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
|
2016-08-25 17:25:46 +02:00
|
|
|
use constant MANIFEST_KEY_BACKUP_STANDBY => 'option-' . OPTION_BACKUP_STANDBY;
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_BACKUP_STANDBY);
|
2015-06-14 00:25:49 +02:00
|
|
|
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);
|
2016-12-13 01:54:07 +02:00
|
|
|
use constant MANIFEST_KEY_CHECKSUM_PAGE => 'option-' . OPTION_CHECKSUM_PAGE;
|
|
|
|
push @EXPORT, qw(MANIFEST_KEY_CHECKSUM_PAGE);
|
2015-06-14 00:25:49 +02:00
|
|
|
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);
|
2016-12-13 01:54:07 +02:00
|
|
|
use constant MANIFEST_SUBKEY_CHECKSUM_PAGE => 'checksum-page';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_CHECKSUM_PAGE);
|
|
|
|
use constant MANIFEST_SUBKEY_CHECKSUM_PAGE_ERROR => 'checksum-page-error';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_CHECKSUM_PAGE_ERROR);
|
2015-06-14 00:25:49 +02:00
|
|
|
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);
|
2016-09-04 15:19:44 +02:00
|
|
|
use constant MANIFEST_SUBKEY_MASTER => 'master';
|
|
|
|
push @EXPORT, qw(MANIFEST_SUBKEY_MASTER);
|
2015-06-14 00:25:49 +02:00
|
|
|
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-08-25 17:25:46 +02:00
|
|
|
use constant DB_PATH_BASE => 'base';
|
|
|
|
push @EXPORT, qw(DB_PATH_BASE);
|
|
|
|
use constant DB_PATH_PGCLOG => 'pg_clog';
|
|
|
|
push @EXPORT, qw(DB_PATH_PGCLOG);
|
2016-05-14 16:33:12 +02:00
|
|
|
use constant DB_PATH_GLOBAL => 'global';
|
|
|
|
push @EXPORT, qw(DB_PATH_GLOBAL);
|
Exclude directories during backup that are cleaned, recreated, or zeroed by PostgreSQL at startup.
These include (depending on the version where they were introduced): pgsql_tmp, pg_dynshmem, pg_notify, pg_replslot, pg_serial, pg_snapshots, pg_stat_tmp, pg_subtrans. The postgresql.auto.conf.tmp file is now excluded in addition to files that were already excluded: backup_label.old, postmaster.opts, postmaster.pid, recovery.conf, recovery.done.
2016-08-16 15:35:16 +02:00
|
|
|
use constant DB_PATH_PGDYNSHMEM => 'pg_dynshmem';
|
|
|
|
push @EXPORT, qw(DB_PATH_PGDYNSHMEM);
|
2016-08-25 17:25:46 +02:00
|
|
|
use constant DB_PATH_PGMULTIXACT => 'pg_multixact';
|
|
|
|
push @EXPORT, qw(DB_PATH_PGMULTIXACT);
|
Exclude directories during backup that are cleaned, recreated, or zeroed by PostgreSQL at startup.
These include (depending on the version where they were introduced): pgsql_tmp, pg_dynshmem, pg_notify, pg_replslot, pg_serial, pg_snapshots, pg_stat_tmp, pg_subtrans. The postgresql.auto.conf.tmp file is now excluded in addition to files that were already excluded: backup_label.old, postmaster.opts, postmaster.pid, recovery.conf, recovery.done.
2016-08-16 15:35:16 +02:00
|
|
|
use constant DB_PATH_PGNOTIFY => 'pg_notify';
|
|
|
|
push @EXPORT, qw(DB_PATH_PGNOTIFY);
|
|
|
|
use constant DB_PATH_PGREPLSLOT => 'pg_replslot';
|
|
|
|
push @EXPORT, qw(DB_PATH_PGREPLSLOT);
|
|
|
|
use constant DB_PATH_PGSERIAL => 'pg_serial';
|
|
|
|
push @EXPORT, qw(DB_PATH_PGSERIAL);
|
|
|
|
use constant DB_PATH_PGSNAPSHOTS => 'pg_snapshots';
|
|
|
|
push @EXPORT, qw(DB_PATH_PGSNAPSHOTS);
|
|
|
|
use constant DB_PATH_PGSTATTMP => 'pg_stat_tmp';
|
|
|
|
push @EXPORT, qw(DB_PATH_PGSTATTMP);
|
|
|
|
use constant DB_PATH_PGSUBTRANS => 'pg_subtrans';
|
|
|
|
push @EXPORT, qw(DB_PATH_PGSUBTRANS);
|
2016-04-15 04:50:02 +02:00
|
|
|
use constant DB_PATH_PGTBLSPC => 'pg_tblspc';
|
|
|
|
push @EXPORT, qw(DB_PATH_PGTBLSPC);
|
2016-07-30 00:44:53 +02:00
|
|
|
use constant DB_PATH_PGXLOG => 'pg_xlog';
|
|
|
|
push @EXPORT, qw(DB_PATH_PGXLOG);
|
2016-05-14 16:33:12 +02:00
|
|
|
|
|
|
|
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);
|
2016-12-13 01:54:07 +02:00
|
|
|
use constant DB_FILE_PGFILENODEMAP => 'pg_filenode.map';
|
|
|
|
push @EXPORT, qw(DB_FILE_PGFILENODEMAP);
|
|
|
|
use constant DB_FILE_PGINTERNALINIT => 'pg_internal.init';
|
|
|
|
push @EXPORT, qw(DB_FILE_PGINTERNALINIT);
|
2016-05-14 16:33:12 +02:00
|
|
|
use constant DB_FILE_PGVERSION => 'PG_VERSION';
|
|
|
|
push @EXPORT, qw(DB_FILE_PGVERSION);
|
Exclude directories during backup that are cleaned, recreated, or zeroed by PostgreSQL at startup.
These include (depending on the version where they were introduced): pgsql_tmp, pg_dynshmem, pg_notify, pg_replslot, pg_serial, pg_snapshots, pg_stat_tmp, pg_subtrans. The postgresql.auto.conf.tmp file is now excluded in addition to files that were already excluded: backup_label.old, postmaster.opts, postmaster.pid, recovery.conf, recovery.done.
2016-08-16 15:35:16 +02:00
|
|
|
use constant DB_FILE_POSTGRESQLAUTOCONFTMP => 'postgresql.auto.conf.tmp';
|
|
|
|
push @EXPORT, qw(DB_FILE_POSTGRESQLAUTOCONFTMP);
|
2016-07-30 00:44:53 +02:00
|
|
|
use constant DB_FILE_POSTMASTEROPTS => 'postmaster.opts';
|
|
|
|
push @EXPORT, qw(DB_FILE_POSTMASTEROPTS);
|
|
|
|
use constant DB_FILE_POSTMASTERPID => 'postmaster.pid';
|
|
|
|
push @EXPORT, qw(DB_FILE_POSTMASTERPID);
|
2016-05-14 16:33:12 +02:00
|
|
|
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
|
|
|
|
Exclude directories during backup that are cleaned, recreated, or zeroed by PostgreSQL at startup.
These include (depending on the version where they were introduced): pgsql_tmp, pg_dynshmem, pg_notify, pg_replslot, pg_serial, pg_snapshots, pg_stat_tmp, pg_subtrans. The postgresql.auto.conf.tmp file is now excluded in addition to files that were already excluded: backup_label.old, postmaster.opts, postmaster.pid, recovery.conf, recovery.done.
2016-08-16 15:35:16 +02:00
|
|
|
use constant DB_FILE_PREFIX_TMP => 'pgsql_tmp';
|
|
|
|
push @EXPORT, qw(DB_FILE_PREFIX_TMP);
|
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Manifest locations for important files/paths
|
|
|
|
####################################################################################################################################
|
2016-08-25 17:25:46 +02:00
|
|
|
use constant MANIFEST_PATH_BASE => MANIFEST_TARGET_PGDATA . '/' . DB_PATH_BASE;
|
|
|
|
push @EXPORT, qw(MANIFEST_PATH_BASE);
|
|
|
|
use constant MANIFEST_PATH_PGCLOG => MANIFEST_TARGET_PGDATA . '/' . DB_PATH_PGCLOG;
|
|
|
|
push @EXPORT, qw(MANIFEST_PATH_PGCLOG);
|
|
|
|
use constant MANIFEST_PATH_GLOBAL => MANIFEST_TARGET_PGDATA . '/' . DB_PATH_GLOBAL;
|
|
|
|
push @EXPORT, qw(MANIFEST_PATH_GLOBAL);
|
Exclude directories during backup that are cleaned, recreated, or zeroed by PostgreSQL at startup.
These include (depending on the version where they were introduced): pgsql_tmp, pg_dynshmem, pg_notify, pg_replslot, pg_serial, pg_snapshots, pg_stat_tmp, pg_subtrans. The postgresql.auto.conf.tmp file is now excluded in addition to files that were already excluded: backup_label.old, postmaster.opts, postmaster.pid, recovery.conf, recovery.done.
2016-08-16 15:35:16 +02:00
|
|
|
use constant MANIFEST_PATH_PGDYNSHMEM => MANIFEST_TARGET_PGDATA . '/' . DB_PATH_PGDYNSHMEM;
|
|
|
|
push @EXPORT, qw(MANIFEST_PATH_PGDYNSHMEM);
|
2016-08-25 17:25:46 +02:00
|
|
|
use constant MANIFEST_PATH_PGMULTIXACT => MANIFEST_TARGET_PGDATA . '/' . DB_PATH_PGMULTIXACT;
|
|
|
|
push @EXPORT, qw(MANIFEST_PATH_PGMULTIXACT);
|
Exclude directories during backup that are cleaned, recreated, or zeroed by PostgreSQL at startup.
These include (depending on the version where they were introduced): pgsql_tmp, pg_dynshmem, pg_notify, pg_replslot, pg_serial, pg_snapshots, pg_stat_tmp, pg_subtrans. The postgresql.auto.conf.tmp file is now excluded in addition to files that were already excluded: backup_label.old, postmaster.opts, postmaster.pid, recovery.conf, recovery.done.
2016-08-16 15:35:16 +02:00
|
|
|
use constant MANIFEST_PATH_PGNOTIFY => MANIFEST_TARGET_PGDATA . '/' . DB_PATH_PGNOTIFY;
|
|
|
|
push @EXPORT, qw(MANIFEST_PATH_PGNOTIFY);
|
|
|
|
use constant MANIFEST_PATH_PGREPLSLOT => MANIFEST_TARGET_PGDATA . '/' . DB_PATH_PGREPLSLOT;
|
|
|
|
push @EXPORT, qw(MANIFEST_PATH_PGREPLSLOT);
|
|
|
|
use constant MANIFEST_PATH_PGSERIAL => MANIFEST_TARGET_PGDATA . '/' . DB_PATH_PGSERIAL;
|
|
|
|
push @EXPORT, qw(MANIFEST_PATH_PGSERIAL);
|
|
|
|
use constant MANIFEST_PATH_PGSNAPSHOTS => MANIFEST_TARGET_PGDATA . '/' . DB_PATH_PGSNAPSHOTS;
|
|
|
|
push @EXPORT, qw(MANIFEST_PATH_PGSNAPSHOTS);
|
|
|
|
use constant MANIFEST_PATH_PGSTATTMP => MANIFEST_TARGET_PGDATA . '/' . DB_PATH_PGSTATTMP;
|
|
|
|
push @EXPORT, qw(MANIFEST_PATH_PGSTATTMP);
|
|
|
|
use constant MANIFEST_PATH_PGSUBTRANS => MANIFEST_TARGET_PGDATA . '/' . DB_PATH_PGSUBTRANS;
|
|
|
|
push @EXPORT, qw(MANIFEST_PATH_PGSUBTRANS);
|
2016-08-25 17:25:46 +02:00
|
|
|
use constant MANIFEST_PATH_PGTBLSPC => MANIFEST_TARGET_PGDATA . '/' . DB_PATH_PGTBLSPC;
|
|
|
|
push @EXPORT, qw(MANIFEST_PATH_PGTBLSPC);
|
2016-07-30 00:44:53 +02:00
|
|
|
use constant MANIFEST_PATH_PGXLOG => MANIFEST_TARGET_PGDATA . '/' . DB_PATH_PGXLOG;
|
|
|
|
push @EXPORT, qw(MANIFEST_PATH_PGXLOG);
|
|
|
|
|
2016-05-16 23:59:26 +02:00
|
|
|
use constant MANIFEST_FILE_BACKUPLABEL => MANIFEST_TARGET_PGDATA . '/' . DB_FILE_BACKUPLABEL;
|
|
|
|
push @EXPORT, qw(MANIFEST_FILE_BACKUPLABEL);
|
Exclude directories during backup that are cleaned, recreated, or zeroed by PostgreSQL at startup.
These include (depending on the version where they were introduced): pgsql_tmp, pg_dynshmem, pg_notify, pg_replslot, pg_serial, pg_snapshots, pg_stat_tmp, pg_subtrans. The postgresql.auto.conf.tmp file is now excluded in addition to files that were already excluded: backup_label.old, postmaster.opts, postmaster.pid, recovery.conf, recovery.done.
2016-08-16 15:35:16 +02:00
|
|
|
use constant MANIFEST_FILE_BACKUPLABELOLD => MANIFEST_TARGET_PGDATA . '/' . DB_FILE_BACKUPLABELOLD;
|
|
|
|
push @EXPORT, qw(MANIFEST_FILE_BACKUPLABELOLD);
|
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);
|
Exclude directories during backup that are cleaned, recreated, or zeroed by PostgreSQL at startup.
These include (depending on the version where they were introduced): pgsql_tmp, pg_dynshmem, pg_notify, pg_replslot, pg_serial, pg_snapshots, pg_stat_tmp, pg_subtrans. The postgresql.auto.conf.tmp file is now excluded in addition to files that were already excluded: backup_label.old, postmaster.opts, postmaster.pid, recovery.conf, recovery.done.
2016-08-16 15:35:16 +02:00
|
|
|
use constant MANIFEST_FILE_POSTGRESQLAUTOCONFTMP => MANIFEST_TARGET_PGDATA . '/' . DB_FILE_POSTGRESQLAUTOCONFTMP;
|
|
|
|
push @EXPORT, qw(MANIFEST_FILE_PGCONTROL);
|
|
|
|
use constant MANIFEST_FILE_POSTMASTEROPTS => MANIFEST_TARGET_PGDATA . '/' . DB_FILE_POSTMASTEROPTS;
|
|
|
|
push @EXPORT, qw(MANIFEST_FILE_POSTMASTEROPTS);
|
|
|
|
use constant MANIFEST_FILE_POSTMASTERPID => MANIFEST_TARGET_PGDATA . '/' . DB_FILE_POSTMASTERPID;
|
|
|
|
push @EXPORT, qw(MANIFEST_FILE_POSTMASTERPID);
|
|
|
|
use constant MANIFEST_FILE_RECOVERYCONF => MANIFEST_TARGET_PGDATA . '/' . DB_FILE_RECOVERYCONF;
|
|
|
|
push @EXPORT, qw(MANIFEST_FILE_RECOVERYCONF);
|
|
|
|
use constant MANIFEST_FILE_RECOVERYDONE => MANIFEST_TARGET_PGDATA . '/' . DB_FILE_RECOVERYDONE;
|
|
|
|
push @EXPORT, qw(MANIFEST_FILE_RECOVERYDONE);
|
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);
|
|
|
|
|
2016-09-04 15:19:44 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Expression to determine whether files can be copied from a standby
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant COPY_STANDBY_EXPRESSION => '^(' . MANIFEST_TARGET_PGDATA . '\/' .
|
|
|
|
'(' . DB_PATH_BASE . '|' . DB_PATH_GLOBAL . '|' .
|
|
|
|
DB_PATH_PGCLOG . '|' . DB_PATH_PGMULTIXACT . ')|' .
|
|
|
|
DB_PATH_PGTBLSPC . ')\/';
|
|
|
|
|
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
|
|
|
|
(
|
2016-08-11 23:32:28 +02:00
|
|
|
__PACKAGE__ . '->new', \@_,
|
2015-08-29 20:20:46 +02:00
|
|
|
{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
|
2017-04-10 19:24:45 +02:00
|
|
|
my $self = $class->SUPER::new($strFileName, {bLoad => $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
|
2016-08-11 23:32:28 +02:00
|
|
|
my ($strOperation) = logDebugParam(__PACKAGE__ . '->save');
|
2015-08-29 20:20:46 +02:00
|
|
|
|
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
|
2016-08-11 23:32:28 +02:00
|
|
|
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
|
|
|
####################################################################################################################################
|
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 ||
|
2016-09-04 15:19:44 +02:00
|
|
|
$strSubKey eq MANIFEST_SUBKEY_MODE || $strSubKey eq MANIFEST_SUBKEY_MASTER) &&
|
2016-04-15 04:50:02 +02:00
|
|
|
$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,
|
Exclude directories during backup that are cleaned, recreated, or zeroed by PostgreSQL at startup.
These include (depending on the version where they were introduced): pgsql_tmp, pg_dynshmem, pg_notify, pg_replslot, pg_serial, pg_snapshots, pg_stat_tmp, pg_subtrans. The postgresql.auto.conf.tmp file is now excluded in addition to files that were already excluded: backup_label.old, postmaster.opts, postmaster.pid, recovery.conf, recovery.done.
2016-08-16 15:35:16 +02:00
|
|
|
$strDbVersion,
|
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,
|
2016-11-30 21:36:39 +02:00
|
|
|
$hTablespaceMap,
|
|
|
|
$hDatabaseMap,
|
2016-04-15 04:50:02 +02:00
|
|
|
$strLevel,
|
|
|
|
$bTablespace,
|
|
|
|
$strParentPath,
|
|
|
|
$strFilter
|
2015-08-29 20:20:46 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
2016-08-11 23:32:28 +02:00
|
|
|
__PACKAGE__ . '->build', \@_,
|
2015-08-29 20:20:46 +02:00
|
|
|
{name => 'oFile'},
|
Exclude directories during backup that are cleaned, recreated, or zeroed by PostgreSQL at startup.
These include (depending on the version where they were introduced): pgsql_tmp, pg_dynshmem, pg_notify, pg_replslot, pg_serial, pg_snapshots, pg_stat_tmp, pg_subtrans. The postgresql.auto.conf.tmp file is now excluded in addition to files that were already excluded: backup_label.old, postmaster.opts, postmaster.pid, recovery.conf, recovery.done.
2016-08-16 15:35:16 +02:00
|
|
|
{name => 'strDbVersion'},
|
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'},
|
2016-11-30 21:36:39 +02:00
|
|
|
{name => 'hTablespaceMap', required => false},
|
|
|
|
{name => 'hDatabaseMap', 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
|
2016-11-30 21:36:39 +02:00
|
|
|
if (!$bOnline && !defined($hTablespaceMap))
|
2015-02-01 01:23:37 +02:00
|
|
|
{
|
2016-11-30 21:36:39 +02:00
|
|
|
my $hTablespaceManifest = $oFile->manifest(PATH_DB_ABSOLUTE, $strPath . '/' . DB_PATH_PGTBLSPC);
|
|
|
|
$hTablespaceMap = {};
|
2015-02-01 01:23:37 +02:00
|
|
|
|
2016-11-30 21:36:39 +02:00
|
|
|
foreach my $strOid (sort(CORE::keys(%{$hTablespaceManifest})))
|
2015-02-01 01:23:37 +02:00
|
|
|
{
|
2016-11-30 21:36:39 +02:00
|
|
|
if ($strOid eq '.' or $strOid eq '..')
|
2015-02-01 01:23:37 +02:00
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2016-11-30 21:36:39 +02:00
|
|
|
logDebugMisc($strOperation, "found tablespace ${strOid} in offline mode");
|
2015-02-01 01:23:37 +02:00
|
|
|
|
2016-11-30 21:36:39 +02:00
|
|
|
$hTablespaceMap->{$strOid} = "ts${strOid}";
|
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];
|
|
|
|
|
2016-11-30 21:36:39 +02:00
|
|
|
if (!defined($hTablespaceMap->{$iTablespaceId}))
|
2016-04-15 04:50:02 +02:00
|
|
|
{
|
|
|
|
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,
|
2016-11-30 21:36:39 +02:00
|
|
|
$hTablespaceMap->{$iTablespaceId});
|
2016-04-15 04:50:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2016-11-30 21:36:39 +02:00
|
|
|
my $hManifest = $oFile->manifest(PATH_DB_ABSOLUTE, $strPath);
|
2016-04-15 04:50:02 +02:00
|
|
|
my $strManifestType = MANIFEST_VALUE_LINK;
|
2015-02-01 01:15:08 +02:00
|
|
|
|
|
|
|
# Loop though all paths/files/links in the manifest
|
2016-11-30 21:36:39 +02:00
|
|
|
foreach my $strName (sort(CORE::keys(%{$hManifest})))
|
2015-02-01 01:15:08 +02:00
|
|
|
{
|
2016-04-15 04:50:02 +02:00
|
|
|
my $strFile = $strLevel;
|
|
|
|
|
|
|
|
if ($strName ne '.')
|
|
|
|
{
|
2016-11-30 21:36:39 +02:00
|
|
|
if ($strManifestType eq MANIFEST_VALUE_LINK && $hManifest->{$strName}{type} eq 'l')
|
2016-08-15 23:11:45 +02:00
|
|
|
{
|
2016-08-15 23:23:37 +02:00
|
|
|
confess &log(ERROR, 'link \'' .
|
2016-08-15 23:11:45 +02:00
|
|
|
$self->dbPathGet(
|
|
|
|
$self->get(MANIFEST_SECTION_BACKUP_TARGET, MANIFEST_TARGET_PGDATA, MANIFEST_SUBKEY_PATH), $strLevel) .
|
2016-08-15 23:23:37 +02:00
|
|
|
'\' -> \'' . $self->get(MANIFEST_SECTION_BACKUP_TARGET, $strLevel, MANIFEST_SUBKEY_PATH) .
|
|
|
|
'\' cannot reference another link', ERROR_LINK_DESTINATION);
|
2016-08-15 23:11:45 +02:00
|
|
|
}
|
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
# 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)
|
|
|
|
{
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
Exclude directories during backup that are cleaned, recreated, or zeroed by PostgreSQL at startup.
These include (depending on the version where they were introduced): pgsql_tmp, pg_dynshmem, pg_notify, pg_replslot, pg_serial, pg_snapshots, pg_stat_tmp, pg_subtrans. The postgresql.auto.conf.tmp file is now excluded in addition to files that were already excluded: backup_label.old, postmaster.opts, postmaster.pid, recovery.conf, recovery.done.
2016-08-16 15:35:16 +02:00
|
|
|
# Skip pg_xlog/* when doing an online backup. WAL will be restored from the archive or stored in pg_xlog at the end of the
|
|
|
|
# backup if the archive-copy option is set.
|
|
|
|
next if ($strFile =~ ('^' . MANIFEST_PATH_PGXLOG . '\/') && $bOnline);
|
|
|
|
|
|
|
|
# Skip all directories and files that start with pgsql_tmp. The files are removed when the server is restarted and the
|
|
|
|
# directories are recreated. Since temp files cannnot be created on the replica it makes sense to delete the directories
|
|
|
|
# and let the server recreate them when they are needed.
|
|
|
|
next if $strName =~ ('(^|\/)' . DB_FILE_PREFIX_TMP);
|
|
|
|
|
|
|
|
# Skip temporary statistics in pg_stat_tmp even when stats_temp_directory is set because PGSS_TEXT_FILE is always created
|
|
|
|
# there.
|
|
|
|
next if $strFile =~ ('^' . MANIFEST_PATH_PGSTATTMP . '\/') && $strDbVersion >= PG_VERSION_84;
|
|
|
|
|
2016-09-04 15:13:13 +02:00
|
|
|
# Skip pg_replslot/* since these files are generally not useful after a restore
|
|
|
|
next if $strFile =~ ('^' . MANIFEST_PATH_PGREPLSLOT . '\/') && $strDbVersion >= PG_VERSION_94;
|
|
|
|
|
Exclude directories during backup that are cleaned, recreated, or zeroed by PostgreSQL at startup.
These include (depending on the version where they were introduced): pgsql_tmp, pg_dynshmem, pg_notify, pg_replslot, pg_serial, pg_snapshots, pg_stat_tmp, pg_subtrans. The postgresql.auto.conf.tmp file is now excluded in addition to files that were already excluded: backup_label.old, postmaster.opts, postmaster.pid, recovery.conf, recovery.done.
2016-08-16 15:35:16 +02:00
|
|
|
# Skip pg_subtrans/* since these files are reset
|
|
|
|
next if $strFile =~ ('^' . MANIFEST_PATH_PGSUBTRANS . '\/');
|
|
|
|
|
|
|
|
# Skip ignored files
|
|
|
|
if ($strFile eq MANIFEST_FILE_POSTGRESQLAUTOCONFTMP || # postgresql.auto.conf.tmp - temp file for safe writes
|
|
|
|
$strFile eq MANIFEST_FILE_BACKUPLABELOLD || # backup_label.old - old backup labels are not useful
|
|
|
|
$strFile eq MANIFEST_FILE_POSTMASTEROPTS || # postmaster.opts - not useful for backup
|
|
|
|
$strFile eq MANIFEST_FILE_POSTMASTERPID || # postmaster.pid - to avoid confusing postgres after restore
|
|
|
|
$strFile eq MANIFEST_FILE_RECOVERYCONF || # recovery.conf - doesn't make sense to backup this file
|
|
|
|
$strFile eq MANIFEST_FILE_RECOVERYDONE) # recovery.done - doesn't make sense to backup this file
|
2015-02-01 01:15:08 +02:00
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2016-11-30 21:36:39 +02:00
|
|
|
my $cType = $hManifest->{$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
|
2016-11-30 21:36:39 +02:00
|
|
|
if ($hManifest->{$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-11-30 21:36:39 +02:00
|
|
|
if (index($hManifest->{$strName}{link_destination}, "${strPath}/") == 0 ||
|
|
|
|
(index($hManifest->{$strName}{link_destination}, '/') != 0 &&
|
2016-04-15 04:50:02 +02:00
|
|
|
index(pathAbsolute($strPath . '/' . DB_PATH_PGTBLSPC,
|
2016-11-30 21:36:39 +02:00
|
|
|
$hManifest->{$strName}{link_destination}) . '/', "${strPath}/") == 0))
|
2016-01-15 14:07:00 +02:00
|
|
|
{
|
2016-11-30 21:36:39 +02:00
|
|
|
confess &log(ERROR, 'tablespace symlink ' . $hManifest->{$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-11-30 21:36:39 +02:00
|
|
|
if (defined($hManifest->{$strName}{user}))
|
2016-06-27 03:01:20 +02:00
|
|
|
{
|
2016-11-30 21:36:39 +02:00
|
|
|
$self->set($strSection, $strFile, MANIFEST_SUBKEY_USER, $hManifest->{$strName}{user});
|
2016-06-27 03:01:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$self->boolSet($strSection, $strFile, MANIFEST_SUBKEY_USER, false);
|
|
|
|
}
|
|
|
|
|
2016-11-30 21:36:39 +02:00
|
|
|
if (defined($hManifest->{$strName}{group}))
|
2016-06-27 03:01:20 +02:00
|
|
|
{
|
2016-11-30 21:36:39 +02:00
|
|
|
$self->set($strSection, $strFile, MANIFEST_SUBKEY_GROUP, $hManifest->{$strName}{group});
|
2016-06-27 03:01:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$self->boolSet($strSection, $strFile, MANIFEST_SUBKEY_GROUP, false);
|
|
|
|
}
|
2015-02-01 01:15:08 +02:00
|
|
|
|
|
|
|
# Mode for required file and path type only
|
|
|
|
if ($cType eq 'f' || $cType eq 'd')
|
|
|
|
{
|
2016-11-30 21:36:39 +02:00
|
|
|
$self->set($strSection, $strFile, MANIFEST_SUBKEY_MODE, $hManifest->{$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-11-30 21:36:39 +02:00
|
|
|
$hManifest->{$strName}{modification_time} + 0);
|
|
|
|
$self->set($strSection, $strFile, MANIFEST_SUBKEY_SIZE, $hManifest->{$strName}{size} + 0);
|
2016-09-04 15:19:44 +02:00
|
|
|
$self->boolSet($strSection, $strFile, MANIFEST_SUBKEY_MASTER,
|
|
|
|
($strFile eq MANIFEST_FILE_PGCONTROL || $strFile !~ COPY_STANDBY_EXPRESSION) ? true : false);
|
2015-02-01 01:15:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Link destination required for link type only
|
|
|
|
if ($cType eq 'l')
|
|
|
|
{
|
2016-11-30 21:36:39 +02:00
|
|
|
my $strLinkDestination = $hManifest->{$strName}{link_destination};
|
2016-04-15 04:50:02 +02:00
|
|
|
$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-11-30 21:36:39 +02:00
|
|
|
$self->build($oFile, $strDbVersion, $strLinkDestination, undef, $bOnline, $hTablespaceMap, $hDatabaseMap,
|
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.
|
2016-11-30 21:36:39 +02:00
|
|
|
foreach my $strDbName (sort(keys(%{$hDatabaseMap})))
|
2016-05-11 15:21:39 +02:00
|
|
|
{
|
|
|
|
$self->numericSet(MANIFEST_SECTION_DB, $strDbName, MANIFEST_KEY_DB_ID,
|
2016-11-30 21:36:39 +02:00
|
|
|
$hDatabaseMap->{$strDbName}{&MANIFEST_KEY_DB_ID});
|
2016-05-11 15:21:39 +02:00
|
|
|
$self->numericSet(MANIFEST_SECTION_DB, $strDbName, MANIFEST_KEY_DB_LAST_SYSTEM_ID,
|
2016-11-30 21:36:39 +02:00
|
|
|
$hDatabaseMap->{$strDbName}{&MANIFEST_KEY_DB_LAST_SYSTEM_ID});
|
2016-05-11 15:21:39 +02:00
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2016-09-04 15:19:44 +02:00
|
|
|
# Copy repo size from the previous manifest
|
2016-04-15 04:50:02 +02:00
|
|
|
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
|
|
|
}
|
2016-09-04 15:19:44 +02:00
|
|
|
|
|
|
|
# Copy master flag from the previous manifest (if it exists)
|
|
|
|
if ($oLastManifest->test(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_MASTER))
|
|
|
|
{
|
|
|
|
$self->set(
|
|
|
|
MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_MASTER,
|
|
|
|
$oLastManifest->get(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_MASTER));
|
|
|
|
}
|
2016-12-13 01:54:07 +02:00
|
|
|
|
|
|
|
# Copy checksum page from the previous manifest (if it exists)
|
|
|
|
my $bChecksumPage = $oLastManifest->get(
|
|
|
|
MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_CHECKSUM_PAGE, false);
|
|
|
|
|
|
|
|
if (defined($bChecksumPage))
|
|
|
|
{
|
|
|
|
$self->boolSet(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_CHECKSUM_PAGE, $bChecksumPage);
|
|
|
|
|
|
|
|
if (!$bChecksumPage &&
|
|
|
|
$oLastManifest->test(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_CHECKSUM_PAGE_ERROR))
|
|
|
|
{
|
|
|
|
$self->set(
|
|
|
|
MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_CHECKSUM_PAGE_ERROR,
|
|
|
|
$oLastManifest->get(MANIFEST_SECTION_TARGET_FILE, $strName, MANIFEST_SUBKEY_CHECKSUM_PAGE_ERROR));
|
|
|
|
}
|
|
|
|
}
|
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-08-29 20:20:46 +02:00
|
|
|
|
2016-06-27 03:01:20 +02:00
|
|
|
# Build default sections
|
|
|
|
$self->buildDefault();
|
|
|
|
}
|
2016-04-15 04:50:02 +02:00
|
|
|
|
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
|
2016-08-11 23:32:28 +02:00
|
|
|
my ($strOperation) = logDebugParam(__PACKAGE__ . '->linkCheck');
|
2016-04-15 04:50:02 +02:00
|
|
|
|
|
|
|
# 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);
|
|
|
|
|
2016-11-07 16:37:16 +02:00
|
|
|
if (index(
|
|
|
|
pathAbsolute($strBasePath, $strChildPath) . '/', pathAbsolute($strBasePath, $strParentPath) . '/') == 0)
|
2016-04-15 04:50:02 +02:00
|
|
|
{
|
|
|
|
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,
|
2016-09-04 15:19:44 +02:00
|
|
|
$strChecksum,
|
|
|
|
$bMaster,
|
2016-05-14 16:39:56 +02:00
|
|
|
) =
|
|
|
|
logDebugParam
|
|
|
|
(
|
|
|
|
__PACKAGE__ . '->fileAdd', \@_,
|
|
|
|
{name => 'strManifestFile'},
|
|
|
|
{name => 'lModificationTime'},
|
|
|
|
{name => 'lSize'},
|
2016-09-04 15:19:44 +02:00
|
|
|
{name => 'lChecksum'},
|
|
|
|
{name => 'bMaster'},
|
2016-05-14 16:39:56 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
# Set manifest values
|
2016-06-27 03:01:20 +02:00
|
|
|
if (!$self->test(MANIFEST_SECTION_TARGET_FILE . ':default', MANIFEST_SUBKEY_USER) ||
|
|
|
|
!$self->test(MANIFEST_SECTION_TARGET_FILE . ':default', MANIFEST_SUBKEY_USER, undef,
|
|
|
|
$self->get(MANIFEST_SECTION_TARGET_PATH, MANIFEST_TARGET_PGDATA, MANIFEST_SUBKEY_USER)))
|
|
|
|
{
|
|
|
|
$self->set(MANIFEST_SECTION_TARGET_FILE, $strManifestFile, MANIFEST_SUBKEY_USER,
|
|
|
|
$self->get(MANIFEST_SECTION_TARGET_PATH, MANIFEST_TARGET_PGDATA, MANIFEST_SUBKEY_USER));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$self->test(MANIFEST_SECTION_TARGET_FILE . ':default', MANIFEST_SUBKEY_GROUP) ||
|
|
|
|
!$self->test(MANIFEST_SECTION_TARGET_FILE . ':default', MANIFEST_SUBKEY_GROUP, undef,
|
|
|
|
$self->get(MANIFEST_SECTION_TARGET_PATH, MANIFEST_TARGET_PGDATA, MANIFEST_SUBKEY_GROUP)))
|
|
|
|
{
|
|
|
|
$self->set(MANIFEST_SECTION_TARGET_FILE, $strManifestFile, MANIFEST_SUBKEY_GROUP,
|
|
|
|
$self->get(MANIFEST_SECTION_TARGET_PATH, MANIFEST_TARGET_PGDATA, MANIFEST_SUBKEY_GROUP));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$self->test(MANIFEST_SECTION_TARGET_FILE . ':default', MANIFEST_SUBKEY_MODE) ||
|
|
|
|
!$self->test(MANIFEST_SECTION_TARGET_FILE . ':default', MANIFEST_SUBKEY_MODE, undef, '0600'))
|
|
|
|
{
|
|
|
|
$self->set(MANIFEST_SECTION_TARGET_FILE, $strManifestFile, MANIFEST_SUBKEY_MODE, '0600');
|
|
|
|
}
|
|
|
|
|
2016-05-14 16:39:56 +02:00
|
|
|
$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);
|
2016-09-04 15:19:44 +02:00
|
|
|
$self->boolSet(MANIFEST_SECTION_TARGET_FILE, $strManifestFile, MANIFEST_SUBKEY_MASTER, $bMaster);
|
2016-05-14 16:39:56 +02:00
|
|
|
}
|
|
|
|
|
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
|
2016-08-11 23:32:28 +02:00
|
|
|
my ($strOperation) = logDebugParam(__PACKAGE__ . '->buildDefault');
|
2016-04-15 04:50:02 +02:00
|
|
|
|
|
|
|
# Set defaults for subkeys that tend to repeat
|
|
|
|
foreach my $strSection (&MANIFEST_SECTION_TARGET_FILE, &MANIFEST_SECTION_TARGET_PATH, &MANIFEST_SECTION_TARGET_LINK)
|
|
|
|
{
|
2016-09-04 15:19:44 +02:00
|
|
|
foreach my $strSubKey (&MANIFEST_SUBKEY_USER, &MANIFEST_SUBKEY_GROUP, &MANIFEST_SUBKEY_MODE, &MANIFEST_SUBKEY_MASTER)
|
2016-04-15 04:50:02 +02:00
|
|
|
{
|
2016-06-27 03:01:20 +02:00
|
|
|
# Links don't have a mode so skip
|
|
|
|
next if ($strSection eq MANIFEST_SECTION_TARGET_LINK && $strSubKey eq &MANIFEST_SUBKEY_MODE);
|
|
|
|
|
2016-09-04 15:19:44 +02:00
|
|
|
# Only files have the master subkey
|
|
|
|
next if ($strSection ne MANIFEST_SECTION_TARGET_FILE && $strSubKey eq &MANIFEST_SUBKEY_MASTER);
|
|
|
|
|
2016-04-15 04:50:02 +02:00
|
|
|
my %oDefault;
|
|
|
|
my $iSectionTotal = 0;
|
|
|
|
|
|
|
|
foreach my $strFile ($self->keys($strSection))
|
|
|
|
{
|
2016-09-04 15:19:44 +02:00
|
|
|
# Don't count false values when subkey in (MANIFEST_SUBKEY_USER, MANIFEST_SUBKEY_GROUP)
|
|
|
|
next if (($strSubKey eq MANIFEST_SUBKEY_USER || $strSubKey eq MANIFEST_SUBKEY_GROUP) &&
|
|
|
|
$self->boolTest($strSection, $strFile, $strSubKey, false));
|
2016-06-27 03:01:20 +02:00
|
|
|
|
2016-09-04 15:19:44 +02:00
|
|
|
my $strValue = $self->get($strSection, $strFile, $strSubKey);
|
|
|
|
|
|
|
|
if (defined($oDefault{$strValue}))
|
|
|
|
{
|
|
|
|
$oDefault{$strValue}++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$oDefault{$strValue} = 1;
|
2016-04-15 04:50:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$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)
|
|
|
|
{
|
2016-09-04 15:19:44 +02:00
|
|
|
if ($strSubKey eq MANIFEST_SUBKEY_MASTER)
|
|
|
|
{
|
|
|
|
$self->boolSet("${strSection}:default", $strSubKey, undef, $strMaxValue);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$self->set("${strSection}:default", $strSubKey, undef, $strMaxValue);
|
|
|
|
}
|
2016-04-15 04:50:02 +02:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-09-06 15:35:02 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# validate
|
|
|
|
#
|
|
|
|
# Checks for any mising values or inconsistencies in the manifest.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub validate
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Assign function parameters, defaults, and log debug info
|
|
|
|
my ($strOperation) = logDebugParam(__PACKAGE__ . 'validate');
|
|
|
|
|
|
|
|
# Make sure that all files have size and checksum (when size > 0). Since these values are removed before the backup file copy
|
|
|
|
# starts this ensures that all files had results stored in the manifest during the file copy.
|
|
|
|
foreach my $strFile ($self->keys(MANIFEST_SECTION_TARGET_FILE))
|
|
|
|
{
|
|
|
|
# Ensure size is set
|
|
|
|
if (!$self->test(MANIFEST_SECTION_TARGET_FILE, $strFile, MANIFEST_SUBKEY_SIZE))
|
|
|
|
{
|
|
|
|
confess &log(ASSERT, "manifest subvalue 'size' not set for file '${strFile}'");
|
|
|
|
}
|
|
|
|
|
|
|
|
# If size > 0 then checksum must also be set
|
|
|
|
if ($self->numericGet(MANIFEST_SECTION_TARGET_FILE, $strFile, MANIFEST_SUBKEY_SIZE) > 0 &&
|
|
|
|
!$self->test(MANIFEST_SECTION_TARGET_FILE, $strFile, MANIFEST_SUBKEY_CHECKSUM))
|
|
|
|
{
|
|
|
|
confess &log(ASSERT, "manifest subvalue 'checksum' not set for file '${strFile}'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Return from function and log return values if any
|
|
|
|
return logDebugReturn($strOperation);
|
|
|
|
}
|
|
|
|
|
2016-12-13 01:54:07 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# isChecksumPage
|
|
|
|
#
|
|
|
|
# Can this file have page checksums in PG >= 9.3?
|
|
|
|
####################################################################################################################################
|
|
|
|
sub isChecksumPage
|
|
|
|
{
|
|
|
|
my $strFile = shift;
|
|
|
|
|
2017-03-02 20:50:29 +02:00
|
|
|
if (($strFile =~ ('^' . MANIFEST_TARGET_PGDATA . '\/' . DB_PATH_BASE . '|^' . MANIFEST_TARGET_PGTBLSPC . '\/') &&
|
2016-12-13 01:54:07 +02:00
|
|
|
$strFile !~ ('(' . DB_FILE_PGFILENODEMAP . '|' . DB_FILE_PGINTERNALINIT . '|' . DB_FILE_PGVERSION . ')$')) ||
|
|
|
|
($strFile =~ ('^' . MANIFEST_TARGET_PGDATA . '\/' . DB_PATH_GLOBAL) &&
|
|
|
|
$strFile !~ ('(' . DB_FILE_PGFILENODEMAP . '|' . DB_FILE_PGINTERNALINIT . '|' . DB_FILE_PGVERSION . '|' .
|
2017-03-02 20:50:29 +02:00
|
|
|
DB_FILE_PGCONTROL . ')$')))
|
2016-12-13 01:54:07 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
push @EXPORT, qw(isChecksumPage);
|
|
|
|
|
2015-01-07 17:59:43 +02:00
|
|
|
1;
|