diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index 4a5d8acd7..9957b5784 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -41,6 +41,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was a fatal error (no snapshot created). Exit status is 3 if some source data could not be read (incomplete snapshot created). +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, PreRun: func(_ *cobra.Command, _ []string) { diff --git a/cmd/restic/cmd_cat.go b/cmd/restic/cmd_cat.go index 46cd0ad6f..693c26790 100644 --- a/cmd/restic/cmd_cat.go +++ b/cmd/restic/cmd_cat.go @@ -23,6 +23,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_check.go b/cmd/restic/cmd_check.go index f6f7c5563..9cccc0609 100644 --- a/cmd/restic/cmd_check.go +++ b/cmd/restic/cmd_check.go @@ -37,6 +37,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_copy.go b/cmd/restic/cmd_copy.go index 158409f61..d7761174a 100644 --- a/cmd/restic/cmd_copy.go +++ b/cmd/restic/cmd_copy.go @@ -36,6 +36,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/cmd/restic/cmd_debug.go b/cmd/restic/cmd_debug.go index 044bf3af5..74c21df24 100644 --- a/cmd/restic/cmd_debug.go +++ b/cmd/restic/cmd_debug.go @@ -45,6 +45,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_diff.go b/cmd/restic/cmd_diff.go index b7c1036c4..6488a7c35 100644 --- a/cmd/restic/cmd_diff.go +++ b/cmd/restic/cmd_diff.go @@ -41,6 +41,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_dump.go b/cmd/restic/cmd_dump.go index 7a7c3850b..7e1efa3ae 100644 --- a/cmd/restic/cmd_dump.go +++ b/cmd/restic/cmd_dump.go @@ -36,6 +36,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_find.go b/cmd/restic/cmd_find.go index 8978297a0..4f9549ca4 100644 --- a/cmd/restic/cmd_find.go +++ b/cmd/restic/cmd_find.go @@ -35,6 +35,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_forget.go b/cmd/restic/cmd_forget.go index 104a75a78..87738b518 100644 --- a/cmd/restic/cmd_forget.go +++ b/cmd/restic/cmd_forget.go @@ -37,6 +37,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_key_add.go b/cmd/restic/cmd_key_add.go index 66fdfd184..c9f0ef233 100644 --- a/cmd/restic/cmd_key_add.go +++ b/cmd/restic/cmd_key_add.go @@ -21,6 +21,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_key_list.go b/cmd/restic/cmd_key_list.go index 679348969..ae751a487 100644 --- a/cmd/restic/cmd_key_list.go +++ b/cmd/restic/cmd_key_list.go @@ -25,6 +25,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_key_passwd.go b/cmd/restic/cmd_key_passwd.go index e2c23f9cb..723acaaab 100644 --- a/cmd/restic/cmd_key_passwd.go +++ b/cmd/restic/cmd_key_passwd.go @@ -21,6 +21,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_key_remove.go b/cmd/restic/cmd_key_remove.go index 761ed5b6d..c4c24fdb7 100644 --- a/cmd/restic/cmd_key_remove.go +++ b/cmd/restic/cmd_key_remove.go @@ -22,6 +22,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_list.go b/cmd/restic/cmd_list.go index 8a884ab8c..060bca871 100644 --- a/cmd/restic/cmd_list.go +++ b/cmd/restic/cmd_list.go @@ -21,6 +21,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_ls.go b/cmd/restic/cmd_ls.go index 115cc49e3..d9a3b0fb8 100644 --- a/cmd/restic/cmd_ls.go +++ b/cmd/restic/cmd_ls.go @@ -41,6 +41,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_migrate.go b/cmd/restic/cmd_migrate.go index f591a1b21..e89980050 100644 --- a/cmd/restic/cmd_migrate.go +++ b/cmd/restic/cmd_migrate.go @@ -24,6 +24,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_mount.go b/cmd/restic/cmd_mount.go index 52dbf4dac..3e0b159be 100644 --- a/cmd/restic/cmd_mount.go +++ b/cmd/restic/cmd_mount.go @@ -66,6 +66,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_prune.go b/cmd/restic/cmd_prune.go index 36226a16b..7e706ccf8 100644 --- a/cmd/restic/cmd_prune.go +++ b/cmd/restic/cmd_prune.go @@ -30,6 +30,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_recover.go b/cmd/restic/cmd_recover.go index 13b0ee536..5e4744bb6 100644 --- a/cmd/restic/cmd_recover.go +++ b/cmd/restic/cmd_recover.go @@ -24,6 +24,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_repair_index.go b/cmd/restic/cmd_repair_index.go index 9d0dd32b3..e6b6e9fa5 100644 --- a/cmd/restic/cmd_repair_index.go +++ b/cmd/restic/cmd_repair_index.go @@ -21,6 +21,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_repair_packs.go b/cmd/restic/cmd_repair_packs.go index c75c65915..b0afefb2d 100644 --- a/cmd/restic/cmd_repair_packs.go +++ b/cmd/restic/cmd_repair_packs.go @@ -25,6 +25,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_repair_snapshots.go b/cmd/restic/cmd_repair_snapshots.go index dc844c35a..fc221ebea 100644 --- a/cmd/restic/cmd_repair_snapshots.go +++ b/cmd/restic/cmd_repair_snapshots.go @@ -39,6 +39,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_restore.go b/cmd/restic/cmd_restore.go index c783a81a6..89942f4cf 100644 --- a/cmd/restic/cmd_restore.go +++ b/cmd/restic/cmd_restore.go @@ -34,6 +34,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_rewrite.go b/cmd/restic/cmd_rewrite.go index 07fcf3e67..73bc32f6f 100644 --- a/cmd/restic/cmd_rewrite.go +++ b/cmd/restic/cmd_rewrite.go @@ -40,6 +40,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_self_update.go b/cmd/restic/cmd_self_update.go index ce7f8ca99..0fce41241 100644 --- a/cmd/restic/cmd_self_update.go +++ b/cmd/restic/cmd_self_update.go @@ -26,6 +26,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_snapshots.go b/cmd/restic/cmd_snapshots.go index c043d7167..9112e1b95 100644 --- a/cmd/restic/cmd_snapshots.go +++ b/cmd/restic/cmd_snapshots.go @@ -25,6 +25,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_stats.go b/cmd/restic/cmd_stats.go index 1b00dbfba..8a78d57f7 100644 --- a/cmd/restic/cmd_stats.go +++ b/cmd/restic/cmd_stats.go @@ -51,6 +51,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/cmd_tag.go b/cmd/restic/cmd_tag.go index f3c98c27d..ea73955f0 100644 --- a/cmd/restic/cmd_tag.go +++ b/cmd/restic/cmd_tag.go @@ -27,6 +27,7 @@ EXIT STATUS Exit status is 0 if the command was successful. Exit status is 1 if there was any error. +Exit status is 10 if the repository does not exist. Exit status is 11 if the repository is already locked. `, DisableAutoGenTag: true, diff --git a/cmd/restic/global.go b/cmd/restic/global.go index cd6a683bf..be485dc3b 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -43,6 +43,10 @@ import ( "golang.org/x/term" ) +// ErrNoRepository is used to report if opening a repsitory failed due +// to a missing backend storage location or config file +var ErrNoRepository = errors.New("repository does not exist") + var version = "0.16.5-dev (compiled manually)" // TimeFormat is the format used for all timestamps printed by restic. @@ -607,6 +611,9 @@ func innerOpen(ctx context.Context, s string, gopts GlobalOptions, opts options. be, err = factory.Open(ctx, cfg, rt, lim) } + if errors.Is(err, backend.ErrNoRepository) { + return nil, fmt.Errorf("Fatal: %w at %v: %v", ErrNoRepository, location.StripPassword(gopts.backends, s), err) + } if err != nil { return nil, errors.Fatalf("unable to open repository at %v: %v", location.StripPassword(gopts.backends, s), err) } @@ -635,6 +642,9 @@ func open(ctx context.Context, s string, gopts GlobalOptions, opts options.Optio // check if config is there fi, err := be.Stat(ctx, backend.Handle{Type: restic.ConfigFile}) + if be.IsNotExist(err) { + return nil, fmt.Errorf("Fatal: %w: unable to open config file: %v\nIs there a repository at the following location?\n%v", ErrNoRepository, err, location.StripPassword(gopts.backends, s)) + } if err != nil { return nil, errors.Fatalf("unable to open config file: %v\nIs there a repository at the following location?\n%v", err, location.StripPassword(gopts.backends, s)) } diff --git a/cmd/restic/main.go b/cmd/restic/main.go index c61ce6cf3..5818221a5 100644 --- a/cmd/restic/main.go +++ b/cmd/restic/main.go @@ -156,6 +156,8 @@ func main() { exitCode = 0 case err == ErrInvalidSourceData: exitCode = 3 + case errors.Is(err, ErrNoRepository): + exitCode = 10 case restic.IsAlreadyLocked(err): exitCode = 11 case errors.Is(err, context.Canceled): diff --git a/internal/backend/b2/b2.go b/internal/backend/b2/b2.go index 1a5e72aaa..9717cdd0e 100644 --- a/internal/backend/b2/b2.go +++ b/internal/backend/b2/b2.go @@ -100,7 +100,9 @@ func Open(ctx context.Context, cfg Config, rt http.RoundTripper) (backend.Backen } bucket, err := client.Bucket(ctx, cfg.Bucket) - if err != nil { + if b2.IsNotExist(err) { + return nil, backend.ErrNoRepository + } else if err != nil { return nil, errors.Wrap(err, "Bucket") } diff --git a/internal/backend/backend.go b/internal/backend/backend.go index 3b0599c30..f606e1123 100644 --- a/internal/backend/backend.go +++ b/internal/backend/backend.go @@ -2,10 +2,13 @@ package backend import ( "context" + "fmt" "hash" "io" ) +var ErrNoRepository = fmt.Errorf("repository does not exist") + // Backend is used to store and access data. // // Backend operations that return an error will be retried when a Backend is