2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-23 19:38:57 +00:00

return exit code 10 if repository does not exist

This commit is contained in:
Michael Eischer 2024-07-10 21:46:26 +02:00
parent d76a78aa99
commit 94fdca08c4
32 changed files with 46 additions and 1 deletions

View File

@ -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) {

View File

@ -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,

View File

@ -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,

View File

@ -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 {

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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))
}

View File

@ -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):

View File

@ -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")
}

View File

@ -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