2014-12-16 00:20:42 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# CONFIG MODULE
|
|
|
|
####################################################################################################################################
|
|
|
|
package BackRest::Config;
|
|
|
|
|
|
|
|
use strict;
|
2015-03-03 07:57:20 +02:00
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
2014-12-16 00:20:42 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
use Cwd qw(abs_path);
|
|
|
|
use Exporter qw(import);
|
2015-07-02 16:05:13 +02:00
|
|
|
use File::Basename qw(dirname basename);
|
2015-06-14 00:25:49 +02:00
|
|
|
use Getopt::Long qw(GetOptions);
|
2014-12-16 00:20:42 +02:00
|
|
|
|
|
|
|
use lib dirname($0) . '/../lib';
|
2015-01-26 00:27:46 +02:00
|
|
|
use BackRest::Exception;
|
2015-06-14 00:25:49 +02:00
|
|
|
use BackRest::Ini;
|
2015-08-05 14:43:41 +02:00
|
|
|
use BackRest::Protocol::Common;
|
|
|
|
use BackRest::Protocol::RemoteMaster;
|
2014-12-16 00:20:42 +02:00
|
|
|
use BackRest::Utility;
|
2014-12-19 00:05:06 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Export functions
|
|
|
|
####################################################################################################################################
|
2015-06-18 22:55:09 +02:00
|
|
|
our @EXPORT = qw(configLoad optionGet optionTest optionRuleGet optionRequired optionDefault commandGet commandTest
|
|
|
|
commandSet commandWrite optionRemoteType optionRemoteTypeTest protocolGet optionRemoteTest
|
2015-06-17 17:26:07 +02:00
|
|
|
protocolDestroy);
|
2015-04-01 21:58:33 +02:00
|
|
|
|
2015-07-02 16:05:13 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# BackRest executable name used for help messages and default
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant BACKREST_EXE => basename($0);
|
|
|
|
push @EXPORT, qw(BACKREST_EXE);
|
|
|
|
|
2015-04-01 21:58:33 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# DB/BACKUP Constants
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant
|
|
|
|
{
|
|
|
|
DB => 'db',
|
|
|
|
BACKUP => 'backup',
|
|
|
|
NONE => 'none'
|
|
|
|
};
|
|
|
|
|
|
|
|
push @EXPORT, qw(DB BACKUP NONE);
|
2014-12-16 00:20:42 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
####################################################################################################################################
|
2015-06-18 22:55:09 +02:00
|
|
|
# Command constants - basic commands that are allowed in backrest
|
2015-03-12 18:15:19 +02:00
|
|
|
####################################################################################################################################
|
2015-06-22 19:11:07 +02:00
|
|
|
use constant CMD_ARCHIVE_GET => 'archive-get';
|
2015-06-18 22:55:09 +02:00
|
|
|
push @EXPORT, qw(CMD_ARCHIVE_GET);
|
2015-06-22 19:11:07 +02:00
|
|
|
use constant CMD_ARCHIVE_PUSH => 'archive-push';
|
2015-06-18 22:55:09 +02:00
|
|
|
push @EXPORT, qw(CMD_ARCHIVE_PUSH);
|
2015-06-22 19:11:07 +02:00
|
|
|
use constant CMD_BACKUP => 'backup';
|
2015-06-18 22:55:09 +02:00
|
|
|
push @EXPORT, qw(CMD_BACKUP);
|
2015-06-22 19:11:07 +02:00
|
|
|
use constant CMD_INFO => 'info';
|
2015-06-18 22:55:09 +02:00
|
|
|
push @EXPORT, qw(CMD_INFO);
|
2015-06-22 19:11:07 +02:00
|
|
|
use constant CMD_REMOTE => 'remote';
|
2015-06-18 22:55:09 +02:00
|
|
|
push @EXPORT, qw(CMD_REMOTE);
|
2015-06-22 19:11:07 +02:00
|
|
|
use constant CMD_RESTORE => 'restore';
|
2015-06-18 22:55:09 +02:00
|
|
|
push @EXPORT, qw(CMD_RESTORE);
|
2015-06-22 19:11:07 +02:00
|
|
|
use constant CMD_EXPIRE => 'expire';
|
2015-06-18 22:55:09 +02:00
|
|
|
push @EXPORT, qw(CMD_EXPIRE);
|
2014-12-16 00:20:42 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# BACKUP Type Constants
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant
|
|
|
|
{
|
|
|
|
BACKUP_TYPE_FULL => 'full',
|
|
|
|
BACKUP_TYPE_DIFF => 'diff',
|
|
|
|
BACKUP_TYPE_INCR => 'incr'
|
|
|
|
};
|
2014-12-16 00:20:42 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
push @EXPORT, qw(BACKUP_TYPE_FULL BACKUP_TYPE_DIFF BACKUP_TYPE_INCR);
|
2015-01-31 20:48:09 +02:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# INFO Output Constants
|
|
|
|
####################################################################################################################################
|
2015-06-17 17:26:07 +02:00
|
|
|
use constant INFO_OUTPUT_TEXT => 'text';
|
|
|
|
push @EXPORT, qw(INFO_OUTPUT_TEXT);
|
|
|
|
use constant INFO_OUTPUT_JSON => 'json';
|
|
|
|
push @EXPORT, qw(INFO_OUTPUT_JSON);
|
2015-06-14 00:25:49 +02:00
|
|
|
|
2015-04-19 23:29:52 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# SOURCE Constants
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant
|
|
|
|
{
|
|
|
|
SOURCE_CONFIG => 'config',
|
|
|
|
SOURCE_PARAM => 'param',
|
|
|
|
SOURCE_DEFAULT => 'default'
|
|
|
|
};
|
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# RECOVERY Type Constants
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant
|
|
|
|
{
|
|
|
|
RECOVERY_TYPE_NAME => 'name',
|
|
|
|
RECOVERY_TYPE_TIME => 'time',
|
|
|
|
RECOVERY_TYPE_XID => 'xid',
|
|
|
|
RECOVERY_TYPE_PRESERVE => 'preserve',
|
|
|
|
RECOVERY_TYPE_NONE => 'none',
|
|
|
|
RECOVERY_TYPE_DEFAULT => 'default'
|
|
|
|
};
|
2015-03-03 05:58:32 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
push @EXPORT, qw(RECOVERY_TYPE_NAME RECOVERY_TYPE_TIME RECOVERY_TYPE_XID RECOVERY_TYPE_PRESERVE RECOVERY_TYPE_NONE
|
|
|
|
RECOVERY_TYPE_DEFAULT);
|
2014-12-16 00:20:42 +02:00
|
|
|
|
2014-12-19 00:05:06 +02:00
|
|
|
####################################################################################################################################
|
2015-03-12 18:15:19 +02:00
|
|
|
# Configuration section constants
|
2014-12-19 00:05:06 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
use constant
|
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
CONFIG_GLOBAL => 'global',
|
|
|
|
|
|
|
|
CONFIG_SECTION_ARCHIVE => 'archive',
|
|
|
|
CONFIG_SECTION_BACKUP => 'backup',
|
|
|
|
CONFIG_SECTION_COMMAND => 'command',
|
|
|
|
CONFIG_SECTION_GENERAL => 'general',
|
|
|
|
CONFIG_SECTION_LOG => 'log',
|
|
|
|
CONFIG_SECTION_RESTORE_RECOVERY_SETTING => 'restore:recovery-setting',
|
|
|
|
CONFIG_SECTION_RESTORE_TABLESPACE_MAP => 'restore:tablespace-map',
|
2015-03-24 17:43:37 +02:00
|
|
|
CONFIG_SECTION_EXPIRE => 'expire',
|
2015-03-12 18:15:19 +02:00
|
|
|
CONFIG_SECTION_STANZA => 'stanza'
|
2014-12-16 19:41:54 +02:00
|
|
|
};
|
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
push @EXPORT, qw(CONFIG_GLOBAL
|
|
|
|
|
|
|
|
CONFIG_SECTION_ARCHIVE CONFIG_SECTION_BACKUP CONFIG_SECTION_COMMAND
|
|
|
|
CONFIG_SECTION_GENERAL CONFIG_SECTION_LOG CONFIG_SECTION_RESTORE_RECOVERY_SETTING
|
2015-03-24 17:43:37 +02:00
|
|
|
CONFIG_SECTION_EXPIRE CONFIG_SECTION_STANZA CONFIG_SECTION_RESTORE_TABLESPACE_MAP);
|
2015-03-12 18:15:19 +02:00
|
|
|
|
2014-12-16 19:41:54 +02:00
|
|
|
####################################################################################################################################
|
2015-03-12 18:15:19 +02:00
|
|
|
# Option constants
|
2014-12-16 00:20:42 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
use constant
|
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
# Command-line-only options
|
|
|
|
OPTION_CONFIG => 'config',
|
|
|
|
OPTION_DELTA => 'delta',
|
|
|
|
OPTION_FORCE => 'force',
|
|
|
|
OPTION_NO_START_STOP => 'no-start-stop',
|
|
|
|
OPTION_SET => 'set',
|
|
|
|
OPTION_STANZA => 'stanza',
|
|
|
|
OPTION_TARGET => 'target',
|
|
|
|
OPTION_TARGET_EXCLUSIVE => 'target-exclusive',
|
|
|
|
OPTION_TARGET_RESUME => 'target-resume',
|
|
|
|
OPTION_TARGET_TIMELINE => 'target-timeline',
|
|
|
|
OPTION_TYPE => 'type',
|
2015-06-14 00:25:49 +02:00
|
|
|
OPTION_OUTPUT => 'output',
|
2015-03-12 18:15:19 +02:00
|
|
|
|
|
|
|
# Command-line/conf file options
|
|
|
|
# GENERAL Section
|
|
|
|
OPTION_BUFFER_SIZE => 'buffer-size',
|
|
|
|
OPTION_COMPRESS => 'compress',
|
|
|
|
OPTION_COMPRESS_LEVEL => 'compress-level',
|
|
|
|
OPTION_COMPRESS_LEVEL_NETWORK => 'compress-level-network',
|
2015-07-23 19:11:38 +02:00
|
|
|
OPTION_NEUTRAL_UMASK => 'neutral-umask',
|
2015-03-12 18:15:19 +02:00
|
|
|
OPTION_REPO_PATH => 'repo-path',
|
|
|
|
OPTION_REPO_REMOTE_PATH => 'repo-remote-path',
|
|
|
|
OPTION_THREAD_MAX => 'thread-max',
|
|
|
|
OPTION_THREAD_TIMEOUT => 'thread-timeout',
|
|
|
|
|
|
|
|
# ARCHIVE Section
|
|
|
|
OPTION_ARCHIVE_MAX_MB => 'archive-max-mb',
|
|
|
|
OPTION_ARCHIVE_ASYNC => 'archive-async',
|
|
|
|
|
|
|
|
# BACKUP Section
|
2015-03-25 00:50:14 +02:00
|
|
|
OPTION_BACKUP_ARCHIVE_CHECK => 'archive-check',
|
|
|
|
OPTION_BACKUP_ARCHIVE_COPY => 'archive-copy',
|
2015-03-12 18:15:19 +02:00
|
|
|
OPTION_BACKUP_HOST => 'backup-host',
|
|
|
|
OPTION_BACKUP_USER => 'backup-user',
|
2015-05-07 02:24:34 +02:00
|
|
|
OPTION_HARDLINK => 'hardlink',
|
|
|
|
OPTION_MANIFEST_SAVE_THRESHOLD => 'manifest-save-threshold',
|
2015-05-07 18:29:30 +02:00
|
|
|
OPTION_RESUME => 'resume',
|
2015-08-08 23:11:20 +02:00
|
|
|
OPTION_STOP_AUTO => 'stop-auto',
|
2015-03-12 18:15:19 +02:00
|
|
|
OPTION_START_FAST => 'start-fast',
|
|
|
|
|
|
|
|
# COMMAND Section
|
2015-03-25 00:50:14 +02:00
|
|
|
OPTION_COMMAND_REMOTE => 'cmd-remote',
|
2015-03-12 18:15:19 +02:00
|
|
|
|
|
|
|
# LOG Section
|
2015-03-25 00:50:14 +02:00
|
|
|
OPTION_LOG_LEVEL_CONSOLE => 'log-level-console',
|
|
|
|
OPTION_LOG_LEVEL_FILE => 'log-level-file',
|
2015-03-12 18:15:19 +02:00
|
|
|
|
|
|
|
# EXPIRE Section
|
|
|
|
OPTION_RETENTION_ARCHIVE => 'retention-archive',
|
|
|
|
OPTION_RETENTION_ARCHIVE_TYPE => 'retention-archive-type',
|
|
|
|
OPTION_RETENTION_DIFF => 'retention-' . BACKUP_TYPE_DIFF,
|
|
|
|
OPTION_RETENTION_FULL => 'retention-' . BACKUP_TYPE_FULL,
|
|
|
|
|
|
|
|
# RESTORE Section
|
2015-05-09 00:34:27 +02:00
|
|
|
OPTION_TABLESPACE => 'tablespace',
|
2015-03-12 18:15:19 +02:00
|
|
|
OPTION_RESTORE_TABLESPACE_MAP => 'tablespace-map',
|
|
|
|
OPTION_RESTORE_RECOVERY_SETTING => 'recovery-setting',
|
|
|
|
|
|
|
|
# STANZA Section
|
|
|
|
OPTION_DB_HOST => 'db-host',
|
|
|
|
OPTION_DB_PATH => 'db-path',
|
2015-08-05 18:32:12 +02:00
|
|
|
OPTION_DB_PORT => 'db-port',
|
|
|
|
OPTION_DB_SOCKET_PATH => 'db-socket-path',
|
2015-03-12 18:15:19 +02:00
|
|
|
OPTION_DB_USER => 'db-user',
|
|
|
|
|
|
|
|
# Command-line-only help/version options
|
|
|
|
OPTION_HELP => 'help',
|
|
|
|
OPTION_VERSION => 'version',
|
|
|
|
|
|
|
|
# Command-line-only test options
|
|
|
|
OPTION_TEST => 'test',
|
|
|
|
OPTION_TEST_DELAY => 'test-delay',
|
|
|
|
OPTION_TEST_NO_FORK => 'no-fork'
|
2014-12-16 00:20:42 +02:00
|
|
|
};
|
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
push @EXPORT, qw(OPTION_CONFIG OPTION_DELTA OPTION_FORCE OPTION_NO_START_STOP OPTION_SET OPTION_STANZA OPTION_TARGET
|
|
|
|
OPTION_TARGET_EXCLUSIVE OPTION_TARGET_RESUME OPTION_TARGET_TIMELINE OPTION_TYPE
|
|
|
|
|
2015-03-23 22:01:15 +02:00
|
|
|
OPTION_DB_HOST OPTION_BACKUP_HOST OPTION_ARCHIVE_MAX_MB OPTION_BACKUP_ARCHIVE_CHECK OPTION_BACKUP_ARCHIVE_COPY
|
2015-03-16 20:45:53 +02:00
|
|
|
OPTION_ARCHIVE_ASYNC
|
2015-03-12 18:15:19 +02:00
|
|
|
OPTION_BUFFER_SIZE OPTION_COMPRESS OPTION_COMPRESS_LEVEL OPTION_COMPRESS_LEVEL_NETWORK OPTION_HARDLINK
|
2015-07-23 19:11:38 +02:00
|
|
|
OPTION_MANIFEST_SAVE_THRESHOLD OPTION_RESUME OPTION_PATH_ARCHIVE OPTION_REPO_PATH OPTION_NEUTRAL_UMASK
|
|
|
|
OPTION_REPO_REMOTE_PATH OPTION_DB_PATH OPTION_OUTPUT OPTION_LOG_LEVEL_CONSOLE OPTION_LOG_LEVEL_FILE
|
2015-03-12 18:15:19 +02:00
|
|
|
OPTION_RESTORE_RECOVERY_SETTING OPTION_RETENTION_ARCHIVE OPTION_RETENTION_ARCHIVE_TYPE OPTION_RETENTION_FULL
|
2015-08-08 23:11:20 +02:00
|
|
|
OPTION_RETENTION_DIFF OPTION_START_FAST OPTION_STOP_AUTO OPTION_THREAD_MAX OPTION_THREAD_TIMEOUT
|
2015-08-05 18:32:12 +02:00
|
|
|
OPTION_DB_USER OPTION_BACKUP_USER OPTION_COMMAND_REMOTE
|
|
|
|
OPTION_TABLESPACE OPTION_RESTORE_TABLESPACE_MAP OPTION_DB_PORT OPTION_DB_SOCKET_PATH
|
2015-03-12 18:15:19 +02:00
|
|
|
|
|
|
|
OPTION_TEST OPTION_TEST_DELAY OPTION_TEST_NO_FORK);
|
|
|
|
|
2015-03-03 05:58:32 +02:00
|
|
|
####################################################################################################################################
|
2015-03-12 18:15:19 +02:00
|
|
|
# Option Defaults
|
2015-03-03 05:58:32 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
use constant
|
|
|
|
{
|
2015-05-07 02:24:34 +02:00
|
|
|
OPTION_DEFAULT_BUFFER_SIZE => 4194304,
|
|
|
|
OPTION_DEFAULT_BUFFER_SIZE_MIN => 16384,
|
|
|
|
OPTION_DEFAULT_BUFFER_SIZE_MAX => 8388608,
|
|
|
|
|
|
|
|
OPTION_DEFAULT_COMPRESS => true,
|
|
|
|
OPTION_DEFAULT_COMPRESS_LEVEL => 6,
|
|
|
|
OPTION_DEFAULT_COMPRESS_LEVEL_MIN => 0,
|
|
|
|
OPTION_DEFAULT_COMPRESS_LEVEL_MAX => 9,
|
|
|
|
OPTION_DEFAULT_COMPRESS_LEVEL_NETWORK => 3,
|
|
|
|
OPTION_DEFAULT_COMPRESS_LEVEL_NETWORK_MIN => 0,
|
|
|
|
OPTION_DEFAULT_COMPRESS_LEVEL_NETWORK_MAX => 9,
|
|
|
|
|
2015-07-02 16:05:13 +02:00
|
|
|
OPTION_DEFAULT_CONFIG => '/etc/' . BACKREST_EXE . '.conf',
|
2015-05-07 02:24:34 +02:00
|
|
|
OPTION_DEFAULT_LOG_LEVEL_CONSOLE => lc(WARN),
|
|
|
|
OPTION_DEFAULT_LOG_LEVEL_FILE => lc(INFO),
|
|
|
|
OPTION_DEFAULT_THREAD_MAX => 1,
|
|
|
|
|
|
|
|
OPTION_DEFAULT_ARCHIVE_ASYNC => false,
|
|
|
|
|
2015-08-05 18:32:12 +02:00
|
|
|
OPTION_DEFAULT_DB_PORT => 5432,
|
|
|
|
OPTION_DEFAULT_DB_USER => 'postgres',
|
|
|
|
|
2015-06-17 17:26:07 +02:00
|
|
|
OPTION_DEFAULT_COMMAND_REMOTE => abs_path($0),
|
2015-05-07 02:24:34 +02:00
|
|
|
|
|
|
|
OPTION_DEFAULT_BACKUP_ARCHIVE_CHECK => true,
|
|
|
|
OPTION_DEFAULT_BACKUP_ARCHIVE_COPY => false,
|
|
|
|
OPTION_DEFAULT_BACKUP_FORCE => false,
|
|
|
|
OPTION_DEFAULT_BACKUP_HARDLINK => false,
|
|
|
|
OPTION_DEFAULT_BACKUP_NO_START_STOP => false,
|
|
|
|
OPTION_DEFAULT_BACKUP_MANIFEST_SAVE_THRESHOLD => 1073741824,
|
2015-05-07 18:29:30 +02:00
|
|
|
OPTION_DEFAULT_BACKUP_RESUME => true,
|
2015-08-08 23:11:20 +02:00
|
|
|
OPTION_DEFAULT_BACKUP_STOP_AUTO => false,
|
2015-05-07 02:24:34 +02:00
|
|
|
OPTION_DEFAULT_BACKUP_START_FAST => false,
|
|
|
|
OPTION_DEFAULT_BACKUP_TYPE => BACKUP_TYPE_INCR,
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
OPTION_DEFAULT_INFO_OUTPUT => INFO_OUTPUT_TEXT,
|
|
|
|
|
2015-07-23 19:11:38 +02:00
|
|
|
OPTION_DEFAULT_NEUTRAL_UMASK => true,
|
2015-05-07 02:24:34 +02:00
|
|
|
OPTION_DEFAULT_REPO_PATH => '/var/lib/backup',
|
|
|
|
|
|
|
|
OPTION_DEFAULT_RESTORE_DELTA => false,
|
|
|
|
OPTION_DEFAULT_RESTORE_FORCE => false,
|
|
|
|
OPTION_DEFAULT_RESTORE_SET => 'latest',
|
2015-05-09 00:34:27 +02:00
|
|
|
OPTION_DEFAULT_RESTORE_TABLESPACE => true,
|
2015-05-07 02:24:34 +02:00
|
|
|
OPTION_DEFAULT_RESTORE_TYPE => RECOVERY_TYPE_DEFAULT,
|
|
|
|
OPTION_DEFAULT_RESTORE_TARGET_EXCLUSIVE => false,
|
|
|
|
OPTION_DEFAULT_RESTORE_TARGET_RESUME => false,
|
|
|
|
|
|
|
|
OPTION_DEFAULT_RETENTION_ARCHIVE_TYPE => BACKUP_TYPE_FULL,
|
|
|
|
OPTION_DEFAULT_RETENTION_MIN => 1,
|
|
|
|
OPTION_DEFAULT_RETENTION_MAX => 999999999,
|
|
|
|
|
|
|
|
OPTION_DEFAULT_TEST => false,
|
|
|
|
OPTION_DEFAULT_TEST_DELAY => 5,
|
|
|
|
OPTION_DEFAULT_TEST_NO_FORK => false
|
2015-03-12 18:15:19 +02:00
|
|
|
};
|
2015-03-03 05:58:32 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
push @EXPORT, qw(OPTION_DEFAULT_BUFFER_SIZE OPTION_DEFAULT_COMPRESS OPTION_DEFAULT_CONFIG OPTION_LEVEL_CONSOLE OPTION_LEVEL_FILE
|
|
|
|
OPTION_DEFAULT_THREAD_MAX
|
2015-03-03 05:58:32 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
OPTION_DEFAULT_COMPRESS OPTION_DEFAULT_COMPRESS_LEVEL OPTION_DEFAULT_COMPRESS_LEVEL_NETWORK
|
|
|
|
OPTION_DEFAULT_COMMAND_REMOTE
|
2015-03-03 05:58:32 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
OPTION_DEFAULT_BACKUP_FORCE OPTION_DEFAULT_BACKUP_NO_START_STOP OPTION_DEFAULT_BACKUP_TYPE
|
|
|
|
|
|
|
|
OPTION_DEFAULT_RESTORE_DELTA OPTION_DEFAULT_RESTORE_FORCE OPTION_DEFAULT_RESTORE_SET OPTION_DEFAULT_RESTORE_TYPE
|
|
|
|
OPTION_DEFAULT_RESTORE_TARGET_EXCLUSIVE OPTION_DEFAULT_RESTORE_TARGET_RESUME
|
|
|
|
|
2015-08-05 18:32:12 +02:00
|
|
|
OPTION_DEFAULT_TEST OPTION_DEFAULT_TEST_DELAY OPTION_DEFAULT_TEST_NO_FORK OPTION_DEFAULT_DB_PORT
|
|
|
|
OPTION_DEFAULT_DB_USER);
|
2015-03-03 05:58:32 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
2015-03-12 18:15:19 +02:00
|
|
|
# Option Rules
|
2015-03-03 05:58:32 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
use constant
|
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
OPTION_RULE_ALLOW_LIST => 'allow-list',
|
|
|
|
OPTION_RULE_ALLOW_RANGE => 'allow-range',
|
|
|
|
OPTION_RULE_DEFAULT => 'default',
|
|
|
|
OPTION_RULE_DEPEND => 'depend',
|
|
|
|
OPTION_RULE_DEPEND_OPTION => 'depend-option',
|
|
|
|
OPTION_RULE_DEPEND_LIST => 'depend-list',
|
|
|
|
OPTION_RULE_DEPEND_VALUE => 'depend-value',
|
2015-05-29 02:52:42 +02:00
|
|
|
OPTION_RULE_HINT => 'hint',
|
2015-03-12 18:15:19 +02:00
|
|
|
OPTION_RULE_NEGATE => 'negate',
|
2015-06-18 22:55:09 +02:00
|
|
|
OPTION_RULE_COMMAND => 'command',
|
2015-03-12 18:15:19 +02:00
|
|
|
OPTION_RULE_REQUIRED => 'required',
|
|
|
|
OPTION_RULE_SECTION => 'section',
|
|
|
|
OPTION_RULE_SECTION_INHERIT => 'section-inherit',
|
|
|
|
OPTION_RULE_TYPE => 'type'
|
2015-03-03 05:58:32 +02:00
|
|
|
};
|
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
push @EXPORT, qw(OPTION_RULE_ALLOW_LIST OPTION_RULE_ALLOW_RANGE OPTION_RULE_DEFAULT OPTION_RULE_DEPEND OPTION_RULE_DEPEND_OPTION
|
2015-06-18 22:55:09 +02:00
|
|
|
OPTION_RULE_DEPEND_LIST OPTION_RULE_DEPEND_VALUE OPTION_RULE_NEGATE OPTION_RULE_COMMAND OPTION_RULE_REQUIRED
|
2015-03-12 18:15:19 +02:00
|
|
|
OPTION_RULE_SECTION OPTION_RULE_SECTION_INHERIT OPTION_RULE_TYPE);
|
|
|
|
|
2014-12-16 00:20:42 +02:00
|
|
|
####################################################################################################################################
|
2015-03-12 18:15:19 +02:00
|
|
|
# Option Types
|
2014-12-16 00:20:42 +02:00
|
|
|
####################################################################################################################################
|
2015-03-12 18:15:19 +02:00
|
|
|
use constant
|
|
|
|
{
|
|
|
|
OPTION_TYPE_BOOLEAN => 'boolean',
|
|
|
|
OPTION_TYPE_FLOAT => 'float',
|
|
|
|
OPTION_TYPE_HASH => 'hash',
|
|
|
|
OPTION_TYPE_INTEGER => 'integer',
|
|
|
|
OPTION_TYPE_STRING => 'string'
|
|
|
|
};
|
|
|
|
|
|
|
|
push @EXPORT, qw(OPTION_TYPE_BOOLEAN OPTION_TYPE_FLOAT OPTION_TYPE_INTEGER OPTION_TYPE_STRING);
|
2014-12-16 00:20:42 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
2015-03-12 18:15:19 +02:00
|
|
|
# Option Rule Hash
|
2014-12-16 00:20:42 +02:00
|
|
|
####################################################################################################################################
|
2015-03-12 18:15:19 +02:00
|
|
|
my %oOptionRule =
|
|
|
|
(
|
|
|
|
# Command-line-only option rule
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
&OPTION_CONFIG =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_STRING,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_CONFIG,
|
|
|
|
&OPTION_RULE_NEGATE => true
|
|
|
|
},
|
2014-12-16 00:20:42 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_DELTA =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_BOOLEAN,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_RESTORE =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_RESTORE_DELTA,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2014-12-16 00:20:42 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_FORCE =>
|
2014-12-24 01:52:38 +02:00
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_BOOLEAN,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-01-28 07:28:21 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_RESTORE =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_RESTORE_FORCE,
|
|
|
|
},
|
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_BACKUP =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_BACKUP_FORCE,
|
|
|
|
&OPTION_RULE_DEPEND =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_DEPEND_OPTION => OPTION_NO_START_STOP,
|
|
|
|
&OPTION_RULE_DEPEND_VALUE => true
|
|
|
|
}
|
|
|
|
}
|
2015-01-28 07:28:21 +02:00
|
|
|
}
|
2015-03-12 18:15:19 +02:00
|
|
|
},
|
2014-12-24 01:52:38 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_NO_START_STOP =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_BOOLEAN,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2014-12-24 01:52:38 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_BACKUP =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_BACKUP_NO_START_STOP
|
|
|
|
}
|
2014-12-24 01:52:38 +02:00
|
|
|
}
|
2015-03-12 18:15:19 +02:00
|
|
|
},
|
2014-12-24 01:52:38 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_SET =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_STRING,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_RESTORE =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-04-19 23:29:52 +02:00
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_RESTORE_SET,
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2014-12-16 00:20:42 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_STANZA =>
|
|
|
|
{
|
2015-06-14 00:25:49 +02:00
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_STRING,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-06-14 00:25:49 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_ARCHIVE_GET =>
|
2015-06-14 00:25:49 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_REQUIRED => true
|
|
|
|
},
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_ARCHIVE_PUSH =>
|
2015-06-14 00:25:49 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_REQUIRED => true
|
|
|
|
},
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_BACKUP =>
|
2015-06-14 00:25:49 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_REQUIRED => true
|
|
|
|
},
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_EXPIRE =>
|
2015-06-14 00:25:49 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_REQUIRED => true
|
|
|
|
},
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_REMOTE =>
|
2015-06-18 21:39:30 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_REQUIRED => false
|
|
|
|
},
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_RESTORE =>
|
2015-06-14 00:25:49 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_REQUIRED => true
|
|
|
|
}
|
|
|
|
}
|
2015-03-12 18:15:19 +02:00
|
|
|
},
|
2014-12-16 00:20:42 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_TARGET =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_STRING,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_RESTORE =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_DEPEND =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_DEPEND_OPTION => OPTION_TYPE,
|
|
|
|
&OPTION_RULE_DEPEND_LIST =>
|
|
|
|
{
|
|
|
|
&RECOVERY_TYPE_NAME => true,
|
|
|
|
&RECOVERY_TYPE_TIME => true,
|
|
|
|
&RECOVERY_TYPE_XID => true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2015-01-23 03:11:33 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_TARGET_EXCLUSIVE =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_BOOLEAN,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_RESTORE =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_RESTORE_TARGET_EXCLUSIVE,
|
|
|
|
&OPTION_RULE_DEPEND =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_DEPEND_OPTION => OPTION_TYPE,
|
|
|
|
&OPTION_RULE_DEPEND_LIST =>
|
|
|
|
{
|
|
|
|
&RECOVERY_TYPE_TIME => true,
|
|
|
|
&RECOVERY_TYPE_XID => true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2015-01-23 03:11:33 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_TARGET_RESUME =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_BOOLEAN,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_RESTORE =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_RESTORE_TARGET_RESUME,
|
|
|
|
&OPTION_RULE_DEPEND =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_DEPEND_OPTION => OPTION_TYPE,
|
|
|
|
&OPTION_RULE_DEPEND_LIST =>
|
|
|
|
{
|
|
|
|
&RECOVERY_TYPE_NAME => true,
|
|
|
|
&RECOVERY_TYPE_TIME => true,
|
|
|
|
&RECOVERY_TYPE_XID => true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2015-01-23 03:11:33 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_TARGET_TIMELINE =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_STRING,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_RESTORE =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_REQUIRED => false,
|
|
|
|
&OPTION_RULE_DEPEND =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_DEPEND_OPTION => OPTION_TYPE,
|
|
|
|
&OPTION_RULE_DEPEND_LIST =>
|
|
|
|
{
|
|
|
|
&RECOVERY_TYPE_DEFAULT => true,
|
|
|
|
&RECOVERY_TYPE_NAME => true,
|
|
|
|
&RECOVERY_TYPE_TIME => true,
|
2015-03-16 20:45:53 +02:00
|
|
|
&RECOVERY_TYPE_XID => true
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2014-12-16 00:20:42 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_TYPE =>
|
2014-12-16 00:20:42 +02:00
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_STRING,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_BACKUP =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_BACKUP_TYPE,
|
|
|
|
&OPTION_RULE_ALLOW_LIST =>
|
|
|
|
{
|
|
|
|
&BACKUP_TYPE_FULL => true,
|
|
|
|
&BACKUP_TYPE_DIFF => true,
|
|
|
|
&BACKUP_TYPE_INCR => true,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_RESTORE =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_RESTORE_TYPE,
|
|
|
|
&OPTION_RULE_ALLOW_LIST =>
|
|
|
|
{
|
|
|
|
&RECOVERY_TYPE_NAME => true,
|
|
|
|
&RECOVERY_TYPE_TIME => true,
|
|
|
|
&RECOVERY_TYPE_XID => true,
|
|
|
|
&RECOVERY_TYPE_PRESERVE => true,
|
|
|
|
&RECOVERY_TYPE_NONE => true,
|
|
|
|
&RECOVERY_TYPE_DEFAULT => true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2014-12-16 00:20:42 +02:00
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
&OPTION_OUTPUT =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_STRING,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-06-14 00:25:49 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_INFO =>
|
2015-06-14 00:25:49 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_INFO_OUTPUT,
|
|
|
|
&OPTION_RULE_ALLOW_LIST =>
|
|
|
|
{
|
|
|
|
&INFO_OUTPUT_TEXT => true,
|
|
|
|
&INFO_OUTPUT_JSON => true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
# Command-line/conf option rules
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
&OPTION_COMMAND_REMOTE =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_STRING,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_COMMAND_REMOTE,
|
|
|
|
&OPTION_RULE_SECTION => CONFIG_SECTION_COMMAND,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_ARCHIVE_GET => true,
|
|
|
|
&CMD_ARCHIVE_PUSH => true,
|
|
|
|
&CMD_BACKUP => true,
|
|
|
|
&CMD_INFO => true,
|
|
|
|
&CMD_RESTORE => true
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
},
|
2014-12-16 00:20:42 +02:00
|
|
|
|
2015-08-05 18:32:12 +02:00
|
|
|
&OPTION_ARCHIVE_ASYNC =>
|
2014-12-16 00:20:42 +02:00
|
|
|
{
|
2015-08-05 18:32:12 +02:00
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_BOOLEAN,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_ARCHIVE_ASYNC,
|
|
|
|
&OPTION_RULE_SECTION => CONFIG_SECTION_ARCHIVE,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-08-05 18:32:12 +02:00
|
|
|
&CMD_ARCHIVE_PUSH => true
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-08-05 18:32:12 +02:00
|
|
|
&OPTION_DB_HOST =>
|
2014-12-16 00:20:42 +02:00
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_STRING,
|
|
|
|
&OPTION_RULE_REQUIRED => false,
|
2015-08-05 18:32:12 +02:00
|
|
|
&OPTION_RULE_SECTION => CONFIG_SECTION_STANZA,
|
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-08-05 18:32:12 +02:00
|
|
|
&CMD_BACKUP => true
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
},
|
2014-12-16 00:20:42 +02:00
|
|
|
|
2015-08-05 18:32:12 +02:00
|
|
|
&OPTION_DB_PORT =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-08-05 18:32:12 +02:00
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_INTEGER,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_DB_PORT,
|
|
|
|
&OPTION_RULE_SECTION => CONFIG_SECTION_STANZA,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2014-12-16 00:20:42 +02:00
|
|
|
{
|
2015-08-05 18:32:12 +02:00
|
|
|
&CMD_BACKUP => true,
|
|
|
|
&CMD_REMOTE => true
|
2014-12-16 00:20:42 +02:00
|
|
|
}
|
2015-03-12 18:15:19 +02:00
|
|
|
},
|
2014-12-16 00:20:42 +02:00
|
|
|
|
2015-08-05 18:32:12 +02:00
|
|
|
&OPTION_DB_SOCKET_PATH =>
|
2014-12-16 00:20:42 +02:00
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_STRING,
|
|
|
|
&OPTION_RULE_REQUIRED => false,
|
|
|
|
&OPTION_RULE_SECTION => CONFIG_SECTION_STANZA,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2014-12-16 00:20:42 +02:00
|
|
|
{
|
2015-08-05 18:32:12 +02:00
|
|
|
&CMD_BACKUP => true,
|
|
|
|
&CMD_REMOTE => true
|
2014-12-16 00:20:42 +02:00
|
|
|
}
|
2015-03-12 18:15:19 +02:00
|
|
|
},
|
2014-12-16 00:20:42 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_DB_USER =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_STRING,
|
2015-08-05 18:32:12 +02:00
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_DB_USER,
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_RULE_SECTION => CONFIG_SECTION_STANZA,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_BACKUP => true
|
2015-03-12 18:15:19 +02:00
|
|
|
},
|
|
|
|
&OPTION_RULE_REQUIRED => false,
|
|
|
|
&OPTION_RULE_DEPEND =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_DEPEND_OPTION => OPTION_DB_HOST
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
&OPTION_BACKUP_HOST =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_STRING,
|
|
|
|
&OPTION_RULE_REQUIRED => false,
|
|
|
|
&OPTION_RULE_SECTION => CONFIG_SECTION_BACKUP,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_ARCHIVE_GET => true,
|
|
|
|
&CMD_ARCHIVE_PUSH => true,
|
|
|
|
&CMD_INFO => true,
|
|
|
|
&CMD_RESTORE => true
|
2015-03-12 18:15:19 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&OPTION_BACKUP_USER =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_STRING,
|
|
|
|
&OPTION_RULE_SECTION => CONFIG_SECTION_BACKUP,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_ARCHIVE_GET => true,
|
|
|
|
&CMD_ARCHIVE_PUSH => true,
|
|
|
|
&CMD_INFO => true,
|
|
|
|
&CMD_RESTORE => true
|
2015-03-12 18:15:19 +02:00
|
|
|
},
|
|
|
|
&OPTION_RULE_REQUIRED => false,
|
|
|
|
&OPTION_RULE_DEPEND =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_DEPEND_OPTION => OPTION_BACKUP_HOST
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-07-23 19:11:38 +02:00
|
|
|
&OPTION_NEUTRAL_UMASK =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_BOOLEAN,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_NEUTRAL_UMASK,
|
|
|
|
&OPTION_RULE_SECTION => CONFIG_SECTION_GENERAL
|
|
|
|
},
|
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_REPO_PATH =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_STRING,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_REPO_PATH,
|
|
|
|
&OPTION_RULE_SECTION => CONFIG_SECTION_GENERAL,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_ARCHIVE_GET => true,
|
|
|
|
&CMD_ARCHIVE_PUSH => true,
|
|
|
|
&CMD_BACKUP => true,
|
|
|
|
&CMD_INFO => true,
|
|
|
|
&CMD_RESTORE => true,
|
|
|
|
&CMD_EXPIRE => true
|
2015-03-12 18:15:19 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&OPTION_REPO_REMOTE_PATH =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_STRING,
|
|
|
|
&OPTION_RULE_REQUIRED => false,
|
|
|
|
&OPTION_RULE_SECTION => CONFIG_SECTION_GENERAL,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_ARCHIVE_GET => true,
|
|
|
|
&CMD_ARCHIVE_PUSH => true,
|
|
|
|
&CMD_INFO => true,
|
|
|
|
&CMD_REMOTE => true,
|
|
|
|
&CMD_RESTORE => true
|
2015-03-12 18:15:19 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&OPTION_DB_PATH =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_STRING,
|
|
|
|
&OPTION_RULE_SECTION => CONFIG_SECTION_STANZA,
|
2015-05-29 02:52:42 +02:00
|
|
|
&OPTION_RULE_HINT => "Does this stanza exist?",
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_ARCHIVE_GET =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_REQUIRED => false
|
2015-03-16 20:01:01 +02:00
|
|
|
},
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_ARCHIVE_PUSH =>
|
2015-03-16 20:01:01 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_REQUIRED => false
|
|
|
|
},
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_BACKUP => true
|
2015-03-12 18:15:19 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&OPTION_BUFFER_SIZE =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_INTEGER,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_BUFFER_SIZE,
|
|
|
|
&OPTION_RULE_SECTION => true,
|
|
|
|
&OPTION_RULE_SECTION_INHERIT => CONFIG_SECTION_GENERAL,
|
|
|
|
&OPTION_RULE_ALLOW_RANGE => [OPTION_DEFAULT_BUFFER_SIZE_MIN, OPTION_DEFAULT_BUFFER_SIZE_MAX]
|
|
|
|
},
|
|
|
|
|
|
|
|
&OPTION_ARCHIVE_MAX_MB =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_INTEGER,
|
|
|
|
&OPTION_RULE_REQUIRED => false,
|
|
|
|
&OPTION_RULE_SECTION => CONFIG_SECTION_ARCHIVE,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_ARCHIVE_PUSH => true
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-03-23 22:01:15 +02:00
|
|
|
&OPTION_BACKUP_ARCHIVE_CHECK =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_BOOLEAN,
|
2015-03-23 22:01:15 +02:00
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_BACKUP_ARCHIVE_CHECK,
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_RULE_SECTION => true,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_BACKUP =>
|
2015-06-14 00:25:49 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_DEPEND =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_DEPEND_OPTION => OPTION_NO_START_STOP,
|
|
|
|
&OPTION_RULE_DEPEND_VALUE => false
|
|
|
|
}
|
|
|
|
}
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-03-23 22:01:15 +02:00
|
|
|
&OPTION_BACKUP_ARCHIVE_COPY =>
|
2015-03-16 20:45:53 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_BOOLEAN,
|
2015-03-23 22:01:15 +02:00
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_BACKUP_ARCHIVE_COPY,
|
2015-03-16 20:45:53 +02:00
|
|
|
&OPTION_RULE_SECTION => true,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-16 20:45:53 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_BACKUP =>
|
2015-03-16 20:45:53 +02:00
|
|
|
{
|
|
|
|
&OPTION_RULE_DEPEND =>
|
|
|
|
{
|
2015-03-23 22:01:15 +02:00
|
|
|
&OPTION_RULE_DEPEND_OPTION => OPTION_BACKUP_ARCHIVE_CHECK,
|
2015-03-16 20:45:53 +02:00
|
|
|
&OPTION_RULE_DEPEND_VALUE => true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_COMPRESS =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_BOOLEAN,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_COMPRESS,
|
|
|
|
&OPTION_RULE_SECTION => true,
|
|
|
|
&OPTION_RULE_SECTION_INHERIT => CONFIG_SECTION_GENERAL,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_ARCHIVE_GET => true,
|
|
|
|
&CMD_ARCHIVE_PUSH => true,
|
|
|
|
&CMD_BACKUP => true,
|
|
|
|
&CMD_RESTORE => true
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
&OPTION_COMPRESS_LEVEL =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_INTEGER,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_COMPRESS_LEVEL,
|
|
|
|
&OPTION_RULE_SECTION => true,
|
|
|
|
&OPTION_RULE_SECTION_INHERIT => CONFIG_SECTION_GENERAL,
|
|
|
|
&OPTION_RULE_ALLOW_RANGE => [OPTION_DEFAULT_COMPRESS_LEVEL_MIN, OPTION_DEFAULT_COMPRESS_LEVEL_MAX],
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_ARCHIVE_GET => true,
|
|
|
|
&CMD_ARCHIVE_PUSH => true,
|
|
|
|
&CMD_BACKUP => true,
|
|
|
|
&CMD_INFO => true,
|
|
|
|
&CMD_REMOTE => true,
|
|
|
|
&CMD_RESTORE => true
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
&OPTION_COMPRESS_LEVEL_NETWORK =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_INTEGER,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_COMPRESS_LEVEL_NETWORK,
|
|
|
|
&OPTION_RULE_SECTION => true,
|
|
|
|
&OPTION_RULE_SECTION_INHERIT => CONFIG_SECTION_GENERAL,
|
|
|
|
&OPTION_RULE_ALLOW_RANGE => [OPTION_DEFAULT_COMPRESS_LEVEL_NETWORK_MIN, OPTION_DEFAULT_COMPRESS_LEVEL_NETWORK_MAX],
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_ARCHIVE_GET => true,
|
|
|
|
&CMD_ARCHIVE_PUSH => true,
|
|
|
|
&CMD_BACKUP => true,
|
|
|
|
&CMD_INFO => true,
|
|
|
|
&CMD_REMOTE => true,
|
|
|
|
&CMD_RESTORE => true
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
&OPTION_HARDLINK =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_BOOLEAN,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_BACKUP_HARDLINK,
|
|
|
|
&OPTION_RULE_SECTION => true,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_BACKUP => true
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
&OPTION_LOG_LEVEL_CONSOLE =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_STRING,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_LOG_LEVEL_CONSOLE,
|
|
|
|
&OPTION_RULE_SECTION => CONFIG_SECTION_LOG,
|
|
|
|
&OPTION_RULE_ALLOW_LIST =>
|
|
|
|
{
|
|
|
|
lc(OFF) => true,
|
|
|
|
lc(ERROR) => true,
|
|
|
|
lc(WARN) => true,
|
|
|
|
lc(INFO) => true,
|
|
|
|
lc(DEBUG) => true,
|
|
|
|
lc(TRACE) => true
|
2015-06-18 21:39:30 +02:00
|
|
|
},
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-06-18 21:39:30 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_ARCHIVE_GET => true,
|
|
|
|
&CMD_ARCHIVE_PUSH => true,
|
|
|
|
&CMD_BACKUP => true,
|
|
|
|
&CMD_EXPIRE => true,
|
|
|
|
&CMD_INFO => true,
|
|
|
|
&CMD_RESTORE => true
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
&OPTION_LOG_LEVEL_FILE =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_STRING,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_LOG_LEVEL_FILE,
|
|
|
|
&OPTION_RULE_SECTION => CONFIG_SECTION_LOG,
|
|
|
|
&OPTION_RULE_ALLOW_LIST =>
|
|
|
|
{
|
|
|
|
lc(OFF) => true,
|
|
|
|
lc(ERROR) => true,
|
|
|
|
lc(WARN) => true,
|
|
|
|
lc(INFO) => true,
|
|
|
|
lc(DEBUG) => true,
|
|
|
|
lc(TRACE) => true
|
2015-06-18 21:39:30 +02:00
|
|
|
},
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-06-18 21:39:30 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_ARCHIVE_GET => true,
|
|
|
|
&CMD_ARCHIVE_PUSH => true,
|
|
|
|
&CMD_BACKUP => true,
|
|
|
|
&CMD_EXPIRE => true,
|
|
|
|
&CMD_INFO => true,
|
|
|
|
&CMD_RESTORE => true
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-05-09 00:34:27 +02:00
|
|
|
&OPTION_TABLESPACE =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_BOOLEAN,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_RESTORE_TABLESPACE,
|
|
|
|
&OPTION_RULE_SECTION => true,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-05-09 00:34:27 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_RESTORE => true
|
2015-05-09 00:34:27 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_RESTORE_TABLESPACE_MAP =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_HASH,
|
|
|
|
&OPTION_RULE_REQUIRED => false,
|
|
|
|
&OPTION_RULE_SECTION => CONFIG_SECTION_RESTORE_TABLESPACE_MAP,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_RESTORE => 1
|
2015-03-12 18:15:19 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
&OPTION_RESTORE_RECOVERY_SETTING =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_HASH,
|
|
|
|
&OPTION_RULE_REQUIRED => false,
|
|
|
|
&OPTION_RULE_SECTION => CONFIG_SECTION_RESTORE_RECOVERY_SETTING,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_RESTORE => 1
|
2015-03-12 18:15:19 +02:00
|
|
|
},
|
|
|
|
&OPTION_RULE_DEPEND =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_DEPEND_OPTION => OPTION_TYPE,
|
|
|
|
&OPTION_RULE_DEPEND_LIST =>
|
|
|
|
{
|
|
|
|
&RECOVERY_TYPE_DEFAULT => true,
|
|
|
|
&RECOVERY_TYPE_NAME => true,
|
|
|
|
&RECOVERY_TYPE_TIME => true,
|
|
|
|
&RECOVERY_TYPE_XID => true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
&OPTION_RETENTION_ARCHIVE =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_INTEGER,
|
|
|
|
&OPTION_RULE_REQUIRED => false,
|
2015-03-24 17:43:37 +02:00
|
|
|
&OPTION_RULE_SECTION => CONFIG_SECTION_EXPIRE,
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_RULE_ALLOW_RANGE => [OPTION_DEFAULT_RETENTION_MIN, OPTION_DEFAULT_RETENTION_MAX],
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_BACKUP => true,
|
|
|
|
&CMD_EXPIRE => true
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
&OPTION_RETENTION_ARCHIVE_TYPE =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_STRING,
|
|
|
|
&OPTION_RULE_REQUIRED => true,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_RETENTION_ARCHIVE_TYPE,
|
2015-03-24 17:43:37 +02:00
|
|
|
&OPTION_RULE_SECTION => CONFIG_SECTION_EXPIRE,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_BACKUP => true,
|
|
|
|
&CMD_EXPIRE => true
|
2015-03-12 18:15:19 +02:00
|
|
|
},
|
|
|
|
&OPTION_RULE_ALLOW_LIST =>
|
|
|
|
{
|
|
|
|
&BACKUP_TYPE_FULL => 1,
|
|
|
|
&BACKUP_TYPE_DIFF => 1,
|
|
|
|
&BACKUP_TYPE_INCR => 1
|
|
|
|
},
|
|
|
|
&OPTION_RULE_DEPEND =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_DEPEND_OPTION => OPTION_RETENTION_ARCHIVE
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
&OPTION_RETENTION_DIFF =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_INTEGER,
|
|
|
|
&OPTION_RULE_REQUIRED => false,
|
2015-03-24 17:43:37 +02:00
|
|
|
&OPTION_RULE_SECTION => CONFIG_SECTION_EXPIRE,
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_RULE_ALLOW_RANGE => [OPTION_DEFAULT_RETENTION_MIN, OPTION_DEFAULT_RETENTION_MAX],
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_BACKUP => true,
|
|
|
|
&CMD_EXPIRE => true
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
&OPTION_RETENTION_FULL =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_INTEGER,
|
|
|
|
&OPTION_RULE_REQUIRED => false,
|
2015-03-24 17:43:37 +02:00
|
|
|
&OPTION_RULE_SECTION => CONFIG_SECTION_EXPIRE,
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_RULE_ALLOW_RANGE => [OPTION_DEFAULT_RETENTION_MIN, OPTION_DEFAULT_RETENTION_MAX],
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_BACKUP => true,
|
|
|
|
&CMD_EXPIRE => true
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
2015-05-07 02:24:34 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
&OPTION_MANIFEST_SAVE_THRESHOLD =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_INTEGER,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_BACKUP_MANIFEST_SAVE_THRESHOLD,
|
|
|
|
&OPTION_RULE_SECTION => true,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-05-07 02:24:34 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_BACKUP => true
|
2015-05-07 02:24:34 +02:00
|
|
|
}
|
2015-05-07 18:29:30 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
&OPTION_RESUME =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_BOOLEAN,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_BACKUP_RESUME,
|
|
|
|
&OPTION_RULE_SECTION => true,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-05-07 18:29:30 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_BACKUP => true
|
2015-05-07 18:29:30 +02:00
|
|
|
}
|
2015-03-12 18:15:19 +02:00
|
|
|
},
|
|
|
|
|
2015-08-08 23:11:20 +02:00
|
|
|
&OPTION_STOP_AUTO =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_BOOLEAN,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_BACKUP_STOP_AUTO,
|
|
|
|
&OPTION_RULE_SECTION => true,
|
|
|
|
&OPTION_RULE_COMMAND =>
|
|
|
|
{
|
|
|
|
&CMD_BACKUP => true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_START_FAST =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_BOOLEAN,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_BACKUP_START_FAST,
|
|
|
|
&OPTION_RULE_SECTION => true,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_BACKUP => true
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
&OPTION_THREAD_MAX =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_INTEGER,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_THREAD_MAX,
|
|
|
|
&OPTION_RULE_SECTION => true,
|
|
|
|
&OPTION_RULE_SECTION_INHERIT => CONFIG_SECTION_GENERAL,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_BACKUP => true,
|
|
|
|
&CMD_RESTORE => true
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
&OPTION_THREAD_TIMEOUT =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_INTEGER,
|
|
|
|
&OPTION_RULE_REQUIRED => false,
|
|
|
|
&OPTION_RULE_SECTION => true,
|
|
|
|
&OPTION_RULE_SECTION_INHERIT => CONFIG_SECTION_GENERAL,
|
2015-06-18 22:55:09 +02:00
|
|
|
&OPTION_RULE_COMMAND =>
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
&CMD_BACKUP => true,
|
|
|
|
&CMD_RESTORE => true
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
# Command-line-only test option rules
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
&OPTION_TEST =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_BOOLEAN,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_TEST
|
|
|
|
},
|
2014-12-16 00:20:42 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_TEST_DELAY =>
|
2014-12-16 00:20:42 +02:00
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_FLOAT,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_TEST_DELAY,
|
|
|
|
&OPTION_RULE_DEPEND =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_DEPEND_OPTION => OPTION_TEST,
|
|
|
|
&OPTION_RULE_DEPEND_VALUE => true
|
|
|
|
}
|
|
|
|
},
|
2014-12-16 00:20:42 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_TEST_NO_FORK =>
|
|
|
|
{
|
|
|
|
&OPTION_RULE_TYPE => OPTION_TYPE_BOOLEAN,
|
|
|
|
&OPTION_RULE_DEFAULT => OPTION_DEFAULT_TEST_NO_FORK,
|
|
|
|
&OPTION_RULE_DEPEND =>
|
2014-12-16 00:20:42 +02:00
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
&OPTION_RULE_DEPEND_OPTION => OPTION_TEST
|
2014-12-16 00:20:42 +02:00
|
|
|
}
|
|
|
|
}
|
2015-03-12 18:15:19 +02:00
|
|
|
);
|
2014-12-16 00:20:42 +02:00
|
|
|
|
2015-07-02 16:05:13 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Help text - not using Pod::Usage since some elements are dynamic
|
|
|
|
####################################################################################################################################
|
|
|
|
use constant BACKREST_HELP =>
|
|
|
|
"Usage:\n" .
|
|
|
|
" " . BACKREST_EXE . " [options] [command]\n" .
|
|
|
|
"\n" .
|
|
|
|
" Commands:\n" .
|
|
|
|
" archive-get retrieve an archive file from backup\n" .
|
|
|
|
" archive-push push an archive file to backup\n" .
|
|
|
|
" backup backup a cluster\n" .
|
|
|
|
" restore restore a cluster\n" .
|
|
|
|
" expire expire old backups (automatically run after backup)\n" .
|
|
|
|
"\n" .
|
|
|
|
" General Options:\n" .
|
|
|
|
" --stanza stanza (cluster) to operate on\n" .
|
|
|
|
" --config alternate path for configuration file\n" .
|
|
|
|
" (defaults to " . OPTION_DEFAULT_CONFIG . ")\n" .
|
|
|
|
" --version display version and exit\n" .
|
|
|
|
" --help display usage and exit\n" .
|
|
|
|
"\n" .
|
|
|
|
" Backup Options:\n" .
|
|
|
|
" --type type of backup to perform (full, diff, incr)\n" .
|
|
|
|
" --no-start-stop do not call pg_start/stop_backup(). Postmaster should not\n" .
|
|
|
|
" be running.\n" .
|
|
|
|
" --force force backup when --no-start-stop passed and\n" .
|
|
|
|
" postmaster.pid exists. Use with extreme caution as this\n" .
|
|
|
|
" will probably produce an inconsistent backup!\n" .
|
|
|
|
"\n" .
|
|
|
|
" Restore Options:\n" .
|
|
|
|
" --set backup set to restore (defaults to latest set).\n" .
|
|
|
|
" --delta perform a delta restore.\n" .
|
|
|
|
" --force force a restore and overwrite all existing files.\n" .
|
|
|
|
" with --delta forces size/timestamp deltas.\n" .
|
|
|
|
"\n" .
|
|
|
|
" Recovery Options:\n" .
|
|
|
|
" --type type of recovery:\n" .
|
|
|
|
" default - recover to end of archive log stream\n" .
|
|
|
|
" name - restore point target\n" .
|
|
|
|
" time - timestamp target\n" .
|
|
|
|
" xid - transaction id target\n" .
|
|
|
|
" preserve - preserve the existing recovery.conf\n" .
|
|
|
|
" none - no recovery.conf generated\n" .
|
|
|
|
" --target recovery target if type is name, time, or xid.\n" .
|
|
|
|
" --target-exclusive stop just before the recovery target\n" .
|
|
|
|
" (default is inclusive).\n" .
|
|
|
|
" --target-resume do not pause after recovery (default is to pause).\n" .
|
|
|
|
" --target-timeline recover into specified timeline\n" .
|
|
|
|
" (default is current timeline).\n" .
|
|
|
|
"\n" .
|
|
|
|
" Output Options:\n" .
|
|
|
|
" --log-level-console console log level (defaults to warn):\n" .
|
|
|
|
" off - No logging at all (not recommended)\n" .
|
|
|
|
" error - Log only errors\n" .
|
|
|
|
" warn - Log warnings and errors\n" .
|
|
|
|
" info - Log info, warnings, and errors\n" .
|
|
|
|
" debug - Log debug, info, warnings, and errors\n" .
|
|
|
|
" trace - Log trace (very verbose debugging), debug,\n" .
|
|
|
|
" info, warnings, and errors\n" .
|
|
|
|
" --log-level-file file log level (defaults to info). Same options as\n" .
|
|
|
|
" --log-level-console.";
|
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# Global variables
|
|
|
|
####################################################################################################################################
|
2015-07-02 16:05:13 +02:00
|
|
|
my %oOption; # Option hash
|
|
|
|
my $strCommand; # Command (backup, archive-get, ...)
|
|
|
|
my $strRemoteType; # Remote type (DB, BACKUP, NONE)
|
|
|
|
my $oProtocol; # Global remote object that is created on first request (NOT THREADSAFE!)
|
2014-12-16 00:20:42 +02:00
|
|
|
|
2015-01-31 22:37:59 +02:00
|
|
|
####################################################################################################################################
|
2015-03-12 18:15:19 +02:00
|
|
|
# configLoad
|
|
|
|
#
|
|
|
|
# Load configuration.
|
2015-01-31 22:37:59 +02:00
|
|
|
####################################################################################################################################
|
2015-03-12 18:15:19 +02:00
|
|
|
sub configLoad
|
2015-01-31 22:37:59 +02:00
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
# Clear option in case it was loaded before
|
|
|
|
%oOption = ();
|
|
|
|
|
|
|
|
# Build hash with all valid command-line options
|
|
|
|
my %oOptionAllow;
|
2015-01-31 22:37:59 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
foreach my $strKey (keys(%oOptionRule))
|
2015-01-31 22:37:59 +02:00
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
my $strOption = $strKey;
|
|
|
|
|
|
|
|
if (!defined($oOptionRule{$strKey}{&OPTION_RULE_TYPE}))
|
|
|
|
{
|
|
|
|
confess &log(ASSERT, "Option ${strKey} does not have a defined type", ERROR_ASSERT);
|
|
|
|
}
|
|
|
|
elsif ($oOptionRule{$strKey}{&OPTION_RULE_TYPE} eq OPTION_TYPE_HASH)
|
|
|
|
{
|
|
|
|
$strOption .= '=s@';
|
|
|
|
}
|
|
|
|
elsif ($oOptionRule{$strKey}{&OPTION_RULE_TYPE} ne OPTION_TYPE_BOOLEAN)
|
|
|
|
{
|
|
|
|
$strOption .= '=s';
|
|
|
|
}
|
|
|
|
|
|
|
|
$oOptionAllow{$strOption} = $strOption;
|
|
|
|
|
|
|
|
# Check if the option can be negated
|
2015-04-08 01:21:48 +02:00
|
|
|
if ((defined($oOptionRule{$strKey}{&OPTION_RULE_NEGATE}) &&
|
|
|
|
$oOptionRule{$strKey}{&OPTION_RULE_NEGATE}) ||
|
|
|
|
($oOptionRule{$strKey}{&OPTION_RULE_TYPE} eq OPTION_TYPE_BOOLEAN &&
|
|
|
|
defined($oOptionRule{$strKey}{&OPTION_RULE_SECTION})))
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
|
|
|
$strOption = "no-${strKey}";
|
|
|
|
$oOptionAllow{$strOption} = $strOption;
|
2015-04-08 01:21:48 +02:00
|
|
|
$oOptionRule{$strKey}{&OPTION_RULE_NEGATE} = true;
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
2015-01-31 22:37:59 +02:00
|
|
|
}
|
|
|
|
|
2015-05-26 21:29:42 +02:00
|
|
|
# Add help and version options
|
|
|
|
$oOptionAllow{'help'} = 'help';
|
|
|
|
$oOptionAllow{'version'} = 'version';
|
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
# Get command-line options
|
|
|
|
my %oOptionTest;
|
2015-01-31 22:37:59 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
if (!GetOptions(\%oOptionTest, %oOptionAllow))
|
|
|
|
{
|
2015-07-02 16:05:13 +02:00
|
|
|
syswrite(*STDOUT, "\n" . BACKREST_EXE . ' ' . BACKREST_VERSION . "\n\n");
|
2015-03-12 18:15:19 +02:00
|
|
|
pod2usage(2);
|
|
|
|
};
|
|
|
|
|
|
|
|
# Display version and exit if requested
|
|
|
|
if (defined($oOptionTest{&OPTION_VERSION}) || defined($oOptionTest{&OPTION_HELP}))
|
|
|
|
{
|
2015-07-02 16:05:13 +02:00
|
|
|
syswrite(*STDOUT, BACKREST_EXE . ' ' . BACKREST_VERSION . "\n");
|
2015-03-12 18:15:19 +02:00
|
|
|
|
|
|
|
if (!defined($oOptionTest{&OPTION_HELP}))
|
|
|
|
{
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Display help and exit if requested
|
|
|
|
if (defined($oOptionTest{&OPTION_HELP}))
|
|
|
|
{
|
2015-07-02 16:05:13 +02:00
|
|
|
syswrite(*STDOUT, "\n" . BACKREST_HELP . "\n");
|
2015-03-12 18:15:19 +02:00
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Validate and store options
|
|
|
|
optionValid(\%oOptionTest);
|
|
|
|
|
2015-07-23 19:11:38 +02:00
|
|
|
# Neutralize the umask to make the repository file/path modes more consistent
|
|
|
|
if (optionGet(OPTION_NEUTRAL_UMASK))
|
|
|
|
{
|
|
|
|
umask(0000);
|
|
|
|
}
|
|
|
|
|
2015-03-25 00:50:14 +02:00
|
|
|
# Set repo-remote-path to repo-path if it is not set
|
|
|
|
if (optionTest(OPTION_REPO_PATH) && !optionTest(OPTION_REPO_REMOTE_PATH))
|
|
|
|
{
|
2015-06-18 21:39:30 +02:00
|
|
|
$oOption{&OPTION_REPO_REMOTE_PATH}{source} = $oOption{&OPTION_REPO_PATH}{source};
|
2015-04-19 23:29:52 +02:00
|
|
|
$oOption{&OPTION_REPO_REMOTE_PATH}{value} = optionGet(OPTION_REPO_PATH);
|
2015-03-25 00:50:14 +02:00
|
|
|
}
|
2015-04-01 21:58:33 +02:00
|
|
|
|
|
|
|
# Check if the backup host is remote
|
|
|
|
if (optionTest(OPTION_BACKUP_HOST))
|
|
|
|
{
|
|
|
|
$strRemoteType = BACKUP;
|
|
|
|
}
|
|
|
|
# Else check if db is remote
|
|
|
|
elsif (optionTest(OPTION_DB_HOST))
|
|
|
|
{
|
|
|
|
# Don't allow both sides to be remote
|
|
|
|
if (defined($strRemoteType))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, 'db and backup cannot both be configured as remote', ERROR_CONFIG);
|
|
|
|
}
|
|
|
|
|
|
|
|
$strRemoteType = DB;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strRemoteType = NONE;
|
|
|
|
}
|
2015-01-31 22:37:59 +02:00
|
|
|
}
|
2015-01-31 20:48:09 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
2015-03-12 18:15:19 +02:00
|
|
|
# optionValid
|
2015-01-31 20:48:09 +02:00
|
|
|
#
|
2015-06-18 22:55:09 +02:00
|
|
|
# Make sure the command-line options are valid based on the command.
|
2015-01-31 20:48:09 +02:00
|
|
|
####################################################################################################################################
|
2015-03-12 18:15:19 +02:00
|
|
|
sub optionValid
|
2015-01-31 20:48:09 +02:00
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
my $oOptionTest = shift;
|
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
# Check that the command is present and valid
|
|
|
|
$strCommand = $ARGV[0];
|
2015-03-12 18:15:19 +02:00
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
if (!defined($strCommand))
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
confess &log(ERROR, "command must be specified", ERROR_COMMAND_REQUIRED);
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
if ($strCommand ne CMD_ARCHIVE_GET &&
|
|
|
|
$strCommand ne CMD_ARCHIVE_PUSH &&
|
|
|
|
$strCommand ne CMD_BACKUP &&
|
|
|
|
$strCommand ne CMD_INFO &&
|
|
|
|
$strCommand ne CMD_REMOTE &&
|
|
|
|
$strCommand ne CMD_RESTORE &&
|
|
|
|
$strCommand ne CMD_EXPIRE)
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
confess &log(ERROR, "invalid command ${strCommand}", ERROR_COMMAND_INVALID);
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
2015-01-31 20:48:09 +02:00
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
# Set the command section - because of the various archive commands this is not always the command
|
|
|
|
my $strCommandSection;
|
2015-01-31 20:48:09 +02:00
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
if (commandTest(CMD_ARCHIVE_GET) || commandTest(CMD_ARCHIVE_PUSH))
|
2015-01-31 20:48:09 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
$strCommandSection = CONFIG_SECTION_ARCHIVE;
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
$strCommandSection = $strCommand;
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Hash to store contents of the config file. The file will be loaded one the config dependency is resolved unless all options
|
|
|
|
# are set on the command line or --no-config is specified.
|
|
|
|
my $oConfig;
|
|
|
|
my $bConfigExists = true;
|
|
|
|
|
|
|
|
# Keep track of unresolved dependencies
|
|
|
|
my $bDependUnresolved = true;
|
|
|
|
my %oOptionResolved;
|
|
|
|
|
|
|
|
# Loop through all possible options
|
|
|
|
while ($bDependUnresolved)
|
|
|
|
{
|
|
|
|
# Assume that all dependencies will be resolved in this loop
|
|
|
|
$bDependUnresolved = false;
|
|
|
|
|
|
|
|
foreach my $strOption (sort(keys(%oOptionRule)))
|
2015-01-31 20:48:09 +02:00
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
# Skip the option if it has been resolved in a prior loop
|
|
|
|
if (defined($oOptionResolved{$strOption}))
|
2015-01-31 20:48:09 +02:00
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
next;
|
2015-01-31 20:48:09 +02:00
|
|
|
}
|
2015-01-31 22:37:59 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
# Store the option value since it is used a lot
|
|
|
|
my $strValue = $$oOptionTest{$strOption};
|
2015-03-03 03:36:12 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
# Check to see if an option can be negated. Make sure that it is not set and negated at the same time.
|
|
|
|
my $bNegate = false;
|
2015-03-03 03:36:12 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
if (defined($oOptionRule{$strOption}{&OPTION_RULE_NEGATE}) && $oOptionRule{$strOption}{&OPTION_RULE_NEGATE})
|
|
|
|
{
|
|
|
|
$bNegate = defined($$oOptionTest{'no-' . $strOption});
|
2015-03-03 05:58:32 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
if ($bNegate && defined($strValue))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "option '${strOption}' cannot be both set and negated", ERROR_OPTION_NEGATE);
|
|
|
|
}
|
2015-04-08 00:36:59 +02:00
|
|
|
|
2015-04-08 01:21:48 +02:00
|
|
|
if ($bNegate && $oOptionRule{$strOption}{&OPTION_RULE_TYPE} eq OPTION_TYPE_BOOLEAN)
|
2015-04-08 00:36:59 +02:00
|
|
|
{
|
|
|
|
$strValue = false;
|
|
|
|
}
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
2015-03-03 05:58:32 +02:00
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
# If the command has rules store them for later evaluation
|
|
|
|
my $oCommandRule = optionCommandRule($strOption, $strCommand);
|
2015-04-01 21:58:33 +02:00
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
# Check dependency for the command then for the option
|
2015-04-01 21:58:33 +02:00
|
|
|
my $bDependResolved = true;
|
2015-06-18 22:55:09 +02:00
|
|
|
my $oDepend = defined($oCommandRule) ? $$oCommandRule{&OPTION_RULE_DEPEND} :
|
|
|
|
$oOptionRule{$strOption}{&OPTION_RULE_DEPEND};
|
2015-04-01 21:58:33 +02:00
|
|
|
my $strDependOption;
|
|
|
|
my $strDependValue;
|
|
|
|
my $strDependType;
|
|
|
|
|
|
|
|
if (defined($oDepend))
|
|
|
|
{
|
|
|
|
# Check if the depend option has a value
|
|
|
|
$strDependOption = $$oDepend{&OPTION_RULE_DEPEND_OPTION};
|
2015-04-19 23:29:52 +02:00
|
|
|
$strDependValue = $oOption{$strDependOption}{value};
|
2015-04-01 21:58:33 +02:00
|
|
|
|
|
|
|
# Make sure the depend option has been resolved, otherwise skip this option for now
|
|
|
|
if (!defined($oOptionResolved{$strDependOption}))
|
|
|
|
{
|
|
|
|
$bDependUnresolved = true;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!defined($strDependValue))
|
|
|
|
{
|
|
|
|
$bDependResolved = false;
|
|
|
|
$strDependType = 'source';
|
|
|
|
}
|
|
|
|
|
|
|
|
# If a depend value exists, make sure the option value matches
|
|
|
|
if ($bDependResolved && defined($$oDepend{&OPTION_RULE_DEPEND_VALUE}) &&
|
|
|
|
$$oDepend{&OPTION_RULE_DEPEND_VALUE} ne $strDependValue)
|
|
|
|
{
|
|
|
|
$bDependResolved = false;
|
|
|
|
$strDependType = 'value';
|
|
|
|
}
|
|
|
|
|
|
|
|
# If a depend list exists, make sure the value is in the list
|
|
|
|
if ($bDependResolved && defined($$oDepend{&OPTION_RULE_DEPEND_LIST}) &&
|
|
|
|
!defined($$oDepend{&OPTION_RULE_DEPEND_LIST}{$strDependValue}))
|
|
|
|
{
|
|
|
|
$bDependResolved = false;
|
|
|
|
$strDependType = 'list';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-02 16:05:13 +02:00
|
|
|
# If the option value is undefined and not negated, see if it can be loaded from the config file
|
2015-03-12 18:15:19 +02:00
|
|
|
if (!defined($strValue) && !$bNegate && $strOption ne OPTION_CONFIG &&
|
2015-04-01 21:58:33 +02:00
|
|
|
$oOptionRule{$strOption}{&OPTION_RULE_SECTION} && $bDependResolved)
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
|
|
|
# If the config option has not been resolved yet then continue processing
|
|
|
|
if (!defined($oOptionResolved{&OPTION_CONFIG}) || !defined($oOptionResolved{&OPTION_STANZA}))
|
|
|
|
{
|
|
|
|
$bDependUnresolved = true;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# If the config option is defined try to get the option from the config file
|
2015-04-19 23:29:52 +02:00
|
|
|
if ($bConfigExists && defined($oOption{&OPTION_CONFIG}{value}))
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
|
|
|
# Attempt to load the config file if it has not been loaded
|
|
|
|
if (!defined($oConfig))
|
|
|
|
{
|
2015-04-19 23:29:52 +02:00
|
|
|
my $strConfigFile = $oOption{&OPTION_CONFIG}{value};
|
2015-03-12 18:15:19 +02:00
|
|
|
$bConfigExists = -e $strConfigFile;
|
|
|
|
|
|
|
|
if ($bConfigExists)
|
|
|
|
{
|
|
|
|
if (!-f $strConfigFile)
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "'${strConfigFile}' is not a file", ERROR_FILE_INVALID);
|
|
|
|
}
|
|
|
|
|
2015-06-14 00:25:49 +02:00
|
|
|
$oConfig = iniLoad($strConfigFile, undef, true);
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get the section that the value should be in
|
|
|
|
my $strSection = defined($oOptionRule{$strOption}{&OPTION_RULE_SECTION}) ?
|
|
|
|
($oOptionRule{$strOption}{&OPTION_RULE_SECTION} eq '1' ?
|
2015-06-18 22:55:09 +02:00
|
|
|
$strCommandSection : $oOptionRule{$strOption}{&OPTION_RULE_SECTION}) : undef;
|
2015-03-12 18:15:19 +02:00
|
|
|
|
|
|
|
# Only look in the stanza section when $strSection = true
|
|
|
|
if ($strSection eq CONFIG_SECTION_STANZA)
|
|
|
|
{
|
2015-06-14 00:25:49 +02:00
|
|
|
if (optionTest(OPTION_STANZA))
|
|
|
|
{
|
|
|
|
$strValue = $$oConfig{optionGet(OPTION_STANZA)}{$strOption};
|
|
|
|
}
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
# Else do a full search
|
|
|
|
else
|
|
|
|
{
|
|
|
|
# First check in the stanza section
|
2015-06-14 00:25:49 +02:00
|
|
|
if (optionTest(OPTION_STANZA))
|
|
|
|
{
|
|
|
|
$strValue = $oOptionRule{$strOption}{&OPTION_RULE_TYPE} eq OPTION_TYPE_HASH ?
|
|
|
|
$$oConfig{optionGet(OPTION_STANZA) . ":${strSection}"} :
|
|
|
|
$$oConfig{optionGet(OPTION_STANZA) . ":${strSection}"}{$strOption};
|
|
|
|
}
|
2015-03-12 18:15:19 +02:00
|
|
|
|
|
|
|
# Else check for an inherited stanza section
|
|
|
|
if (!defined($strValue))
|
|
|
|
{
|
|
|
|
my $strInheritedSection = undef;
|
|
|
|
|
|
|
|
$strInheritedSection = $oOptionRule{$strOption}{&OPTION_RULE_SECTION_INHERIT};
|
|
|
|
|
|
|
|
if (defined($strInheritedSection))
|
|
|
|
{
|
2015-06-14 00:25:49 +02:00
|
|
|
if (optionTest(OPTION_STANZA))
|
|
|
|
{
|
|
|
|
$strValue = $$oConfig{optionGet(OPTION_STANZA) . ":${strInheritedSection}"}{$strOption};
|
|
|
|
}
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Else check the global section
|
|
|
|
if (!defined($strValue))
|
|
|
|
{
|
|
|
|
$strValue = $oOptionRule{$strOption}{&OPTION_RULE_TYPE} eq OPTION_TYPE_HASH ?
|
|
|
|
$$oConfig{&CONFIG_GLOBAL . ":${strSection}"} :
|
|
|
|
$$oConfig{&CONFIG_GLOBAL . ":${strSection}"}{$strOption};
|
|
|
|
|
|
|
|
# Else check the global inherited section
|
|
|
|
if (!defined($strValue) && defined($strInheritedSection))
|
|
|
|
{
|
|
|
|
$strValue = $$oConfig{&CONFIG_GLOBAL . ":${strInheritedSection}"}{$strOption};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Fix up data types
|
|
|
|
if (defined($strValue))
|
|
|
|
{
|
|
|
|
if ($strValue eq '')
|
|
|
|
{
|
|
|
|
$strValue = undef;
|
|
|
|
}
|
|
|
|
elsif ($oOptionRule{$strOption}{&OPTION_RULE_TYPE} eq OPTION_TYPE_BOOLEAN)
|
|
|
|
{
|
|
|
|
if ($strValue eq 'y')
|
|
|
|
{
|
|
|
|
$strValue = true;
|
|
|
|
}
|
|
|
|
elsif ($strValue eq 'n')
|
|
|
|
{
|
|
|
|
$strValue = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "'${strValue}' is not valid for '${strOption}' option",
|
|
|
|
ERROR_OPTION_INVALID_VALUE);
|
|
|
|
}
|
|
|
|
}
|
2015-04-19 23:29:52 +02:00
|
|
|
|
|
|
|
$oOption{$strOption}{source} = SOURCE_CONFIG;
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-03 05:58:32 +02:00
|
|
|
|
2015-04-01 21:58:33 +02:00
|
|
|
if (defined($oDepend) && !$bDependResolved && defined($strValue))
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
|
|
|
my $strError = "option '${strOption}' not valid without option '${strDependOption}'";
|
|
|
|
|
2015-04-01 21:58:33 +02:00
|
|
|
if ($strDependType eq 'source')
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
|
|
|
confess &log(ERROR, $strError, ERROR_OPTION_INVALID);
|
|
|
|
}
|
|
|
|
|
|
|
|
# If a depend value exists, make sure the option value matches
|
2015-04-01 21:58:33 +02:00
|
|
|
if ($strDependType eq 'value')
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-04-01 21:58:33 +02:00
|
|
|
if ($oOptionRule{$strDependOption}{&OPTION_RULE_TYPE} eq OPTION_TYPE_BOOLEAN)
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-04-01 21:58:33 +02:00
|
|
|
if (!$$oDepend{&OPTION_RULE_DEPEND_VALUE})
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-04-01 21:58:33 +02:00
|
|
|
confess &log(ASSERT, "no error has been created for unused case where depend value = false");
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-01 21:58:33 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$strError .= " = '$$oDepend{&OPTION_RULE_DEPEND_VALUE}'";
|
|
|
|
}
|
|
|
|
|
|
|
|
confess &log(ERROR, $strError, ERROR_OPTION_INVALID);
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# If a depend list exists, make sure the value is in the list
|
2015-04-01 21:58:33 +02:00
|
|
|
if ($strDependType eq 'list')
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-04-01 21:58:33 +02:00
|
|
|
my @oyValue;
|
2015-03-12 18:15:19 +02:00
|
|
|
|
2015-06-21 18:06:13 +02:00
|
|
|
foreach my $strValue (sort(keys(%{$$oDepend{&OPTION_RULE_DEPEND_LIST}})))
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-04-01 21:58:33 +02:00
|
|
|
push(@oyValue, "'${strValue}'");
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
2015-04-01 21:58:33 +02:00
|
|
|
|
|
|
|
$strError .= @oyValue == 1 ? " = $oyValue[0]" : " in (" . join(", ", @oyValue) . ")";
|
|
|
|
confess &log(ERROR, $strError, ERROR_OPTION_INVALID);
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
}
|
2015-03-03 05:58:32 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
# Is the option defined?
|
|
|
|
if (defined($strValue))
|
|
|
|
{
|
|
|
|
# Check that floats and integers are valid
|
|
|
|
if ($oOptionRule{$strOption}{&OPTION_RULE_TYPE} eq OPTION_TYPE_INTEGER ||
|
|
|
|
$oOptionRule{$strOption}{&OPTION_RULE_TYPE} eq OPTION_TYPE_FLOAT)
|
|
|
|
{
|
|
|
|
# Test that the string is a valid float or integer by adding 1 to it. It's pretty hokey but it works and it
|
|
|
|
# beats requiring Scalar::Util::Numeric to do it properly.
|
|
|
|
eval
|
|
|
|
{
|
|
|
|
my $strTest = $strValue + 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
my $bError = $@ ? true : false;
|
|
|
|
|
|
|
|
# Check that integers are really integers
|
|
|
|
if (!$bError && $oOptionRule{$strOption}{&OPTION_RULE_TYPE} eq OPTION_TYPE_INTEGER &&
|
|
|
|
(int($strValue) . 'S') ne ($strValue . 'S'))
|
|
|
|
{
|
|
|
|
$bError = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Error if the value did not pass tests
|
|
|
|
!$bError
|
|
|
|
or confess &log(ERROR, "'${strValue}' is not valid for '${strOption}' option", ERROR_OPTION_INVALID_VALUE);
|
|
|
|
}
|
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
# Process an allow list for the command then for the option
|
|
|
|
my $oAllow = defined($oCommandRule) ? $$oCommandRule{&OPTION_RULE_ALLOW_LIST} :
|
|
|
|
$oOptionRule{$strOption}{&OPTION_RULE_ALLOW_LIST};
|
2015-03-12 18:15:19 +02:00
|
|
|
|
|
|
|
if (defined($oAllow) && !defined($$oAllow{$strValue}))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "'${strValue}' is not valid for '${strOption}' option", ERROR_OPTION_INVALID_VALUE);
|
|
|
|
}
|
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
# Process an allow range for the command then for the option
|
|
|
|
$oAllow = defined($oCommandRule) ? $$oCommandRule{&OPTION_RULE_ALLOW_RANGE} :
|
2015-03-12 18:15:19 +02:00
|
|
|
$oOptionRule{$strOption}{&OPTION_RULE_ALLOW_RANGE};
|
|
|
|
|
|
|
|
if (defined($oAllow) && ($strValue < $$oAllow[0] || $strValue > $$oAllow[1]))
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "'${strValue}' is not valid for '${strOption}' option", ERROR_OPTION_INVALID_RANGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Set option value
|
|
|
|
if ($oOptionRule{$strOption}{&OPTION_RULE_TYPE} eq OPTION_TYPE_HASH && ref($strValue) eq 'ARRAY')
|
|
|
|
{
|
|
|
|
foreach my $strItem (@{$strValue})
|
|
|
|
{
|
|
|
|
# Check for = and make sure there is a least one character on each side
|
|
|
|
my $iEqualPos = index($strItem, '=');
|
|
|
|
|
|
|
|
if ($iEqualPos < 1 || length($strItem) <= $iEqualPos + 1)
|
|
|
|
{
|
|
|
|
confess &log(ERROR, "'${strItem}' not valid key/value for '${strOption}' option",
|
|
|
|
ERROR_OPTION_INVALID_PAIR);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check that the key has not already been set
|
|
|
|
my $strKey = substr($strItem, 0, $iEqualPos);
|
|
|
|
|
2015-04-19 23:29:52 +02:00
|
|
|
if (defined($oOption{$strOption}{$strKey}{value}))
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
|
|
|
confess &log(ERROR, "'${$strItem}' already defined for '${strOption}' option",
|
|
|
|
ERROR_OPTION_DUPLICATE_KEY);
|
|
|
|
}
|
|
|
|
|
2015-04-19 23:29:52 +02:00
|
|
|
$oOption{$strOption}{value}{$strKey} = substr($strItem, $iEqualPos + 1);
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-19 23:29:52 +02:00
|
|
|
$oOption{$strOption}{value} = $strValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
# If not config sourced then it must be a param
|
|
|
|
if (!defined($oOption{$strOption}{source}))
|
|
|
|
{
|
|
|
|
$oOption{$strOption}{source} = SOURCE_PARAM;
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
}
|
2015-03-16 20:01:01 +02:00
|
|
|
# Else try to set a default
|
|
|
|
elsif ($bDependResolved &&
|
2015-06-18 22:55:09 +02:00
|
|
|
(!defined($oOptionRule{$strOption}{&OPTION_RULE_COMMAND}) ||
|
|
|
|
defined($oOptionRule{$strOption}{&OPTION_RULE_COMMAND}{$strCommand})))
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-04-19 23:29:52 +02:00
|
|
|
# Source is default for this option
|
|
|
|
$oOption{$strOption}{source} = SOURCE_DEFAULT;
|
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
# Check for default in command then option
|
|
|
|
my $strDefault = optionDefault($strOption, $strCommand);
|
2015-03-12 18:15:19 +02:00
|
|
|
|
|
|
|
# If default is defined
|
|
|
|
if (defined($strDefault))
|
|
|
|
{
|
|
|
|
# Only set default if dependency is resolved
|
2015-04-19 23:29:52 +02:00
|
|
|
$oOption{$strOption}{value} = $strDefault if !$bNegate;
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
2015-03-16 20:01:01 +02:00
|
|
|
# Else check required
|
2015-06-18 22:55:09 +02:00
|
|
|
elsif (optionRequired($strOption, $strCommand))
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
confess &log(ERROR, "${strCommand} command requires option: ${strOption}" .
|
2015-05-29 02:52:42 +02:00
|
|
|
(defined($oOptionRule{$strOption}{&OPTION_RULE_HINT}) ?
|
|
|
|
"\nHINT: " . $oOptionRule{$strOption}{&OPTION_RULE_HINT} : ''),
|
|
|
|
ERROR_OPTION_REQUIRED);
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
}
|
2015-03-03 05:58:32 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
$oOptionResolved{$strOption} = true;
|
|
|
|
}
|
|
|
|
}
|
2015-03-03 05:58:32 +02:00
|
|
|
}
|
|
|
|
|
2015-03-16 20:01:01 +02:00
|
|
|
####################################################################################################################################
|
2015-06-18 22:55:09 +02:00
|
|
|
# optionCommandRule
|
2015-03-16 20:01:01 +02:00
|
|
|
#
|
2015-06-18 22:55:09 +02:00
|
|
|
# Returns the option rules based on the command.
|
2015-03-16 20:01:01 +02:00
|
|
|
####################################################################################################################################
|
2015-06-18 22:55:09 +02:00
|
|
|
sub optionCommandRule
|
2015-03-16 20:01:01 +02:00
|
|
|
{
|
|
|
|
my $strOption = shift;
|
2015-06-18 22:55:09 +02:00
|
|
|
my $strCommand = shift;
|
2015-03-16 20:01:01 +02:00
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
if (defined($strCommand))
|
2015-03-25 00:50:14 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
return defined($oOptionRule{$strOption}{&OPTION_RULE_COMMAND}) &&
|
|
|
|
defined($oOptionRule{$strOption}{&OPTION_RULE_COMMAND}{$strCommand}) &&
|
|
|
|
ref($oOptionRule{$strOption}{&OPTION_RULE_COMMAND}{$strCommand}) eq 'HASH' ?
|
|
|
|
$oOptionRule{$strOption}{&OPTION_RULE_COMMAND}{$strCommand} : undef;
|
2015-03-25 00:50:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return undef;
|
2015-03-16 20:01:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# optionRequired
|
|
|
|
#
|
2015-06-18 22:55:09 +02:00
|
|
|
# Is the option required for this command?
|
2015-03-16 20:01:01 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
sub optionRequired
|
|
|
|
{
|
|
|
|
my $strOption = shift;
|
2015-06-18 22:55:09 +02:00
|
|
|
my $strCommand = shift;
|
2015-03-16 20:01:01 +02:00
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
# Get the command rule
|
|
|
|
my $oCommandRule = optionCommandRule($strOption, $strCommand);
|
2015-03-16 20:01:01 +02:00
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
# Check for required in command then option
|
|
|
|
my $bRequired = defined($oCommandRule) ? $$oCommandRule{&OPTION_RULE_REQUIRED} :
|
|
|
|
$oOptionRule{$strOption}{&OPTION_RULE_REQUIRED};
|
2015-03-16 20:01:01 +02:00
|
|
|
|
|
|
|
# Return required
|
|
|
|
return !defined($bRequired) || $bRequired;
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# optionDefault
|
|
|
|
#
|
2015-06-18 22:55:09 +02:00
|
|
|
# Does the option have a default for this command?
|
2015-03-16 20:01:01 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
sub optionDefault
|
|
|
|
{
|
|
|
|
my $strOption = shift;
|
2015-06-18 22:55:09 +02:00
|
|
|
my $strCommand = shift;
|
2015-03-16 20:01:01 +02:00
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
# Get the command rule
|
|
|
|
my $oCommandRule = optionCommandRule($strOption, $strCommand);
|
2015-03-16 20:01:01 +02:00
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
# Check for default in command
|
|
|
|
my $strDefault = defined($oCommandRule) ? $$oCommandRule{&OPTION_RULE_DEFAULT} : undef;
|
2015-03-16 20:45:53 +02:00
|
|
|
|
2015-03-16 20:01:01 +02:00
|
|
|
# If defined return, else try to grab the global default
|
|
|
|
return defined($strDefault) ? $strDefault : $oOptionRule{$strOption}{&OPTION_RULE_DEFAULT};
|
|
|
|
}
|
|
|
|
|
2015-03-03 05:58:32 +02:00
|
|
|
####################################################################################################################################
|
2015-06-18 22:55:09 +02:00
|
|
|
# commandGet
|
2015-03-03 05:58:32 +02:00
|
|
|
#
|
2015-06-18 22:55:09 +02:00
|
|
|
# Get the current command.
|
2015-03-03 05:58:32 +02:00
|
|
|
####################################################################################################################################
|
2015-06-18 22:55:09 +02:00
|
|
|
sub commandGet
|
2015-03-03 05:58:32 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
return $strCommand;
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
2015-03-03 05:58:32 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
####################################################################################################################################
|
2015-06-18 22:55:09 +02:00
|
|
|
# commandTest
|
2015-03-12 18:15:19 +02:00
|
|
|
#
|
2015-06-18 22:55:09 +02:00
|
|
|
# Test the current command.
|
2015-03-12 18:15:19 +02:00
|
|
|
####################################################################################################################################
|
2015-06-18 22:55:09 +02:00
|
|
|
sub commandTest
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
my $strCommandTest = shift;
|
2015-03-03 05:58:32 +02:00
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
return $strCommandTest eq $strCommand;
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2015-06-18 22:55:09 +02:00
|
|
|
# commandSet
|
2015-03-12 18:15:19 +02:00
|
|
|
#
|
2015-06-18 22:55:09 +02:00
|
|
|
# Set current command (usually for triggering follow-on commands).
|
2015-03-12 18:15:19 +02:00
|
|
|
####################################################################################################################################
|
2015-06-18 22:55:09 +02:00
|
|
|
sub commandSet
|
2015-03-12 18:15:19 +02:00
|
|
|
{
|
|
|
|
my $strValue = shift;
|
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
$strCommand = $strValue;
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# optionGet
|
|
|
|
#
|
|
|
|
# Get option value.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub optionGet
|
|
|
|
{
|
|
|
|
my $strOption = shift;
|
|
|
|
my $bRequired = shift;
|
|
|
|
|
2015-04-19 23:29:52 +02:00
|
|
|
if (!defined($oOption{$strOption}{value}) && (!defined($bRequired) || $bRequired))
|
2015-03-03 03:36:12 +02:00
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
confess &log(ASSERT, "option ${strOption} is required");
|
2015-03-03 03:36:12 +02:00
|
|
|
}
|
|
|
|
|
2015-04-19 23:29:52 +02:00
|
|
|
return $oOption{$strOption}{value};
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2015-06-18 22:55:09 +02:00
|
|
|
# commandWrite
|
2015-04-19 23:29:52 +02:00
|
|
|
#
|
2015-06-18 22:55:09 +02:00
|
|
|
# Using the options that were passed to the current command, write the command string for another command. For example, this
|
2015-04-19 23:29:52 +02:00
|
|
|
# can be used to write the archive-get command for recovery.conf during a restore.
|
|
|
|
####################################################################################################################################
|
2015-06-18 22:55:09 +02:00
|
|
|
sub commandWrite
|
2015-04-19 23:29:52 +02:00
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
my $strNewCommand = shift;
|
2015-06-18 21:39:30 +02:00
|
|
|
my $bIncludeConfig = shift;
|
2015-06-18 22:55:09 +02:00
|
|
|
my $strCommandString = shift;
|
2015-06-18 21:39:30 +02:00
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
$strCommandString = defined($strCommandString) ? $strCommandString : abs_path($0);
|
2015-04-19 23:29:52 +02:00
|
|
|
|
2015-06-18 21:39:30 +02:00
|
|
|
# If config setting are included then also set --no-config
|
|
|
|
$bIncludeConfig = defined($bIncludeConfig) ? $bIncludeConfig : false;
|
|
|
|
|
|
|
|
if ($bIncludeConfig)
|
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
$strCommandString .= ' --no-config';
|
2015-06-18 21:39:30 +02:00
|
|
|
}
|
2015-04-19 23:29:52 +02:00
|
|
|
|
|
|
|
foreach my $strOption (sort(keys(%oOption)))
|
|
|
|
{
|
2015-06-18 21:39:30 +02:00
|
|
|
next if ($bIncludeConfig && $strOption eq OPTION_CONFIG);
|
|
|
|
|
|
|
|
# &log(WARN, "option ${strOption} = " . (defined($oOption{$strOption}{source}) ? $oOption{$strOption}{source} : 'undef') .
|
|
|
|
# ", " . (defined($oOption{$strOption}{value}) ? $oOption{$strOption}{value} : 'undef'));
|
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
if ((!defined($oOptionRule{$strOption}{&OPTION_RULE_COMMAND}) ||
|
|
|
|
defined($oOptionRule{$strOption}{&OPTION_RULE_COMMAND}{$strNewCommand})) &&
|
2015-06-18 21:39:30 +02:00
|
|
|
defined($oOption{$strOption}{value}) &&
|
|
|
|
($bIncludeConfig ? $oOption{$strOption}{source} ne SOURCE_DEFAULT : $oOption{$strOption}{source} eq SOURCE_PARAM))
|
2015-04-19 23:29:52 +02:00
|
|
|
{
|
2015-06-18 21:39:30 +02:00
|
|
|
my $strParam;
|
|
|
|
|
|
|
|
if ($oOptionRule{$strOption}{&OPTION_RULE_TYPE} eq OPTION_TYPE_BOOLEAN)
|
|
|
|
{
|
|
|
|
$strParam = '--' . ($oOption{$strOption}{value} ? '' : 'no-') . $strOption;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$strParam = "--${strOption}=$oOption{$strOption}{value}";
|
|
|
|
}
|
2015-04-19 23:29:52 +02:00
|
|
|
|
|
|
|
if (index($oOption{$strOption}{value}, " ") != -1)
|
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
$strCommandString .= " \"${strParam}\"";
|
2015-04-19 23:29:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-18 22:55:09 +02:00
|
|
|
$strCommandString .= " ${strParam}";
|
2015-04-19 23:29:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-18 22:55:09 +02:00
|
|
|
$strCommandString .= " ${strNewCommand}";
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
2015-03-03 05:58:32 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
####################################################################################################################################
|
2015-06-18 22:55:09 +02:00
|
|
|
# optionTest
|
2015-03-12 18:15:19 +02:00
|
|
|
#
|
|
|
|
# Test a option value.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub optionTest
|
|
|
|
{
|
|
|
|
my $strOption = shift;
|
|
|
|
my $strValue = shift;
|
2015-01-31 22:37:59 +02:00
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
if (defined($strValue))
|
2015-01-31 22:37:59 +02:00
|
|
|
{
|
2015-03-12 18:15:19 +02:00
|
|
|
return optionGet($strOption) eq $strValue;
|
2015-01-31 22:37:59 +02:00
|
|
|
}
|
2015-03-12 18:15:19 +02:00
|
|
|
|
2015-04-19 23:29:52 +02:00
|
|
|
return defined($oOption{$strOption}{value});
|
2015-03-12 18:15:19 +02:00
|
|
|
}
|
|
|
|
|
2015-04-01 21:58:33 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# optionRemoteType
|
|
|
|
#
|
|
|
|
# Returns the remote type.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub optionRemoteType
|
|
|
|
{
|
|
|
|
return $strRemoteType;
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# optionRemoteTypeTest
|
|
|
|
#
|
|
|
|
# Test the remote type.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub optionRemoteTypeTest
|
|
|
|
{
|
|
|
|
my $strTest = shift;
|
|
|
|
|
|
|
|
return $strRemoteType eq $strTest ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2015-06-17 17:26:07 +02:00
|
|
|
# protocolGet
|
2015-04-01 21:58:33 +02:00
|
|
|
#
|
2015-06-17 17:26:07 +02:00
|
|
|
# Get the protocol object or create it if does not exist. Shared protocol objects are used because they create an SSH connection
|
|
|
|
# to the remote host and the number of these connections should be minimized. A protocol object can be shared within a single
|
|
|
|
# thread - for new threads clone() should be called on the shared protocol object.
|
2015-04-01 21:58:33 +02:00
|
|
|
####################################################################################################################################
|
2015-06-17 17:26:07 +02:00
|
|
|
sub protocolGet
|
2015-04-01 21:58:33 +02:00
|
|
|
{
|
|
|
|
my $bForceLocal = shift;
|
2015-04-07 13:34:37 +02:00
|
|
|
my $bStore = shift;
|
2015-04-01 21:58:33 +02:00
|
|
|
|
|
|
|
# If force local or remote = NONE then create a local remote and return it
|
|
|
|
if ((defined($bForceLocal) && $bForceLocal) || optionRemoteTypeTest(NONE))
|
|
|
|
{
|
2015-08-05 14:43:41 +02:00
|
|
|
return new BackRest::Protocol::Common
|
2015-04-01 21:58:33 +02:00
|
|
|
(
|
|
|
|
optionGet(OPTION_BUFFER_SIZE),
|
2015-06-18 22:55:09 +02:00
|
|
|
commandTest(CMD_EXPIRE) ? OPTION_DEFAULT_COMPRESS_LEVEL : optionGet(OPTION_COMPRESS_LEVEL),
|
|
|
|
commandTest(CMD_EXPIRE) ? OPTION_DEFAULT_COMPRESS_LEVEL_NETWORK : optionGet(OPTION_COMPRESS_LEVEL_NETWORK)
|
2015-04-01 21:58:33 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Return the remote if is already defined
|
2015-06-17 17:26:07 +02:00
|
|
|
if (defined($oProtocol))
|
2015-04-01 21:58:33 +02:00
|
|
|
{
|
2015-06-17 17:26:07 +02:00
|
|
|
return $oProtocol;
|
2015-04-01 21:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Return the remote when required
|
2015-08-05 14:43:41 +02:00
|
|
|
my $oProtocolTemp = new BackRest::Protocol::RemoteMaster
|
2015-04-01 21:58:33 +02:00
|
|
|
(
|
2015-06-18 22:55:09 +02:00
|
|
|
commandWrite(CMD_REMOTE, true, optionGet(OPTION_COMMAND_REMOTE)),
|
2015-04-01 21:58:33 +02:00
|
|
|
optionGet(OPTION_BUFFER_SIZE),
|
2015-06-18 22:55:09 +02:00
|
|
|
commandTest(CMD_EXPIRE) ? OPTION_DEFAULT_COMPRESS_LEVEL : optionGet(OPTION_COMPRESS_LEVEL),
|
2015-08-05 14:43:41 +02:00
|
|
|
commandTest(CMD_EXPIRE) ? OPTION_DEFAULT_COMPRESS_LEVEL_NETWORK : optionGet(OPTION_COMPRESS_LEVEL_NETWORK),
|
|
|
|
optionRemoteTypeTest(DB) ? optionGet(OPTION_DB_HOST) : optionGet(OPTION_BACKUP_HOST),
|
|
|
|
optionRemoteTypeTest(DB) ? optionGet(OPTION_DB_USER) : optionGet(OPTION_BACKUP_USER)
|
2015-04-01 21:58:33 +02:00
|
|
|
);
|
|
|
|
|
2015-07-10 15:20:28 +02:00
|
|
|
if (!defined($bStore) || $bStore)
|
2015-04-07 13:34:37 +02:00
|
|
|
{
|
2015-06-17 17:26:07 +02:00
|
|
|
$oProtocol = $oProtocolTemp;
|
2015-04-07 13:34:37 +02:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:26:07 +02:00
|
|
|
return $oProtocolTemp;
|
2015-04-07 13:34:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
2015-06-17 17:26:07 +02:00
|
|
|
# protocolDestroy
|
2015-04-07 13:34:37 +02:00
|
|
|
#
|
2015-06-17 17:26:07 +02:00
|
|
|
# Undefine the protocol if it is stored locally.
|
2015-04-07 13:34:37 +02:00
|
|
|
####################################################################################################################################
|
2015-06-17 17:26:07 +02:00
|
|
|
sub protocolDestroy
|
2015-04-07 13:34:37 +02:00
|
|
|
{
|
2015-06-17 17:26:07 +02:00
|
|
|
if (defined($oProtocol))
|
2015-04-07 13:34:37 +02:00
|
|
|
{
|
2015-06-17 17:26:07 +02:00
|
|
|
undef($oProtocol);
|
2015-04-07 13:34:37 +02:00
|
|
|
}
|
2015-04-01 21:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# optionRemoteTest
|
|
|
|
#
|
|
|
|
# Test if the remote DB or BACKUP.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub optionRemoteTest
|
|
|
|
{
|
|
|
|
return $strRemoteType ne NONE ? true : false;
|
|
|
|
}
|
|
|
|
|
2015-03-12 18:15:19 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# optionRuleGet
|
|
|
|
#
|
|
|
|
# Get the option rules.
|
|
|
|
####################################################################################################################################
|
|
|
|
sub optionRuleGet
|
|
|
|
{
|
|
|
|
use Storable qw(dclone);
|
|
|
|
return dclone(\%oOptionRule);
|
2015-01-31 20:48:09 +02:00
|
|
|
}
|
|
|
|
|
2014-12-16 00:20:42 +02:00
|
|
|
1;
|