title: Constants eleventyNavigation: key: 🟰 Constants
New in version 1.7.10 borgmatic supports defining custom configuration constants. This is similar to the variable interpolation feature for command hooks, but the constants feature lets you substitute your own custom values into any option values in the entire configuration file.
Here's an example usage:
constants:
user: foo
archive_prefix: bar
source_directories:
- /home/{user}/.config
- /home/{user}/.ssh
...
archive_name_format: '{archive_prefix}-{now}'
Prior to version 1.8.0 Don't
forget to specify the section (like location: or storage:) that any option
is in.
In this example, when borgmatic runs, all instances of {user} get replaced
with foo and all instances of {archive_prefix} get replaced with bar.
And {now} doesn't get replaced with anything, but gets passed directly to
Borg, which has its own
placeholders
using the same syntax as borgmatic constants. So borgmatic options like
archive_name_format that get passed directly to Borg can use either Borg
placeholders or borgmatic constants or both!
After substitution, the logical result looks something like this:
source_directories:
- /home/foo/.config
- /home/foo/.ssh
...
archive_name_format: 'bar-{now}'
Note that if you'd like to interpolate a constant into the beginning of a value, you'll need to quote it. For instance, this won't work:
source_directories:
- {my_home_directory}/.config # This will error!
Instead, do this:
source_directories:
- "{my_home_directory}/.config"
New in version 1.8.5 Constants work across includes, meaning you can define a constant and then include a separate configuration file that uses that constant.
An alternate to constants is passing in your values via environment variables.