Skip to content

backup: return exit code 3 if not all targets are available#5347

Merged
MichaelEischer merged 6 commits into
restic:masterfrom
zmanda:fix-gh-4467-backup-exits-with-0-on-file-not-exists
Oct 5, 2025
Merged

backup: return exit code 3 if not all targets are available#5347
MichaelEischer merged 6 commits into
restic:masterfrom
zmanda:fix-gh-4467-backup-exits-with-0-on-file-not-exists

Conversation

@konidev20

@konidev20 konidev20 commented Apr 5, 2025

Copy link
Copy Markdown
Contributor

What does this PR change? What problem does it solve?

Restic backup command will also exit with code 3 if any one of the targets selected for backup are inaccessible. Previously, the backup command would exit with code 3 only if a child directory or file was inaccessible.

I have modified the collectTargets function in the cmd_backup.go command to check if all the targets collected from command line args, --files-from, --files-from-verbatim and --files-from-raw are accessible. If any of the targets are inaccessible then, we return the ErrInvalidSourceData towards the end; this will result in a exit code 3 (partial snapshot)

Was the change previously discussed in an issue or on the forum?

Closes #4467

Checklist

  • I have added tests for all code changes.
  • I have added documentation for relevant changes (in the manual).
  • There's a new file in changelog/unreleased/ that describes the changes for our users (see template).
  • I'm done! This pull request is ready for review.

@konidev20 konidev20 force-pushed the fix-gh-4467-backup-exits-with-0-on-file-not-exists branch from 40cadc1 to d31d6ba Compare April 5, 2025 19:25
@konidev20 konidev20 marked this pull request as draft April 5, 2025 19:35
@konidev20 konidev20 force-pushed the fix-gh-4467-backup-exits-with-0-on-file-not-exists branch from 03d4992 to 6f5d1e6 Compare April 5, 2025 19:37
@konidev20 konidev20 marked this pull request as ready for review April 6, 2025 12:06
@konidev20 konidev20 force-pushed the fix-gh-4467-backup-exits-with-0-on-file-not-exists branch from cabe397 to 06ce995 Compare April 6, 2025 18:21
@konidev20 konidev20 force-pushed the fix-gh-4467-backup-exits-with-0-on-file-not-exists branch from 06ce995 to 72e2aa7 Compare June 3, 2025 19:15
@konidev20

Copy link
Copy Markdown
Contributor Author

Hi @MichaelEischer, bubbling this PR up since I see you are reviewing some PRs.

@konidev20 konidev20 force-pushed the fix-gh-4467-backup-exits-with-0-on-file-not-exists branch from 72e2aa7 to 2342a1c Compare September 13, 2025 18:02
@konidev20 konidev20 force-pushed the fix-gh-4467-backup-exits-with-0-on-file-not-exists branch from 2342a1c to 6a3ab69 Compare September 27, 2025 08:17

@MichaelEischer MichaelEischer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, see below for comments and sorry for yet another merge conflict 🙈 .

Comment thread cmd/restic/cmd_backup.go Outdated
Comment thread changelog/unreleased/issue-4467 Outdated
* to make the exit code behaviour consistent with files inaccessible during the backup phase, making this change to exit with code 3 if not all target files/folders are accessible for backup

resticgh-4467

backup: add changelog entry for resticgh-4467

bugfix: backup fails completely when one target is inaccessible

chore: remove unnecessary err=nil

tests: fix integration tests for non-existing file

tests: update cmd_backup_test.go

tests: fix backup tests and merge conflicts
@konidev20 konidev20 force-pushed the fix-gh-4467-backup-exits-with-0-on-file-not-exists branch from 6a3ab69 to 805dcb3 Compare October 5, 2025 06:57

@MichaelEischer MichaelEischer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR in its current form is completely broken, see comments and suggestions below.

Comment thread changelog/unreleased/issue-4467 Outdated
Comment thread changelog/unreleased/issue-4467 Outdated
Comment thread cmd/restic/cmd_backup.go
Comment thread cmd/restic/cmd_backup.go Outdated
Comment thread cmd/restic/cmd_backup.go Outdated
Comment thread cmd/restic/cmd_backup.go
Comment thread cmd/restic/cmd_backup_integration_test.go Outdated
Comment thread cmd/restic/cmd_backup_integration_test.go
Comment thread cmd/restic/cmd_backup_test.go
konidev20 and others added 4 commits October 5, 2025 18:03
Co-authored-by: Michael Eischer <michael.eischer@gmx.de>
Co-authored-by: Michael Eischer <michael.eischer@gmx.de>
Co-authored-by: Michael Eischer <michael.eischer@gmx.de>

@MichaelEischer MichaelEischer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@MichaelEischer MichaelEischer merged commit 481fcb9 into restic:master Oct 5, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exit code 0 instead of 3 when directory given by --files-from is not readable

2 participants