mirror of
https://github.com/restic/restic.git
synced 2025-08-23 01:07:36 +00:00
Merge pull request #5322 from zmanda/fix-gh-5233-forget-failure-exit-codes
forget: return exit code 3 on partial removal of snapshots
This commit is contained in:
8
changelog/unreleased/issue-5233
Normal file
8
changelog/unreleased/issue-5233
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
Bugfix: forget command returns exit code 3 on partial removal of snapshots
|
||||||
|
|
||||||
|
The `forget` command now returns exit code 3 when it fails to remove one or
|
||||||
|
more snapshots. Previously, it returned exit code 0, which could lead to
|
||||||
|
confusion if the command was used in a script.
|
||||||
|
|
||||||
|
https://github.com/restic/restic/issues/5233
|
||||||
|
https://github.com/restic/restic/pull/5322
|
@@ -41,6 +41,7 @@ EXIT STATUS
|
|||||||
|
|
||||||
Exit status is 0 if the command was successful.
|
Exit status is 0 if the command was successful.
|
||||||
Exit status is 1 if there was any error.
|
Exit status is 1 if there was any error.
|
||||||
|
Exit status is 3 if there was an error removing one or more snapshots.
|
||||||
Exit status is 10 if the repository does not exist.
|
Exit status is 10 if the repository does not exist.
|
||||||
Exit status is 11 if the repository is already locked.
|
Exit status is 11 if the repository is already locked.
|
||||||
Exit status is 12 if the password is incorrect.
|
Exit status is 12 if the password is incorrect.
|
||||||
@@ -62,6 +63,7 @@ Exit status is 12 if the password is incorrect.
|
|||||||
type ForgetPolicyCount int
|
type ForgetPolicyCount int
|
||||||
|
|
||||||
var ErrNegativePolicyCount = errors.New("negative values not allowed, use 'unlimited' instead")
|
var ErrNegativePolicyCount = errors.New("negative values not allowed, use 'unlimited' instead")
|
||||||
|
var ErrFailedToRemoveOneOrMoreSnapshots = errors.New("failed to remove one or more snapshots")
|
||||||
|
|
||||||
func (c *ForgetPolicyCount) Set(s string) error {
|
func (c *ForgetPolicyCount) Set(s string) error {
|
||||||
switch s {
|
switch s {
|
||||||
@@ -305,12 +307,15 @@ func runForget(ctx context.Context, opts ForgetOptions, pruneOptions PruneOption
|
|||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// these are the snapshots that failed to be removed
|
||||||
|
failedSnIDs := restic.NewIDSet()
|
||||||
if len(removeSnIDs) > 0 {
|
if len(removeSnIDs) > 0 {
|
||||||
if !opts.DryRun {
|
if !opts.DryRun {
|
||||||
bar := printer.NewCounter("files deleted")
|
bar := printer.NewCounter("files deleted")
|
||||||
err := restic.ParallelRemove(ctx, repo, removeSnIDs, restic.WriteableSnapshotFile, func(id restic.ID, err error) error {
|
err := restic.ParallelRemove(ctx, repo, removeSnIDs, restic.WriteableSnapshotFile, func(id restic.ID, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printer.E("unable to remove %v/%v from the repository\n", restic.SnapshotFile, id)
|
printer.E("unable to remove %v/%v from the repository\n", restic.SnapshotFile, id)
|
||||||
|
failedSnIDs.Insert(id)
|
||||||
} else {
|
} else {
|
||||||
printer.VV("removed %v/%v\n", restic.SnapshotFile, id)
|
printer.VV("removed %v/%v\n", restic.SnapshotFile, id)
|
||||||
}
|
}
|
||||||
@@ -332,6 +337,10 @@ func runForget(ctx context.Context, opts ForgetOptions, pruneOptions PruneOption
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(failedSnIDs) > 0 {
|
||||||
|
return ErrFailedToRemoveOneOrMoreSnapshots
|
||||||
|
}
|
||||||
|
|
||||||
if len(removeSnIDs) > 0 && opts.Prune {
|
if len(removeSnIDs) > 0 && opts.Prune {
|
||||||
if opts.DryRun {
|
if opts.DryRun {
|
||||||
printer.P("%d snapshots would be removed, running prune dry run\n", len(removeSnIDs))
|
printer.P("%d snapshots would be removed, running prune dry run\n", len(removeSnIDs))
|
||||||
|
@@ -206,6 +206,8 @@ func main() {
|
|||||||
exitCode = 0
|
exitCode = 0
|
||||||
case err == ErrInvalidSourceData:
|
case err == ErrInvalidSourceData:
|
||||||
exitCode = 3
|
exitCode = 3
|
||||||
|
case errors.Is(err, ErrFailedToRemoveOneOrMoreSnapshots):
|
||||||
|
exitCode = 3
|
||||||
case errors.Is(err, ErrNoRepository):
|
case errors.Is(err, ErrNoRepository):
|
||||||
exitCode = 10
|
exitCode = 10
|
||||||
case restic.IsAlreadyLocked(err):
|
case restic.IsAlreadyLocked(err):
|
||||||
|
Reference in New Issue
Block a user