From 767c2539a0d573b9b4d7699ba9f28f9e28fb69ff Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 21 Jan 2024 22:06:54 +0100 Subject: [PATCH 1/2] backup: Improve help text for `--stdin-from-command` --- changelog/unreleased/issue-4251 | 9 +++++---- cmd/restic/cmd_backup.go | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/changelog/unreleased/issue-4251 b/changelog/unreleased/issue-4251 index 31be52401..5aeb50062 100644 --- a/changelog/unreleased/issue-4251 +++ b/changelog/unreleased/issue-4251 @@ -3,10 +3,11 @@ Enhancement: Support reading backup from a program's standard output When reading data from stdin, the `backup` command could not verify whether the corresponding command completed successfully. -The `backup` command now supports starting an arbitrary command and sourcing -the backup content from its standard output. This enables restic to verify that -the command completes with exit code zero. A non-zero exit code causes the -backup to fail. +The `backup` command now supports the `--stdin-from-command` option. When using +this option, the arguments to `backup` are interpreted as a command. `backup` +then executes the command and stores its standard output in the backup. This +enables restic to verify that the command completes with exit code zero. A +non-zero exit code causes the backup to fail. Example: `restic backup --stdin-from-command mysqldump [...]` diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index a2b81a759..be3de5f8e 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -135,7 +135,7 @@ func init() { f.StringVar(&backupOptions.ExcludeLargerThan, "exclude-larger-than", "", "max `size` of the files to be backed up (allowed suffixes: k/K, m/M, g/G, t/T)") f.BoolVar(&backupOptions.Stdin, "stdin", false, "read backup from stdin") f.StringVar(&backupOptions.StdinFilename, "stdin-filename", "stdin", "`filename` to use when reading from stdin") - f.BoolVar(&backupOptions.StdinCommand, "stdin-from-command", false, "execute command and store its stdout") + f.BoolVar(&backupOptions.StdinCommand, "stdin-from-command", false, "interpret arguments as command to execute and store its stdout") f.Var(&backupOptions.Tags, "tag", "add `tags` for the new snapshot in the format `tag[,tag,...]` (can be specified multiple times)") f.UintVar(&backupOptions.ReadConcurrency, "read-concurrency", 0, "read `n` files concurrently (default: $RESTIC_READ_CONCURRENCY or 2)") f.StringVarP(&backupOptions.Host, "host", "H", "", "set the `hostname` for the snapshot manually. To prevent an expensive rescan use the \"parent\" flag") From 6cc2bec5ddcd9bd2cec7dd825f4d3cb58b52d8b2 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Tue, 23 Jan 2024 19:09:04 +0100 Subject: [PATCH 2/2] apply suggestion from review --- changelog/unreleased/issue-4251 | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/changelog/unreleased/issue-4251 b/changelog/unreleased/issue-4251 index 5aeb50062..d1d3f4508 100644 --- a/changelog/unreleased/issue-4251 +++ b/changelog/unreleased/issue-4251 @@ -1,15 +1,16 @@ -Enhancement: Support reading backup from a program's standard output - -When reading data from stdin, the `backup` command could not verify whether the -corresponding command completed successfully. +Enhancement: Support reading backup from a commands's standard output The `backup` command now supports the `--stdin-from-command` option. When using -this option, the arguments to `backup` are interpreted as a command. `backup` -then executes the command and stores its standard output in the backup. This -enables restic to verify that the command completes with exit code zero. A -non-zero exit code causes the backup to fail. +this option, the arguments to `backup` are interpreted as a command instead of +paths to back up. `backup` then executes the given command and stores the +standard output from it in the backup, similar to the what the `--stdin` option +does. This also enables restic to verify that the command completes with exit +code zero. A non-zero exit code causes the backup to fail. -Example: `restic backup --stdin-from-command mysqldump [...]` +Note that the `--stdin` option does not have to be specified at the same time, +and that the `--stdin-filename` option also applies to `--stdin-from-command`. + +Example: `restic backup --stdin-from-command --stdin-filename dump.sql mysqldump [...]` https://github.com/restic/restic/issues/4251 https://github.com/restic/restic/pull/4410