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

Closed
rehanone opened this issue Oct 9, 2023 · 6 comments · Fixed by #1218
Closed

Per source hooks in the config file #902

rehanone opened this issue Oct 9, 2023 · 6 comments · Fixed by #1218
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
Milestone

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

@rdelaage
Copy link

Hello I would also be very interested in for that feature. I also suggested hooks for other actions in autorestic (cupcakearmy/autorestic#213) such as backup restore or checking for example.

@aawsome
Copy link
Member

aawsome commented Aug 31, 2024

We have a WIP-PR for this: #1218
Feel free to add any input to the discussion there - or try it out!

@simonsan simonsan added this to the NEXT milestone Sep 24, 2024
github-merge-queue bot pushed a commit that referenced this issue Oct 5, 2024
This PR adds `run-before`, `run-after`, `run-failure` and `run-finally`
hooks for:
- all commands in the `[global.hooks]` config profile section
- commands accessing the repository in the `[repository.hooks]` config
profile section
- the `backup` command specifically in the `[backup.hooks]` config
profile section
- specific backup sources in the `[backup.snapshots.hooks]` section

Note: This PR includes only calling the given commands. If there is the
wish for supplying information to the commands (env variables or
parameter substitution), this should be covered by a separate feature
request/PR.

closes #902

---------

Signed-off-by: simonsan <[email protected]>
Co-authored-by: simonsan <[email protected]>
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

Successfully merging a pull request may close this issue.

5 participants