pgbackrest.git / summary / log / commit / refs

commit    de9b6d5133c5fbbb02cb0c8b7d4596843a2d3545
Author:   David Steele <david@pgmasters.net>
Date:     Sat Feb 06 21:49:12 2016 +0000

    Closed #113: Better error message when repo does not exist.


CHANGELOG.md | 2 ++ bin/pg_backrest | 13 +++++++++++++ doc/xml/change-log.xml | 3 +++ lib/BackRest/Common/Exception.pm | 2 ++ lib/BackRest/Config/Config.pm | 2 +- test/lib/BackRestTest/BackupTest.pm | 13 +++++++++++++ test/lib/BackRestTest/FileTest.pm | 5 +++-- test/log/backup-synthetic-001.log | 7 +++++++ test/log/backup-synthetic-005.log | 7 +++++++ 9 files changed, 51 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c2ad1870..bfdcbb557 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ __No Release Date Set__ * Generate an error when `archive-check=y` but `archive_command` does not execute `pg_backrest`. _Contributed by Jason O'Donnell_. +* Improved error message when `repo-path` or `repo-remote-path` does not exist. + * Added checks for `--delta` and `--force` restore options to ensure that the destination is a valid $PGDATA directory. pgBackRest will check for the presence of `PG_VERSION` or `backup.manifest` (left over from an aborted restore). If neither is found then `--delta` and `--force` will be disabled but the restore will proceed unless there are files in the $PGDATA directory (or any tablespace directories) in which case the operation will be aborted. * When restore `--set=latest` (the default) the actual backup restored will be output to the log. diff --git a/bin/pg_backrest b/bin/pg_backrest index b8fe17409..63243a9ff 100755 --- a/bin/pg_backrest +++ b/bin/pg_backrest @@ -59,6 +59,13 @@ eval # Set log levels logLevelSet(OFF, REMOTE); + # Check that the remote repo path exists + if (optionTest(OPTION_REPO_REMOTE_PATH) && !-e optionGet(OPTION_REPO_REMOTE_PATH)) + { + confess &log(ERROR, 'repo-remote-path \'' . optionGet(OPTION_REPO_REMOTE_PATH) . '\' does not exist', + ERROR_PATH_MISSING); + } + # Load module dynamically require BackRest::Protocol::RemoteMinion; BackRest::Protocol::RemoteMinion->import(); @@ -89,6 +96,12 @@ eval # Log the command start commandStart(); + # Check that the repo path exists + if (optionTest(OPTION_REPO_PATH) && !-e optionGet(OPTION_REPO_PATH)) + { + confess &log(ERROR, 'repo-path \'' . optionGet(OPTION_REPO_PATH) . '\' does not exist', ERROR_PATH_MISSING); + } + ################################################################################################################################ # Process archive commands ################################################################################################################################ diff --git a/doc/xml/change-log.xml b/doc/xml/change-log.xml index e39f9d348..1356a64a1 100644 --- a/doc/xml/change-log.xml +++ b/doc/xml/change-log.xml @@ -26,6 +26,9 @@ <release-feature> <text>Generate an error when <setting>archive-check=y</setting> but <setting>archive_command</setting> does not execute <file>pg_backrest</file>. <i>Contributed by Jason O'Donnell</i>.</text> </release-feature> + <release-feature> + <text>Improved error message when <setting>repo-path</setting> or <setting>repo-remote-path</setting> does not exist.</text> + </release-feature> <release-feature> <text>Added checks for <setting>--delta</setting> and <setting>--force</setting> restore options to ensure that the destination is a valid $PGDATA directory. <backrest/> will check for the presence of <file>PG_VERSION</file> or <file>backup.manifest</file> (left over from an aborted restore). If neither is found then <setting>--delta</setting> and <setting>--force</setting> will be disabled but the restore will proceed unless there are files in the $PGDATA directory (or any tablespace directories) in which case the operation will be aborted.</text> </release-feature> diff --git a/lib/BackRest/Common/Exception.pm b/lib/BackRest/Common/Exception.pm index 4ffc15841..c01e8038e 100644 --- a/lib/BackRest/Common/Exception.pm +++ b/lib/BackRest/Common/Exception.pm @@ -114,6 +114,8 @@ use constant ERROR_TABLESPACE_IN_PGDATA => ERROR_MIN push @EXPORT, qw(ERROR_TABLESPACE_IN_PGDATA); use constant ERROR_HOST_INVALID => ERROR_MINIMUM + 47; push @EXPORT, qw(ERROR_HOST_INVALID); +use constant ERROR_PATH_MISSING => ERROR_MINIMUM + 48; + push @EXPORT, qw(ERROR_PATH_MISSING); use constant ERROR_INVALID_VALUE => ERROR_MAXIMUM - 1; push @EXPORT, qw(ERROR_INVALID_VALUE); diff --git a/lib/BackRest/Config/Config.pm b/lib/BackRest/Config/Config.pm index acd1c7153..9bb815cbe 100644 --- a/lib/BackRest/Config/Config.pm +++ b/lib/BackRest/Config/Config.pm @@ -1620,7 +1620,7 @@ sub optionValid $strCommandSection = $strCommand; } - # Hash to store contents of the config file. The file will be loaded one the config dependency is resolved unless all options + # Hash to store contents of the config file. The file will be loaded once the config dependency is resolved unless all options # are set on the command line or --no-config is specified. my $oConfig; my $bConfigExists = true; diff --git a/test/lib/BackRestTest/BackupTest.pm b/test/lib/BackRestTest/BackupTest.pm index 735d55412..da49a8d6c 100755 --- a/test/lib/BackRestTest/BackupTest.pm +++ b/test/lib/BackRestTest/BackupTest.pm @@ -88,6 +88,8 @@ sub BackRestTestBackup_Test #------------------------------------------------------------------------------------------------------------------------------- # Create remotes #------------------------------------------------------------------------------------------------------------------------------- + BackRestTestBackup_Create(true, false); + my $oRemote = new BackRest::Protocol::RemoteMaster ( BackRestTestCommon_CommandRemoteFullGet(), # Remote command @@ -99,6 +101,8 @@ sub BackRestTestBackup_Test PROTOCOL_TIMEOUT_TEST # Protocol timeout ); + BackRestTestBackup_Drop(); + my $oLocal = new BackRest::Protocol::Common ( OPTION_DEFAULT_BUFFER_SIZE, # Buffer size @@ -1044,6 +1048,15 @@ sub BackRestTestBackup_Test $strFullBackup = BackRestTestBackup_BackupSynthetic($strType, $strStanza, \%oManifest, 'resume', {strTest => TEST_BACKUP_RESUME}); + # Misconfigure repo-path and check errors + #----------------------------------------------------------------------------------------------------------------------- + if ($bNeutralTest) + { + BackRestTestBackup_BackupSynthetic($strType, $strStanza, \%oManifest, 'invalid repo', + {strOptionalParam => '--' . ($bRemote ? OPTION_REPO_REMOTE_PATH : OPTION_REPO_PATH) . '=/bogus_path' . + ' --log-level-console=info', iExpectedExitStatus => ERROR_PATH_MISSING}); + } + # Restore - tests various mode, extra files/paths, missing files/paths #----------------------------------------------------------------------------------------------------------------------- my $bDelta = true; diff --git a/test/lib/BackRestTest/FileTest.pm b/test/lib/BackRestTest/FileTest.pm index 6c4970c28..c80a4917b 100755 --- a/test/lib/BackRestTest/FileTest.pm +++ b/test/lib/BackRestTest/FileTest.pm @@ -102,11 +102,12 @@ sub BackRestTestFile_Test #------------------------------------------------------------------------------------------------------------------------------- # Create remotes #------------------------------------------------------------------------------------------------------------------------------- - executeTest('rm -rf ' . cwd() . '/log_remote'); + mkdir($strTestPath, oct('0770')) or confess 'Unable to create test directory'; + mkdir($strTestPath . '/backrest', oct('0770')) or confess 'Unable to create test directory'; my $oRemote = new BackRest::Protocol::RemoteMaster ( - BackRestTestCommon_CommandRemoteFullGet() . ' --repo-path=' . cwd() . '/log_remote', # Remote command + BackRestTestCommon_CommandRemoteFullGet(), # Remote command OPTION_DEFAULT_BUFFER_SIZE, # Buffer size OPTION_DEFAULT_COMPRESS_LEVEL, # Compress level OPTION_DEFAULT_COMPRESS_LEVEL_NETWORK, # Compress network level diff --git a/test/log/backup-synthetic-001.log b/test/log/backup-synthetic-001.log index 779b2ad1f..c1b954f9f 100644 --- a/test/log/backup-synthetic-001.log +++ b/test/log/backup-synthetic-001.log @@ -530,6 +530,13 @@ db-version="9.3" [db:history] 1={"db-catalog-version":201306121,"db-control-version":937,"db-system-id":6156904820763115222,"db-version":"9.3"} +full backup (invalid repo) +> [BACKREST_BIN] --config=[TEST_PATH]/db/pg_backrest.conf --no-start-stop --repo-path=/bogus_path --log-level-console=info --type=full --stanza=db backup +------------------------------------------------------------------------------------------------------------------------------------ + INFO: backup start: --no-compress --config=[TEST_PATH]/db/pg_backrest.conf --config-remote=[TEST_PATH]/backrest/pg_backrest.conf --db-path=[TEST_PATH]/db/common --db-port=[PORT-1] --db-socket-path=[TEST_PATH]/db --log-level-console=info --log-level-file=trace --no-start-stop --repo-path=/bogus_path --repo-remote-path=/bogus_path --stanza=db --start-fast --type=full +ERROR: [148]: repo-path '/bogus_path' does not exist + INFO: backup stop + restore delta, backup '[BACKUP-FULL-2]' (add and delete files) > [BACKREST_BIN] --config=[TEST_PATH]/db/pg_backrest.conf --delta --set=[BACKUP-FULL-2] --stanza=db restore ------------------------------------------------------------------------------------------------------------------------------------ diff --git a/test/log/backup-synthetic-005.log b/test/log/backup-synthetic-005.log index 554cc6afe..6e84e932b 100644 --- a/test/log/backup-synthetic-005.log +++ b/test/log/backup-synthetic-005.log @@ -716,6 +716,13 @@ db-version="9.3" [db:history] 1={"db-catalog-version":201306121,"db-control-version":937,"db-system-id":6156904820763115222,"db-version":"9.3"} +full backup (invalid repo) +> [BACKREST_BIN] --config=[TEST_PATH]/backrest/pg_backrest.conf --no-start-stop --repo-remote-path=/bogus_path --log-level-console=info --type=full --stanza=db backup +------------------------------------------------------------------------------------------------------------------------------------ + INFO: backup start: --cmd-remote=[BACKREST_BIN] --no-compress --config=[TEST_PATH]/backrest/pg_backrest.conf --config-remote=[TEST_PATH]/db/pg_backrest.conf --db-host=127.0.0.1 --db-path=[TEST_PATH]/db/common --db-port=[PORT-1] --db-socket-path=[TEST_PATH]/db --db-user=vagrant --log-level-console=info --log-level-file=trace --no-start-stop --repo-path=[TEST_PATH]/backrest --repo-remote-path=/bogus_path --stanza=db --start-fast --type=full +ERROR: [148]: remote process terminated: ERROR [148]: repo-remote-path '/bogus_path' does not exist + INFO: backup stop + restore delta, backup '[BACKUP-FULL-2]' (add and delete files) > [BACKREST_BIN] --config=[TEST_PATH]/db/pg_backrest.conf --delta --set=[BACKUP-FULL-2] --stanza=db restore ------------------------------------------------------------------------------------------------------------------------------------ [parent: f8b47997a314]