Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per source hooks in the config file #902

Open
rehanone opened this issue Oct 9, 2023 · 4 comments
Open

Per source hooks in the config file #902

rehanone opened this issue Oct 9, 2023 · 4 comments
Labels
A-cli Area: `rustic` command line interface A-config Area: Related to the config file functionality and format A-examples Area: Related to examples C-enhancement Category: New feature or request E-help-wanted Call for participation: Help is requested to fix this issue

Comments

@rehanone
Copy link

rehanone commented Oct 9, 2023

Thanks a lot for creating wonderful alternative to the amazing restic program. I have been watching the progress of your project for a while and waiting for the right moment to jump on. We a few things have happened that cause me to seriously take a look at this project. I have been looking to restore a very old snapshot in restic and found the lack of any description very challenging in figuring out the right snapshot to pick. So the fact that this one has that ability is great incentive going forward. However I am using a wrapper for restic called autorestic which has the ability to call scripts/programs per source/location as hooks. I use this ability extensively to gracefully bring down containers before backup and bring them back up after the backup is complete. There is a documentation available for this feature here. There are 4 hooks supported:

  • before
  • after
  • failure
  • success

These hooks are per source. But I think there might be some value in having hooks that are called per repo as well.

@github-actions github-actions bot added the S-triage Status: Waiting for a maintainer to triage this issue/PR label Oct 9, 2023
@aawsome
Copy link
Member

aawsome commented Oct 9, 2023

Thanks a lot @rehanone for your feature request!

I think this is quite a small enhancement which would only affect the rustic CLI and not rustic_core.

There are already several command which are called, see e.g. this config file - and the called hooks could just add to this list.

@aawsome aawsome added C-enhancement Category: New feature or request E-help-wanted Call for participation: Help is requested to fix this issue A-cli Area: `rustic` command line interface A-examples Area: Related to examples A-config Area: Related to the config file functionality and format and removed S-triage Status: Waiting for a maintainer to triage this issue/PR labels Oct 9, 2023
@rehanone
Copy link
Author

rehanone commented Oct 9, 2023

@aawsome , thanks for a very quick response. Yes I agree that is a very small change in the CLI only. It is already implemented on the repository level in post-create-command and post-create-command as you comment perhaps is alluding to.

@rehanone
Copy link
Author

rehanone commented Oct 9, 2023

@aawsome, I would also like to suggest that making each of these hooks to be a list of commands rather than a single command would be much better in terms of making it flexible. This would not be a big change in the design but allows for adding arbitrary number of commands to be executed against each hook.

@zxcat
Copy link
Contributor

zxcat commented Oct 12, 2023

+1. I am using restic+resticprofile wrapper and now trying to move to rustic.
There are run-before, run-after, run-after-fail and run-finally options in resticprofile, which I use from the 1st day. Each option can be a list of commands and also supports inheritance + env vars. E.g. you can define them on root level using env vars like run-before: 'echo "== run-before profile $PROFILE_NAME and command $PROFILE_COMMAND"' and then reuse on profile level or command level without any additional configuration.
For backup command I use something like

  run-finally:
    - 'grep -Ev "(^unchanged\\s|\(0 B added, 0 B stored\))" {{$logName}} > "…/logs/bkp-$PROFILE_NAME/$(date '+%Y-%m-%d_%H-%M-%S').log"'`
    - # notify command here

To filter and organize logs and notify if something important happened.

Note: $logName here is a go template variable, but that's a different story. To make hook commands flexible it's enough to set some env vars, containing flags passed to rustic and calculated from current config. Actually, I only used $PROFILE_NAME and paths (source/repo/log-path).

Note 2: resticprofile runs each command in a list separately, so

  run-after:
    - 'my_var=123'
    - 'echo $my_var'

outputs nothing. It may create some inconveniences, but seems more secure.


For reference: resticprofile hooks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Area: `rustic` command line interface A-config Area: Related to the config file functionality and format A-examples Area: Related to examples C-enhancement Category: New feature or request E-help-wanted Call for participation: Help is requested to fix this issue
Projects
None yet
Development

No branches or pull requests

3 participants