2019-02-04 07:20:59 +01:00
|
|
|
---
|
|
|
|
title: How to make per-application backups
|
2020-08-21 23:27:47 +02:00
|
|
|
eleventyNavigation:
|
|
|
|
key: Make per-application backups
|
|
|
|
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
|
|
|
|
different applications on your system. For instance, you may want one backup
|
|
|
|
configuration for your database data directory, and a different configuration
|
|
|
|
for your user home directories.
|
|
|
|
|
|
|
|
The way to accomplish that is pretty simple: Create multiple separate
|
|
|
|
configuration files and place each one in a `/etc/borgmatic.d/` directory. For
|
|
|
|
instance:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
sudo mkdir /etc/borgmatic.d
|
|
|
|
sudo generate-borgmatic-config --destination /etc/borgmatic.d/app1.yaml
|
|
|
|
sudo generate-borgmatic-config --destination /etc/borgmatic.d/app2.yaml
|
|
|
|
```
|
|
|
|
|
|
|
|
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
|
|
|
|
to merge your configuration files, see below about configuration includes.
|
|
|
|
|
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
|
|
|
|
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.
|
|
|
|
|
|
|
|
Let's say that you want to include common retention configuration across all
|
|
|
|
of your configuration files. You could do that in each configuration file with
|
|
|
|
the following:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
location:
|
|
|
|
...
|
|
|
|
|
|
|
|
retention:
|
|
|
|
!include /etc/borgmatic/common_retention.yaml
|
|
|
|
```
|
|
|
|
|
|
|
|
And then the contents of `common_retention.yaml` could be:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
keep_hourly: 24
|
|
|
|
keep_daily: 7
|
|
|
|
```
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2019-03-06 21:06:27 +01:00
|
|
|
Note that this form of include must be a YAML value rather than a key. For
|
|
|
|
example, this will not work:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
location:
|
|
|
|
...
|
|
|
|
|
|
|
|
# Don't do this. It won't work!
|
|
|
|
!include /etc/borgmatic/common_retention.yaml
|
|
|
|
```
|
|
|
|
|
2022-04-26 06:18:37 +02:00
|
|
|
But if you do want to merge in a YAML key *and* its values, keep reading!
|
2019-03-06 21:06:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
## Include merging
|
|
|
|
|
|
|
|
If you need to get even fancier and pull in common configuration options while
|
|
|
|
potentially overriding individual 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 two retention options via
|
2022-04-26 06:18:37 +02:00
|
|
|
an include and then overrides one of them locally:
|
2019-03-06 21:06:27 +01:00
|
|
|
|
|
|
|
```yaml
|
2022-04-26 06:18:37 +02:00
|
|
|
<<: !include /etc/borgmatic/common.yaml
|
|
|
|
|
2019-03-06 21:06:27 +01:00
|
|
|
location:
|
|
|
|
...
|
|
|
|
|
|
|
|
retention:
|
|
|
|
keep_daily: 5
|
|
|
|
```
|
|
|
|
|
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
|
2022-04-26 06:18:37 +02:00
|
|
|
retention:
|
|
|
|
keep_hourly: 24
|
|
|
|
keep_daily: 7
|
2019-03-06 21:06:27 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
Once this include gets merged in, the resulting configuration would have a
|
|
|
|
`keep_hourly` value of `24` and an overridden `keep_daily` value of `5`.
|
|
|
|
|
2022-04-26 06:18:37 +02:00
|
|
|
When there's an option collision between the local file and the merged
|
2022-04-26 19:12:02 +02:00
|
|
|
include, the local file's option takes precedence. And as of borgmatic 1.6.0,
|
2022-04-26 06:18:37 +02:00
|
|
|
this feature performs a deep merge, meaning that values are merged 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.
|
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
|
|
|
|
single value directly, please see the section above about standard includes.
|
2019-06-17 06:33:40 +02:00
|
|
|
|
2019-03-06 21:06:27 +01:00
|
|
|
|
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
|
2020-07-24 06:33:42 +02:00
|
|
|
borgmatic create --override location.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
|
|
|
|
the configured value for the `remote_path` option in the `location` section,
|
2020-07-24 06:33:42 +02:00
|
|
|
and use the value of `/usr/local/bin/borg1` instead.
|
2019-12-17 20:46:27 +01:00
|
|
|
|
2020-11-19 20:01:53 +01:00
|
|
|
You can even override multiple values at once. For instance:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
borgmatic create --override section.option1=value1 section.option2=value2
|
|
|
|
```
|
|
|
|
|
|
|
|
This will accomplish the same thing:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
borgmatic create --override section.option1=value1 --override section.option2=value2
|
|
|
|
```
|
|
|
|
|
|
|
|
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
|
|
|
|
borgmatic create --override location.repositories=[test1.borg,test2.borg]
|
|
|
|
```
|
|
|
|
|
2020-07-24 06:33:42 +02:00
|
|
|
Or even a single list element:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
borgmatic create --override location.repositories=[/root/test1.borg]
|
|
|
|
```
|
|
|
|
|
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.
|