add --stdin-from-command flag to backup command#4410
add --stdin-from-command flag to backup command#4410MichaelEischer merged 17 commits intorestic:masterfrom
Conversation
|
I rebased the code to the latest |
44f4ffb to
7135980
Compare
|
Is there other software that has this option name ( |
Actually, |
|
Nah, there's already two |
7135980 to
f8fe0c6
Compare
|
@MichaelEischer I've implemented your suggestions from the old pull request. I implemented a new I'm testing the code now :-) |
|
Thank you for continuing with this feature. I tested your branch and it still creates snapshots when subcommand exists with non zero: |
Uh, I was about to do the same test :-D Thanks for your report, I'll investigate and fix 👍 |
|
The problem was that the error returned in file reading or closing was logged, but the snapshot itself was continuing unaffected (because the logic assumed that an error while reading one file should not abort the snapshot). The What do you think? |
I'm not sure about the I like your current implementation more, because having a snapshot with no data makes no sense for me. But it might be behaving differently than we have in existing implementations. |
You are right, it is a different behavior. I assumed that this is expected, given that we are explicitly asking for monitoring the command. On second thought, the best way is to check the command exit code also in I'll modify the code asap :-) |
|
Ok, now the code should stop the snapshot creation by looking only at the exit code. If there is no output, the snapshot is still created with a warning (and exit code 3), which is the same behavior that other snapshot options have ( |
|
Works for me. Very good! I think there should now be some feedback on the code itself. |
Agreed, thanks for feedbacks and tests :-) |
fb2a9f9 to
569234f
Compare
|
I rebased the branch to the latest |
87bae0d to
a7c1cae
Compare
|
@Enrico204 Thanks for finishing the PR, and sorry for the late feedback. I've somehow missed that the review comments have been addressed in the meantime. I've reworked the code a bit: the command startup is now handled by |
|
No problem at all :-) I will compile this branch and I will test it as soon as possible! |
a7c1cae to
2053832
Compare
|
I am testing the code since a few weeks: so far, no issues :-) |
This new flag is added to the backup subcommand in order to allow restic to control the execution of a command and determine whether to save a snapshot if the given command succeeds. Signed-off-by: Sebastian Hoß <seb@xn--ho-hia.de>
In order to run with --stdin-from-command we need to short-circuit some functions similar to how it is handled for the --stdin flag. The only difference here is that --stdin-from-command actually expects that len(args) should be greater 0 whereas --stdin does not expect any args at all. Signed-off-by: Sebastian Hoß <seb@xn--ho-hia.de>
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>
In order to determine whether to save a snapshot, we need to capture the exit code returned by a command. In order to provide a nice error message, we supply stderr as well. Signed-off-by: Sebastian Hoß <seb@xn--ho-hia.de>
Return with an error containing the stderr of the given command in case it fails. No new snapshot will be created and future prune operations on the repository will remove the unreferenced data. Signed-off-by: Sebastian Hoß <seb@xn--ho-hia.de>
The code has been refactored so that the archiver is back to the original code, and the stderr is handled using a go routine to avoid deadlock.
…de 0 from command The behavior of the new option should reflect the behavior of normal backups: when the command exit code is zero and there is no output in the stdout, emit a warning but create the snapshot. This commit fixes the integration tests and the ReadCloserCommand struct.
2053832 to
be28a02
Compare
MichaelEischer
left a comment
There was a problem hiding this comment.
LGTM. Thanks for your work on the PR!
I've rebased the commits one more time before merging it.
Add module support for --stdin-from-command flag, which was added to restic in restic/restic#4410. I also made a few very small changes here and there in the nix code to make it look a little neater in my opinion. I could potentially add support for the --stdin flag too, but this would require prepending the restic command with an external command and a pipe, which seems a bit messy - and the restic documentation says to prefer --stdin-from-command over --stdin anyway. I could add an option for --stdin-filename, but I feel that this would be better for users to do in extraBackupArgs.
What does this PR change? What problem does it solve?
This pull request is a continuation of #4254.
This fixes #4251 by providing the requested
--stdin-from-commandflag to therestic backupcommand. It skips snapshot creation in case the given commands fails as determined byexec.Cmd.Wait()and returns the stderr of the given command as an error message back to the user.I have not written any tests, nor documentation because I wanted to get some feedback about the path taken here wrt. upstream inclusion first. I am seeing various test failures in existing tests but these seem to be unrelated and might just occur because I'm building/testing the project within a container. Using these changes locally does look promising though:
Was the change previously discussed in an issue or on the forum?
Closes #4251
Checklist
changelog/unreleased/that describes the changes for our users (see template).gofmton the code in all commits.