2019-02-04 07:20:59 +01:00
|
|
|
---
|
|
|
|
title: How to make per-application backups
|
2020-08-21 23:27:47 +02:00
|
|
|
eleventyNavigation:
|
2022-05-20 20:11:35 +02:00
|
|
|
key: 🔀 Make per-application backups
|
2020-08-21 23:27:47 +02:00
|
|
|
parent: How-to guides
|
|
|
|
order: 1
|
2019-02-04 07:20:59 +01:00
|
|
|
---
|
|
|
|
## Multiple backup configurations
|
|
|
|
|
|
|
|
You may find yourself wanting to create different backup policies for
|
2022-08-22 06:48:37 +02:00
|
|
|
different applications on your system or even for different backup
|
|
|
|
repositories. For instance, you might want one backup configuration for your
|
|
|
|
database data directory and a different configuration for your user home
|
|
|
|
directories. Or one backup configuration for your local backups with a
|
|
|
|
different configuration for your remote repository.
|
2019-02-04 07:20:59 +01:00
|
|
|
|
|
|
|
The way to accomplish that is pretty simple: Create multiple separate
|
|
|
|
configuration files and place each one in a `/etc/borgmatic.d/` directory. For
|
2022-08-22 06:48:37 +02:00
|
|
|
instance, for applications:
|
2019-02-04 07:20:59 +01:00
|
|
|
|
|
|
|
```bash
|
|
|
|
sudo mkdir /etc/borgmatic.d
|
2023-06-21 21:19:49 +02:00
|
|
|
sudo borgmatic config generate --destination /etc/borgmatic.d/app1.yaml
|
|
|
|
sudo borgmatic config generate --destination /etc/borgmatic.d/app2.yaml
|
2019-02-04 07:20:59 +01:00
|
|
|
```
|
|
|
|
|
2022-08-22 06:48:37 +02:00
|
|
|
Or, for repositories:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
sudo mkdir /etc/borgmatic.d
|
2023-06-21 21:19:49 +02:00
|
|
|
sudo borgmatic config generate --destination /etc/borgmatic.d/repo1.yaml
|
|
|
|
sudo borgmatic config generate --destination /etc/borgmatic.d/repo2.yaml
|
2022-08-22 06:48:37 +02:00
|
|
|
```
|
|
|
|
|
2023-06-21 21:19:49 +02:00
|
|
|
<span class="minilink minilink-addedin">Prior to version 1.7.15</span> The
|
2023-06-21 22:14:54 +02:00
|
|
|
command to generate configuration files was `generate-borgmatic-config`
|
|
|
|
instead of `borgmatic config generate`.
|
2023-06-21 21:19:49 +02:00
|
|
|
|
2019-02-04 07:20:59 +01:00
|
|
|
When you set up multiple configuration files like this, borgmatic will run
|
|
|
|
each one in turn from a single borgmatic invocation. This includes, by
|
|
|
|
default, the traditional `/etc/borgmatic/config.yaml` as well.
|
|
|
|
|
2019-12-13 20:42:17 +01:00
|
|
|
Each configuration file is interpreted independently, as if you ran borgmatic
|
|
|
|
for each configuration file one at a time. In other words, borgmatic does not
|
|
|
|
perform any merging of configuration files by default. If you'd like borgmatic
|
2022-08-22 06:48:37 +02:00
|
|
|
to merge your configuration files, for instance to avoid duplication of
|
|
|
|
settings, see below about configuration includes.
|
2019-12-13 20:42:17 +01:00
|
|
|
|
2020-01-22 18:26:58 +01:00
|
|
|
Additionally, the `~/.config/borgmatic.d/` directory works the same way as
|
2022-04-28 20:16:31 +02:00
|
|
|
`/etc/borgmatic.d`.
|
|
|
|
|
|
|
|
If you need even more customizability, you can specify alternate configuration
|
|
|
|
paths on the command-line with borgmatic's `--config` flag. (See `borgmatic
|
|
|
|
--help` for more information.) For instance, if you want to schedule your
|
|
|
|
various borgmatic backups to run at different times, you'll need multiple
|
|
|
|
entries in your [scheduling software of
|
|
|
|
choice](https://torsion.org/borgmatic/docs/how-to/set-up-backups/#autopilot),
|
|
|
|
each entry using borgmatic's `--config` flag instead of relying on
|
|
|
|
`/etc/borgmatic.d`.
|
2019-02-04 07:20:59 +01:00
|
|
|
|
2023-04-01 00:21:08 +02:00
|
|
|
|
|
|
|
## Archive naming
|
|
|
|
|
|
|
|
If you've got multiple borgmatic configuration files, you might want to create
|
|
|
|
archives with different naming schemes for each one. This is especially handy
|
|
|
|
if each configuration file is backing up to the same Borg repository but you
|
|
|
|
still want to be able to distinguish backup archives for one application from
|
|
|
|
another.
|
|
|
|
|
|
|
|
borgmatic supports this use case with an `archive_name_format` option. The
|
|
|
|
idea is that you define a string format containing a number of [Borg
|
|
|
|
placeholders](https://borgbackup.readthedocs.io/en/stable/usage/help.html#borg-placeholders),
|
|
|
|
and borgmatic uses that format to name any new archive it creates. For
|
|
|
|
instance:
|
|
|
|
|
|
|
|
```yaml
|
2023-07-12 04:42:14 +02:00
|
|
|
archive_name_format: home-directories-{now}
|
2023-04-01 00:21:08 +02:00
|
|
|
```
|
|
|
|
|
2023-07-12 04:42:14 +02:00
|
|
|
<span class="minilink minilink-addedin">Prior to version 1.8.0</span> Put
|
|
|
|
this option in the `storage:` section of your configuration.
|
|
|
|
|
|
|
|
This example means that when borgmatic creates an archive, its name will start
|
|
|
|
with the string `home-directories-` and end with a timestamp for its creation
|
|
|
|
time. If `archive_name_format` is unspecified, the default is
|
2023-04-01 00:21:08 +02:00
|
|
|
`{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}`, meaning your system hostname plus a
|
|
|
|
timestamp in a particular format.
|
|
|
|
|
2023-05-16 08:17:45 +02:00
|
|
|
|
2023-05-16 08:25:13 +02:00
|
|
|
### Archive filtering
|
2023-05-16 08:17:45 +02:00
|
|
|
|
2023-04-01 00:21:08 +02:00
|
|
|
<span class="minilink minilink-addedin">New in version 1.7.11</span> borgmatic
|
|
|
|
uses the `archive_name_format` option to automatically limit which archives
|
|
|
|
get used for actions operating on multiple archives. This prevents, for
|
|
|
|
instance, duplicate archives from showing up in `rlist` or `info` results—even
|
|
|
|
if the same repository appears in multiple borgmatic configuration files. To
|
2023-04-20 23:28:04 +02:00
|
|
|
take advantage of this feature, use a different `archive_name_format` in each
|
|
|
|
configuration file.
|
2023-04-01 00:21:08 +02:00
|
|
|
|
|
|
|
Under the hood, borgmatic accomplishes this by substituting globs for certain
|
|
|
|
ephemeral data placeholders in your `archive_name_format`—and using the result
|
2023-04-01 00:36:59 +02:00
|
|
|
to filter archives when running supported actions.
|
2023-04-01 00:21:08 +02:00
|
|
|
|
|
|
|
For instance, let's say that you have this in your configuration:
|
|
|
|
|
|
|
|
```yaml
|
2023-07-12 07:10:57 +02:00
|
|
|
archive_name_format: {hostname}-user-data-{now}
|
2023-04-01 00:21:08 +02:00
|
|
|
```
|
|
|
|
|
2023-07-12 07:10:57 +02:00
|
|
|
<span class="minilink minilink-addedin">Prior to version 1.8.0</span> Put
|
|
|
|
this option in the `storage:` section of your configuration.
|
|
|
|
|
2023-04-01 00:36:59 +02:00
|
|
|
borgmatic considers `{now}` an emphemeral data placeholder that will probably
|
2023-04-01 00:21:08 +02:00
|
|
|
change per archive, while `{hostname}` won't. So it turns the example value
|
|
|
|
into `{hostname}-user-data-*` and applies it to filter down the set of
|
|
|
|
archives used for actions like `rlist`, `info`, `prune`, `check`, etc.
|
|
|
|
|
|
|
|
The end result is that when borgmatic runs the actions for a particular
|
|
|
|
application-specific configuration file, it only operates on the archives
|
2023-04-20 23:28:04 +02:00
|
|
|
created for that application. But this doesn't apply to actions like `compact`
|
|
|
|
that operate on an entire repository.
|
2023-04-01 00:21:08 +02:00
|
|
|
|
2023-04-02 08:57:55 +02:00
|
|
|
If this behavior isn't quite smart enough for your needs, you can use the
|
|
|
|
`match_archives` option to override the pattern that borgmatic uses for
|
|
|
|
filtering archives. For example:
|
|
|
|
|
|
|
|
```yaml
|
2023-07-12 07:10:57 +02:00
|
|
|
archive_name_format: {hostname}-user-data-{now}
|
|
|
|
match_archives: sh:myhost-user-data-*
|
2023-04-02 08:57:55 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
For Borg 1.x, use a shell pattern for the `match_archives` value and see the
|
|
|
|
[Borg patterns
|
|
|
|
documentation](https://borgbackup.readthedocs.io/en/stable/usage/help.html#borg-help-patterns)
|
|
|
|
for more information. For Borg 2.x, see the [match archives
|
|
|
|
documentation](https://borgbackup.readthedocs.io/en/2.0.0b5/usage/help.html#borg-help-match-archives).
|
|
|
|
|
2023-04-05 06:25:10 +02:00
|
|
|
Some borgmatic command-line actions also have a `--match-archives` flag that
|
|
|
|
overrides both the auto-matching behavior and the `match_archives`
|
|
|
|
configuration option.
|
|
|
|
|
2023-04-01 00:21:08 +02:00
|
|
|
<span class="minilink minilink-addedin">Prior to 1.7.11</span> The way to
|
2023-04-01 00:36:59 +02:00
|
|
|
limit the archives used for the `prune` action was a `prefix` option in the
|
|
|
|
`retention` section for matching against the start of archive names. And the
|
|
|
|
option for limiting the archives used for the `check` action was a separate
|
|
|
|
`prefix` in the `consistency` section. Both of these options are deprecated in
|
2023-04-05 06:25:10 +02:00
|
|
|
favor of the auto-matching behavior (or `match_archives`/`--match-archives`)
|
|
|
|
in newer versions of borgmatic.
|
2023-04-01 00:21:08 +02:00
|
|
|
|
|
|
|
|
2019-03-06 21:06:27 +01:00
|
|
|
## Configuration includes
|
|
|
|
|
|
|
|
Once you have multiple different configuration files, you might want to share
|
|
|
|
common configuration options across these files with having to copy and paste
|
|
|
|
them. To achieve this, you can put fragments of common configuration options
|
|
|
|
into a file, and then include or inline that file into one or more borgmatic
|
|
|
|
configuration files.
|
|
|
|
|
2023-07-12 04:42:14 +02:00
|
|
|
Let's say that you want to include common consistency check configuration across all
|
2019-03-06 21:06:27 +01:00
|
|
|
of your configuration files. You could do that in each configuration file with
|
|
|
|
the following:
|
|
|
|
|
|
|
|
```yaml
|
2023-07-12 04:42:14 +02:00
|
|
|
repositories:
|
|
|
|
- path: repo.borg
|
2019-03-06 21:06:27 +01:00
|
|
|
|
2023-07-12 04:42:14 +02:00
|
|
|
checks:
|
|
|
|
!include /etc/borgmatic/common_checks.yaml
|
2019-03-06 21:06:27 +01:00
|
|
|
```
|
|
|
|
|
2023-07-12 04:42:14 +02:00
|
|
|
<span class="minilink minilink-addedin">Prior to version 1.8.0</span> These
|
|
|
|
options were organized into sections like `location:` and `consistency:`.
|
|
|
|
|
|
|
|
The contents of `common_checks.yaml` could be:
|
2019-03-06 21:06:27 +01:00
|
|
|
|
|
|
|
```yaml
|
2023-07-12 04:42:14 +02:00
|
|
|
- name: repository
|
|
|
|
frequency: 3 weeks
|
|
|
|
- name: archives
|
|
|
|
frequency: 2 weeks
|
2019-03-06 21:06:27 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
To prevent borgmatic from trying to load these configuration fragments by
|
|
|
|
themselves and complaining that they are not valid configuration files, you
|
|
|
|
should put them in a directory other than `/etc/borgmatic.d/`. (A subdirectory
|
|
|
|
is fine.)
|
|
|
|
|
2022-05-20 02:15:05 +02:00
|
|
|
When a configuration include is a relative path, borgmatic loads it from either
|
|
|
|
the current working directory or from the directory containing the file doing
|
|
|
|
the including.
|
|
|
|
|
2023-07-12 07:10:57 +02:00
|
|
|
Note that this form of include must be a value rather than an option name. For
|
2019-03-06 21:06:27 +01:00
|
|
|
example, this will not work:
|
|
|
|
|
|
|
|
```yaml
|
2023-07-12 04:42:14 +02:00
|
|
|
repositories:
|
|
|
|
- path: repo.borg
|
2019-03-06 21:06:27 +01:00
|
|
|
|
|
|
|
# Don't do this. It won't work!
|
2023-07-12 04:42:14 +02:00
|
|
|
!include /etc/borgmatic/common_checks.yaml
|
2019-03-06 21:06:27 +01:00
|
|
|
```
|
|
|
|
|
2023-07-12 07:10:57 +02:00
|
|
|
But if you do want to merge in a option name *and* its values, keep reading!
|
2019-03-06 21:06:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
## Include merging
|
|
|
|
|
2022-10-29 04:33:19 +02:00
|
|
|
If you need to get even fancier and merge in common configuration options, you
|
|
|
|
can perform a YAML merge of included configuration using the YAML `<<` key.
|
|
|
|
For instance, here's an example of a main configuration file that pulls in
|
2023-07-12 04:42:14 +02:00
|
|
|
retention and consistency checks options via a single include:
|
2019-03-06 21:06:27 +01:00
|
|
|
|
|
|
|
```yaml
|
2023-07-12 04:42:14 +02:00
|
|
|
repositories:
|
|
|
|
- path: repo.borg
|
2022-04-26 06:18:37 +02:00
|
|
|
|
2023-07-12 04:42:14 +02:00
|
|
|
<<: !include /etc/borgmatic/common.yaml
|
2019-03-06 21:06:27 +01:00
|
|
|
```
|
|
|
|
|
2022-04-26 06:18:37 +02:00
|
|
|
This is what `common.yaml` might look like:
|
2019-03-06 21:06:27 +01:00
|
|
|
|
|
|
|
```yaml
|
2023-07-12 04:42:14 +02:00
|
|
|
keep_hourly: 24
|
|
|
|
keep_daily: 7
|
2022-10-29 04:33:19 +02:00
|
|
|
|
2023-07-12 04:42:14 +02:00
|
|
|
checks:
|
|
|
|
- name: repository
|
|
|
|
frequency: 3 weeks
|
|
|
|
- name: archives
|
|
|
|
frequency: 2 weeks
|
2019-03-06 21:06:27 +01:00
|
|
|
```
|
|
|
|
|
2023-07-12 04:42:14 +02:00
|
|
|
<span class="minilink minilink-addedin">Prior to version 1.8.0</span> These
|
|
|
|
options were organized into sections like `retention:` and `consistency:`.
|
|
|
|
|
2022-10-29 04:33:19 +02:00
|
|
|
Once this include gets merged in, the resulting configuration would have all
|
2023-07-12 04:42:14 +02:00
|
|
|
of the options from the original configuration file *and* the options from the
|
|
|
|
include.
|
2019-03-06 21:06:27 +01:00
|
|
|
|
2019-06-17 06:33:40 +02:00
|
|
|
Note that this `<<` include merging syntax is only for merging in mappings
|
2022-05-08 23:48:42 +02:00
|
|
|
(configuration options and their values). But if you'd like to include a
|
2023-07-12 04:42:14 +02:00
|
|
|
single value directly, please see the above about standard includes.
|
2019-06-17 06:33:40 +02:00
|
|
|
|
2022-05-26 08:12:42 +02:00
|
|
|
Additionally, there is a limitation preventing multiple `<<` include merges
|
2023-07-12 04:42:14 +02:00
|
|
|
per file or option value. So for instance, that means you can do one `<<`
|
|
|
|
merge at the global level, another `<<` within each nested option value, etc.
|
|
|
|
(This is a YAML limitation.)
|
2022-05-26 08:12:42 +02:00
|
|
|
|
2019-03-06 21:06:27 +01:00
|
|
|
|
2022-06-17 05:23:16 +02:00
|
|
|
### Deep merge
|
|
|
|
|
2022-06-17 05:49:15 +02:00
|
|
|
<span class="minilink minilink-addedin">New in version 1.6.0</span> borgmatic
|
|
|
|
performs a deep merge of merged include files, meaning that values are merged
|
2022-10-29 04:33:19 +02:00
|
|
|
at all levels in the two configuration files. This allows you to include
|
|
|
|
common configuration—up to full borgmatic configuration files—while overriding
|
|
|
|
only the parts you want to customize.
|
|
|
|
|
2023-07-12 07:10:57 +02:00
|
|
|
For instance, here's an example of a main configuration file that pulls in
|
|
|
|
options via an include and then overrides one of them locally:
|
2022-10-29 04:33:19 +02:00
|
|
|
|
|
|
|
```yaml
|
|
|
|
<<: !include /etc/borgmatic/common.yaml
|
|
|
|
|
2023-07-12 07:10:57 +02:00
|
|
|
constants:
|
|
|
|
hostname: myhostname
|
2022-10-29 04:33:19 +02:00
|
|
|
|
2023-07-12 07:10:57 +02:00
|
|
|
repositories:
|
|
|
|
- path: repo.borg
|
2022-10-29 04:33:19 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
This is what `common.yaml` might look like:
|
|
|
|
|
|
|
|
```yaml
|
2023-07-12 07:10:57 +02:00
|
|
|
constants:
|
|
|
|
prefix: myprefix
|
|
|
|
hostname: otherhost
|
2022-10-29 04:33:19 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
Once this include gets merged in, the resulting configuration would have a
|
2023-07-12 07:10:57 +02:00
|
|
|
`prefix` value of `myprefix` and an overridden `hostname` value of
|
|
|
|
`myhostname`.
|
2022-10-29 04:33:19 +02:00
|
|
|
|
|
|
|
When there's an option collision between the local file and the merged
|
|
|
|
include, the local file's option takes precedence.
|
|
|
|
|
2023-04-13 23:39:36 +02:00
|
|
|
|
|
|
|
#### List merge
|
|
|
|
|
2022-10-29 04:33:19 +02:00
|
|
|
<span class="minilink minilink-addedin">New in version 1.6.1</span> Colliding
|
|
|
|
list values are appended together.
|
2022-06-17 05:23:16 +02:00
|
|
|
|
2023-04-13 23:39:36 +02:00
|
|
|
<span class="minilink minilink-addedin">New in version 1.7.12</span> If there
|
|
|
|
is a list value from an include that you *don't* want in your local
|
|
|
|
configuration file, you can omit it with an `!omit` tag. For instance:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
<<: !include /etc/borgmatic/common.yaml
|
|
|
|
|
2023-07-12 07:10:57 +02:00
|
|
|
source_directories:
|
|
|
|
- !omit /home
|
|
|
|
- /var
|
2023-04-13 23:39:36 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
And `common.yaml` like this:
|
|
|
|
|
|
|
|
```yaml
|
2023-07-12 07:10:57 +02:00
|
|
|
source_directories:
|
|
|
|
- /home
|
|
|
|
- /etc
|
2023-04-13 23:39:36 +02:00
|
|
|
```
|
|
|
|
|
2023-07-12 07:10:57 +02:00
|
|
|
<span class="minilink minilink-addedin">Prior to version 1.8.0</span> Put
|
|
|
|
this option in the `location:` section of your configuration.
|
|
|
|
|
2023-04-13 23:39:36 +02:00
|
|
|
Once this include gets merged in, the resulting configuration will have a
|
|
|
|
`source_directories` value of `/etc` and `/var`—with `/home` omitted.
|
|
|
|
|
|
|
|
This feature currently only works on scalar (e.g. string or number) list items
|
|
|
|
and will not work elsewhere in a configuration file. Be sure to put the
|
|
|
|
`!omit` tag *before* the list item (after the dash). Putting `!omit` after the
|
|
|
|
list item will not work, as it gets interpreted as part of the string. Here's
|
|
|
|
an example of some things not to do:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
<<: !include /etc/borgmatic/common.yaml
|
|
|
|
|
2023-07-12 07:10:57 +02:00
|
|
|
source_directories:
|
|
|
|
# Do not do this! It will not work. "!omit" belongs before "/home".
|
|
|
|
- /home !omit
|
2023-04-13 23:39:36 +02:00
|
|
|
|
2023-07-12 07:10:57 +02:00
|
|
|
# Do not do this either! "!omit" only works on scalar list items.
|
|
|
|
repositories: !omit
|
|
|
|
# Also do not do this for the same reason! This is a list item, but it's
|
|
|
|
# not a scalar.
|
|
|
|
- !omit path: repo.borg
|
2023-04-13 23:39:36 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
Additionally, the `!omit` tag only works in a configuration file that also
|
|
|
|
performs a merge include with `<<: !include`. It doesn't make sense within,
|
|
|
|
for instance, an included configuration file itself (unless it in turn
|
|
|
|
performs its own merge include). That's because `!omit` only applies to the
|
|
|
|
file doing the include; it doesn't work in reverse or propagate through
|
|
|
|
includes.
|
|
|
|
|
2022-06-17 05:23:16 +02:00
|
|
|
|
2023-04-12 06:49:10 +02:00
|
|
|
### Shallow merge
|
|
|
|
|
|
|
|
Even though deep merging is generally pretty handy for included files,
|
2023-07-12 04:42:14 +02:00
|
|
|
sometimes you want specific options in the local file to take precedence over
|
|
|
|
included options—without any merging occurring for them.
|
2023-04-12 06:49:10 +02:00
|
|
|
|
|
|
|
<span class="minilink minilink-addedin">New in version 1.7.12</span> That's
|
|
|
|
where the `!retain` tag comes in. Whenever you're merging an included file
|
|
|
|
into your configuration file, you can optionally add the `!retain` tag to
|
2023-04-12 19:30:23 +02:00
|
|
|
particular local mappings or lists to retain the local values and ignore
|
2023-04-12 06:49:10 +02:00
|
|
|
included values.
|
|
|
|
|
|
|
|
For instance, start with this configuration file containing the `!retain` tag
|
|
|
|
on the `retention` mapping:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
<<: !include /etc/borgmatic/common.yaml
|
|
|
|
|
2023-07-12 04:42:14 +02:00
|
|
|
repositories:
|
|
|
|
- path: repo.borg
|
2023-04-12 06:49:10 +02:00
|
|
|
|
2023-07-12 04:42:14 +02:00
|
|
|
checks: !retain
|
|
|
|
- name: repository
|
2023-04-12 06:49:10 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
And `common.yaml` like this:
|
|
|
|
|
|
|
|
```yaml
|
2023-07-12 04:42:14 +02:00
|
|
|
repositories:
|
|
|
|
- path: common.borg
|
2023-04-12 06:49:10 +02:00
|
|
|
|
2023-07-12 04:42:14 +02:00
|
|
|
checks:
|
|
|
|
- name: archives
|
2023-04-12 06:49:10 +02:00
|
|
|
```
|
|
|
|
|
2023-07-12 04:42:14 +02:00
|
|
|
<span class="minilink minilink-addedin">Prior to version 1.8.0</span> These
|
|
|
|
options were organized into sections like `location:` and `consistency:`.
|
2023-04-12 19:30:23 +02:00
|
|
|
|
2023-07-12 04:42:14 +02:00
|
|
|
Once this include gets merged in, the resulting configuration will have a
|
|
|
|
`checks` value with a name of `repository` and no other values. That's because
|
|
|
|
the `!retain` tag says to retain the local version of `checks` and ignore any
|
|
|
|
values coming in from the include. But because the `repositories` list doesn't
|
|
|
|
have a `!retain` tag, it still gets merged together to contain both
|
|
|
|
`common.borg` and `repo.borg`.
|
|
|
|
|
|
|
|
The `!retain` tag can only be placed on mappings (keys/values) and lists, and
|
|
|
|
it goes right after the name of the option (and its colon) on the same line.
|
|
|
|
The effects of `!retain` are recursive, meaning that if you place a `!retain`
|
|
|
|
tag on a top-level mapping, even deeply nested values within it will not be
|
|
|
|
merged.
|
2023-04-12 06:49:10 +02:00
|
|
|
|
|
|
|
Additionally, the `!retain` tag only works in a configuration file that also
|
|
|
|
performs a merge include with `<<: !include`. It doesn't make sense within,
|
|
|
|
for instance, an included configuration file itself (unless it in turn
|
|
|
|
performs its own merge include). That's because `!retain` only applies to the
|
|
|
|
file doing the include; it doesn't work in reverse or propagate through
|
|
|
|
includes.
|
|
|
|
|
|
|
|
|
2023-04-11 19:49:09 +02:00
|
|
|
## Debugging includes
|
|
|
|
|
2023-06-23 19:11:41 +02:00
|
|
|
<span class="minilink minilink-addedin">New in version 1.7.15</span> If you'd
|
2023-04-11 19:49:09 +02:00
|
|
|
like to see what the loaded configuration looks like after includes get merged
|
2023-06-23 19:11:41 +02:00
|
|
|
in, run the `validate` action on your configuration file:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
sudo borgmatic config validate --show
|
|
|
|
```
|
|
|
|
|
|
|
|
<span class="minilink minilink-addedin">In version 1.7.12 through
|
|
|
|
1.7.14</span> Use this command instead:
|
2023-04-11 19:49:09 +02:00
|
|
|
|
|
|
|
```bash
|
|
|
|
sudo validate-borgmatic-config --show
|
|
|
|
```
|
|
|
|
|
|
|
|
You'll need to specify your configuration file with `--config` if it's not in
|
|
|
|
a default location.
|
|
|
|
|
|
|
|
This will output the merged configuration as borgmatic sees it, which can be
|
|
|
|
helpful for understanding how your includes work in practice.
|
|
|
|
|
|
|
|
|
2019-12-17 20:46:27 +01:00
|
|
|
## Configuration overrides
|
|
|
|
|
|
|
|
In more complex multi-application setups, you may want to override particular
|
|
|
|
borgmatic configuration file options at the time you run borgmatic. For
|
|
|
|
instance, you could reuse a common configuration file for multiple
|
|
|
|
applications, but then set the repository for each application at runtime. Or
|
|
|
|
you might want to try a variant of an option for testing purposes without
|
|
|
|
actually touching your configuration file.
|
|
|
|
|
|
|
|
Whatever the reason, you can override borgmatic configuration options at the
|
|
|
|
command-line via the `--override` flag. Here's an example:
|
|
|
|
|
|
|
|
```bash
|
2023-07-12 04:42:14 +02:00
|
|
|
borgmatic create --override remote_path=/usr/local/bin/borg1
|
2019-12-17 20:46:27 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
What this does is load your configuration files, and for each one, disregard
|
2023-07-12 04:42:14 +02:00
|
|
|
the configured value for the `remote_path` option, and use the value of
|
|
|
|
`/usr/local/bin/borg1` instead.
|
2019-12-17 20:46:27 +01:00
|
|
|
|
2023-07-12 04:42:14 +02:00
|
|
|
You can even override nested values or multiple values at once. For instance:
|
2020-11-19 20:01:53 +01:00
|
|
|
|
|
|
|
```bash
|
2023-07-12 04:42:14 +02:00
|
|
|
borgmatic create --override parent_option.option1=value1 parent_option.option2=value2
|
2020-11-19 20:01:53 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
This will accomplish the same thing:
|
|
|
|
|
|
|
|
```bash
|
2023-07-12 04:42:14 +02:00
|
|
|
borgmatic create --override parent_option.option1=value1 --override parent_option.option2=value2
|
2020-11-19 20:01:53 +01:00
|
|
|
```
|
|
|
|
|
2023-07-12 04:42:14 +02:00
|
|
|
<span class="minilink minilink-addedin">Prior to version 1.8.0</span> Don't
|
|
|
|
forget to specify the section that an option is in. That looks like a prefix
|
|
|
|
on the option name, e.g. `location.repositories`.
|
|
|
|
|
2020-11-19 20:01:53 +01:00
|
|
|
Note that each value is parsed as an actual YAML string, so you can even set
|
2019-12-17 20:46:27 +01:00
|
|
|
list values by using brackets. For instance:
|
|
|
|
|
|
|
|
```bash
|
2023-07-12 04:42:14 +02:00
|
|
|
borgmatic create --override repositories=[test1.borg,test2.borg]
|
2019-12-17 20:46:27 +01:00
|
|
|
```
|
|
|
|
|
2020-07-24 06:33:42 +02:00
|
|
|
Or even a single list element:
|
|
|
|
|
|
|
|
```bash
|
2023-07-12 04:42:14 +02:00
|
|
|
borgmatic create --override repositories=[/root/test.borg]
|
2022-05-20 22:38:53 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
If your override value contains special YAML characters like colons, then
|
|
|
|
you'll need quotes for it to parse correctly:
|
|
|
|
|
|
|
|
```bash
|
2023-07-12 04:42:14 +02:00
|
|
|
borgmatic create --override repositories="['user@server:test.borg']"
|
2020-07-24 06:33:42 +02:00
|
|
|
```
|
|
|
|
|
2019-12-17 20:46:27 +01:00
|
|
|
There is not currently a way to override a single element of a list without
|
|
|
|
replacing the whole list.
|
|
|
|
|
2020-07-24 06:33:42 +02:00
|
|
|
Note that if you override an option of the list type (like
|
|
|
|
`location.repositories`), you do need to use the `[ ]` list syntax. See the
|
|
|
|
[configuration
|
|
|
|
reference](https://torsion.org/borgmatic/docs/reference/configuration/) for
|
|
|
|
which options are list types. (YAML list values look like `- this` with an
|
|
|
|
indentation and a leading dash.)
|
|
|
|
|
2019-12-17 20:46:27 +01:00
|
|
|
Be sure to quote your overrides if they contain spaces or other characters
|
|
|
|
that your shell may interpret.
|
2022-06-17 00:30:53 +02:00
|
|
|
|
2023-07-12 04:42:14 +02:00
|
|
|
An alternate to command-line overrides is passing in your values via
|
|
|
|
[environment
|
|
|
|
variables](https://torsion.org/borgmatic/docs/how-to/provide-your-passwords/).
|
2023-03-25 07:47:05 +01:00
|
|
|
|
|
|
|
|
2023-03-25 16:56:25 +01:00
|
|
|
## Constant interpolation
|
2023-03-25 07:47:05 +01:00
|
|
|
|
|
|
|
<span class="minilink minilink-addedin">New in version 1.7.10</span> Another
|
|
|
|
tool is borgmatic's support for defining custom constants. This is similar to
|
|
|
|
the [variable interpolation
|
|
|
|
feature](https://torsion.org/borgmatic/docs/how-to/add-preparation-and-cleanup-steps-to-backups/#variable-interpolation)
|
|
|
|
for command hooks, but the constants feature lets you substitute your own
|
|
|
|
custom values into anywhere in the entire configuration file. (Constants don't
|
|
|
|
work across includes or separate configuration files though.)
|
|
|
|
|
|
|
|
Here's an example usage:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
constants:
|
|
|
|
user: foo
|
2023-04-01 00:21:08 +02:00
|
|
|
archive_prefix: bar
|
2023-03-25 07:47:05 +01:00
|
|
|
|
2023-07-12 04:42:14 +02:00
|
|
|
source_directories:
|
|
|
|
- /home/{user}/.config
|
|
|
|
- /home/{user}/.ssh
|
2023-03-25 07:47:05 +01:00
|
|
|
|
2023-07-12 04:42:14 +02:00
|
|
|
...
|
|
|
|
|
|
|
|
archive_name_format: '{archive_prefix}-{now}'
|
2023-03-25 07:47:05 +01:00
|
|
|
```
|
|
|
|
|
2023-07-12 04:42:14 +02:00
|
|
|
<span class="minilink minilink-addedin">Prior to version 1.8.0</span> Don't
|
|
|
|
forget to specify the section (like `location:` or `storage:`) that any option
|
|
|
|
is in.
|
|
|
|
|
2023-03-25 07:47:05 +01:00
|
|
|
In this example, when borgmatic runs, all instances of `{user}` get replaced
|
2023-04-01 00:21:08 +02:00
|
|
|
with `foo` and all instances of `{archive-prefix}` get replaced with `bar-`.
|
|
|
|
(And in this particular example, `{now}` doesn't get replaced with anything,
|
|
|
|
but gets passed directly to Borg.) After substitution, the logical result
|
|
|
|
looks something like this:
|
2023-03-25 07:47:05 +01:00
|
|
|
|
|
|
|
```yaml
|
2023-07-12 04:42:14 +02:00
|
|
|
source_directories:
|
|
|
|
- /home/foo/.config
|
|
|
|
- /home/foo/.ssh
|
2023-03-25 07:47:05 +01:00
|
|
|
|
2023-07-12 04:42:14 +02:00
|
|
|
...
|
|
|
|
|
|
|
|
archive_name_format: 'bar-{now}'
|
2023-03-25 07:47:05 +01:00
|
|
|
```
|
2023-03-25 16:56:25 +01:00
|
|
|
|
|
|
|
An alternate to constants is passing in your values via [environment
|
|
|
|
variables](https://torsion.org/borgmatic/docs/how-to/provide-your-passwords/).
|