2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 02:48:55 +00:00

Start command from --stdin-from-command

It acts similar to --stdin but reads its data from the stdout of the given command instead of os.Stdin.

Signed-off-by: Sebastian Hoß <seb@xn--ho-hia.de>
This commit is contained in:
Sebastian Hoß 2023-03-16 08:11:49 +01:00 committed by Michael Eischer
parent 333fe1c3cf
commit a2b76ff34f

View File

@ -7,6 +7,7 @@ import (
"fmt"
"io"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
@ -594,16 +595,37 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter
defer localVss.DeleteSnapshots()
targetFS = localVss
}
if opts.Stdin {
var command *exec.Cmd
var stderr io.ReadCloser
if opts.Stdin || opts.StdinCommand {
if !gopts.JSON {
progressPrinter.V("read data from stdin")
}
filename := path.Join("/", opts.StdinFilename)
var closer io.ReadCloser
if opts.StdinCommand {
command = exec.CommandContext(ctx, args[0], args[1:]...)
stdout, err := command.StdoutPipe()
if err != nil {
return err
}
stderr, err = command.StderrPipe()
if err != nil {
return err
}
if err := command.Start(); err != nil {
return err
}
closer = stdout
} else {
closer = os.Stdin
}
targetFS = &fs.Reader{
ModTime: timeStamp,
Name: filename,
Mode: 0644,
ReadCloser: os.Stdin,
ReadCloser: closer,
}
targets = []string{filename}
}