-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Backup flag to execute commands with restic, read content from standard input and consider return status #4251
Description
Output of restic version
restic 0.15.1 compiled with go1.20 on linux/amd64
What should restic do differently? Which functionality do you think we should add?
When using restic backup command with a Pipe and --stdin flag, restic is not able to detect when other processes together in the Pipe exit unexpected. As result restic creates valid snapshots whether other processes in the pipe are successful or not.
As discussed in the forum thread Failed database dump results in valid snapshot the feature proposal is to implement a borg like --stdin-from-command flag. With this flag restic should be able to execute commands directly, read the stdin output, monitor their return code and decide whether a snapshot is to be created or not.
My expectation is that the following things will be taken into account when restic is handling additional commands to read from stdin:
- exit code is handled and is part of the decision whether to create a snapshot or not
- environment variables are also visible to the additional command
- the difference between normale Pipes and the new flag is described in the documentation
- possible safety concerns when executing commands directly with restic have been considered (Are there any?)
What are you trying to do? What problem would this solve?
To create database backups I use mysql/pgdump commands and restic in stdin mode, running in a bash script with set -e and set -o pipefail. In some situations the databases dumps fail but restic still result in a valid snapshot.
Minimal reproducer:
$ pg_dump -h foobar 2>&1; echo $?
pg_dump: error: could not translate host name "foobar" to address: No address associated with hostname
1
$ pg_dump -h foobar 2>&1 | restic -p tmp/password -r tmp/restic_repo backup --stdin --stdin-filename dump.sql
repository b7cd6922 opened (version 2, compression level auto)
Files: 1 new, 0 changed, 0 unmodified
Dirs: 0 new, 0 changed, 0 unmodified
Added to the repository: 410 B (422 B stored)
processed 1 files, 103 B in 0:00
snapshot 7635bd5b saved
(redirecting stderr to stdout for demonstration purposes only)
Did restic help you today? Did it make you happy in any way?
I've been using restic for years and it saved my ass several times or at least saved me a lot of time. Not just because it's fast and efficient, but also because it's so easy to use and has an intuitive and not bloated user interface with very helpful documentation and messages.