-
Notifications
You must be signed in to change notification settings - Fork 30
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
Question: How to calculate a value in before-run
which is available afterwards for the restic commands
#299
Comments
After more research, I doubt that things in the configuration can be dynamically calculated at all if not possible via the built-in mechanisms that the templates provide. So I came up with a workaround. I use In case anyone else should be interested, Here is how I implemented the workaround:
And the script
|
I do like this idea of using an environment variable inside any configuration value: read-data-daily:
inherit: read-data-daily-1
env:
EXAMPLE_PORTION: "100"
run-before:
# Is correctly expanded at runtime
- "echo \"Portion: $EXAMPLE_PORTION\""
check:
# introducing new feature to make it work
read-data-subset: ${EXAMPLE_PORTION}/255
schedule:
- 'daily' that would simplify a lot of the pain of using template variables, which can only be referenced during the compilation of the configuration anyway. Now we need to extract the environment variables that were set during a command. What if we wrap up any command inside a tiny shell script, like: [command goes here, any `run-before`, `run-after` or calling `restic`]
# grab the exit code
exitCode = $?
# save environment variables
env > output_env.tmp
# return the exit code from the command
exit $exitCode This way we can save the environment variables that have been set by the command. What do you think @jkellerer ? |
I am having a hard time, getting my head around how the environment is available during resticprofile runs and how I can manipulate it to inject values to variables which I need to be present during restic execution (or at parsing time)
Ultimately the Problem to solve is that I want to have a
check
profile which does aread-data-subset: n/m
wherem
is some value that can be static butn
should count upwards based on the day of year and be reset to1
when it reachesm
.I first built some complicated things with multiple profiles that make use of
{{ (.Now.AddDate 0 0 -(m-1)).YearDay }}
scheduling it with multipleOnCalendar
-directives (Which kinda worked), but that requires a lot of code duplication which I am apparently not able (given my current knowledge) to deduplicate using the template language and ends up in for example at least 7 profile entries ifm
happens to be50
. Also to deal with the leap year is really complicated and makes everything even messier.So I can easily calculate the value of
n
externally using a script or binary. I only need to have that value present for accessing it in theread-data-subset:
call.I am not able to even simulate it by hardcoding an
env:
variable. At the actual check command line, it is always empty.I am a bit lost at this point. Any Ideas how to proceed?
P.S.:
This was the complicated approach which kinda works, I described above:
And this was an approach where I experimented with a hardcoded
env:
config, which did not expand the variable on the actual check execution:The text was updated successfully, but these errors were encountered: