2019-10-15 19:49:14 +02:00
|
|
|
---
|
|
|
|
title: How to monitor your backups
|
2020-08-21 23:27:47 +02:00
|
|
|
eleventyNavigation:
|
2022-05-20 20:11:35 +02:00
|
|
|
key: 🚨 Monitor your backups
|
2020-08-21 23:27:47 +02:00
|
|
|
parent: How-to guides
|
2022-06-17 00:30:53 +02:00
|
|
|
order: 6
|
2019-10-15 19:49:14 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
## Monitoring and alerting
|
|
|
|
|
|
|
|
Having backups is great, but they won't do you a lot of good unless you have
|
|
|
|
confidence that they're running on a regular basis. That's where monitoring
|
|
|
|
and alerting comes in.
|
|
|
|
|
|
|
|
There are several different ways you can monitor your backups and find out
|
|
|
|
whether they're succeeding. Which of these you choose to do is up to you and
|
2020-08-12 19:40:39 +02:00
|
|
|
your particular infrastructure.
|
|
|
|
|
|
|
|
### Job runner alerts
|
|
|
|
|
|
|
|
The easiest place to start is with failure alerts from the [scheduled job
|
|
|
|
runner](https://torsion.org/borgmatic/docs/how-to/set-up-backups/#autopilot)
|
|
|
|
(cron, systemd, etc.) that's running borgmatic. But note that if the job
|
|
|
|
doesn't even get scheduled (e.g. due to the job runner not running), you
|
|
|
|
probably won't get an alert at all! Still, this is a decent first line of
|
|
|
|
defense, especially when combined with some of the other approaches below.
|
|
|
|
|
|
|
|
### Commands run on error
|
|
|
|
|
|
|
|
The `on_error` hook allows you to run an arbitrary command or script when
|
|
|
|
borgmatic itself encounters an error running your backups. So for instance,
|
|
|
|
you can run a script to send yourself a text message alert. But note that if
|
|
|
|
borgmatic doesn't actually run, this alert won't fire. See [error
|
2019-10-15 19:49:14 +02:00
|
|
|
hooks](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#error-hooks)
|
|
|
|
below for how to configure this.
|
2020-08-12 19:40:39 +02:00
|
|
|
|
|
|
|
### Third-party monitoring services
|
|
|
|
|
2023-10-05 04:23:53 +02:00
|
|
|
borgmatic integrates with these monitoring services and libraries, pinging
|
|
|
|
them as backups happen:
|
|
|
|
|
|
|
|
* [Healthchecks](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#healthchecks-hook)
|
|
|
|
* [Cronitor](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#cronitor-hook)
|
|
|
|
* [Cronhub](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#cronhub-hook)
|
|
|
|
* [PagerDuty](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#pagerduty-hook)
|
|
|
|
* [ntfy](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#ntfy-hook)
|
|
|
|
* [Grafana Loki](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#loki-hook)
|
|
|
|
* [Apprise](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#apprise-hook)
|
|
|
|
|
|
|
|
The idea is that you'll receive an alert when something goes wrong or when the
|
|
|
|
service doesn't hear from borgmatic for a configured interval (if supported).
|
|
|
|
See the documentation links above for configuration information.
|
|
|
|
|
|
|
|
While these services and libraries offer different features, you probably only
|
|
|
|
need to use one of them at most.
|
2020-08-12 19:40:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
### Third-party monitoring software
|
|
|
|
|
|
|
|
You can use traditional monitoring software to consume borgmatic JSON output
|
|
|
|
and track when the last successful backup occurred. See [scripting
|
2019-10-15 19:49:14 +02:00
|
|
|
borgmatic](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#scripting-borgmatic)
|
|
|
|
below for how to configure this.
|
2020-08-12 19:40:39 +02:00
|
|
|
|
|
|
|
### Borg hosting providers
|
|
|
|
|
|
|
|
Most [Borg hosting
|
2019-10-15 19:49:14 +02:00
|
|
|
providers](https://torsion.org/borgmatic/#hosting-providers) include
|
|
|
|
monitoring and alerting as part of their offering. This gives you a dashboard
|
|
|
|
to check on all of your backups, and can alert you if the service doesn't hear
|
|
|
|
from borgmatic for a configured interval.
|
2020-08-12 19:40:39 +02:00
|
|
|
|
|
|
|
### Consistency checks
|
|
|
|
|
2023-05-01 00:43:41 +02:00
|
|
|
While not strictly part of monitoring, if you want confidence that your
|
2020-08-12 19:40:39 +02:00
|
|
|
backups are not only running but are restorable as well, you can configure
|
|
|
|
particular [consistency
|
2019-10-15 19:49:14 +02:00
|
|
|
checks](https://torsion.org/borgmatic/docs/how-to/deal-with-very-large-backups/#consistency-check-configuration)
|
2019-11-01 05:45:47 +01:00
|
|
|
or even script full [extract
|
|
|
|
tests](https://torsion.org/borgmatic/docs/how-to/extract-a-backup/).
|
2019-10-15 19:49:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
## Error hooks
|
|
|
|
|
2023-03-08 23:05:06 +01:00
|
|
|
When an error occurs during a `create`, `prune`, `compact`, or `check` action,
|
2022-02-09 23:33:12 +01:00
|
|
|
borgmatic can run configurable shell commands to fire off custom error
|
|
|
|
notifications or take other actions, so you can get alerted as soon as
|
|
|
|
something goes wrong. Here's a not-so-useful example:
|
2019-10-15 19:49:14 +02:00
|
|
|
|
|
|
|
```yaml
|
2023-07-12 07:10:57 +02:00
|
|
|
on_error:
|
|
|
|
- echo "Error while creating a backup or running a backup hook."
|
2019-10-15 19:49:14 +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 `hooks:` section of your configuration.
|
|
|
|
|
2019-10-15 19:49:14 +02:00
|
|
|
The `on_error` hook supports interpolating particular runtime variables into
|
|
|
|
the hook command. Here's an example that assumes you provide a separate shell
|
|
|
|
script to handle the alerting:
|
|
|
|
|
|
|
|
```yaml
|
2023-07-12 07:10:57 +02:00
|
|
|
on_error:
|
2024-03-11 18:42:51 +01:00
|
|
|
- send-text-message.sh {configuration_filename} {repository}
|
2019-10-15 19:49:14 +02:00
|
|
|
```
|
|
|
|
|
2022-03-14 21:34:14 +01:00
|
|
|
In this example, when the error occurs, borgmatic interpolates runtime values
|
2023-07-19 08:27:45 +02:00
|
|
|
into the hook command: the borgmatic configuration filename and the path of
|
2022-03-14 21:34:14 +01:00
|
|
|
the repository. Here's the full set of supported variables you can use here:
|
2019-10-15 19:49:14 +02:00
|
|
|
|
|
|
|
* `configuration_filename`: borgmatic configuration filename in which the
|
|
|
|
error occurred
|
|
|
|
* `repository`: path of the repository in which the error occurred (may be
|
|
|
|
blank if the error occurs in a hook)
|
|
|
|
* `error`: the error message itself
|
|
|
|
* `output`: output of the command that failed (may be blank if an error
|
|
|
|
occurred without running a command)
|
|
|
|
|
2023-03-08 23:05:06 +01:00
|
|
|
Note that borgmatic runs the `on_error` hooks only for `create`, `prune`,
|
2023-07-19 08:27:45 +02:00
|
|
|
`compact`, or `check` actions/hooks in which an error occurs and not other
|
2022-02-09 23:33:12 +01:00
|
|
|
actions. borgmatic does not run `on_error` hooks if an error occurs within a
|
2019-12-20 22:58:02 +01:00
|
|
|
`before_everything` or `after_everything` hook. For more about hooks, see the
|
|
|
|
[borgmatic hooks
|
2019-10-24 00:35:37 +02:00
|
|
|
documentation](https://torsion.org/borgmatic/docs/how-to/add-preparation-and-cleanup-steps-to-backups/),
|
2019-10-15 19:49:14 +02:00
|
|
|
especially the security information.
|
|
|
|
|
2024-03-11 18:42:51 +01:00
|
|
|
<span class="minilink minilink-addedin">New in version 1.8.7</span> borgmatic
|
|
|
|
automatically escapes these interpolated values to prevent shell injection
|
|
|
|
attacks. One implication of this change is that you shouldn't wrap the
|
|
|
|
interpolated values in your own quotes, as that will interfere with the
|
|
|
|
quoting performed by borgmatic and result in your command receiving incorrect
|
|
|
|
arguments. For instance, this won't work:
|
|
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
on_error:
|
|
|
|
# Don't do this! It won't work, as the {error} value is already quoted.
|
|
|
|
- send-text-message.sh "Uh oh: {error}"
|
|
|
|
```
|
|
|
|
|
|
|
|
Do this instead:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
on_error:
|
|
|
|
- send-text-message.sh {error}
|
|
|
|
```
|
|
|
|
|
2019-10-15 19:49:14 +02:00
|
|
|
|
|
|
|
## Healthchecks hook
|
|
|
|
|
|
|
|
[Healthchecks](https://healthchecks.io/) is a service that provides "instant
|
2023-08-25 19:52:00 +02:00
|
|
|
alerts when your cron jobs fail silently," and borgmatic has built-in
|
2019-10-15 19:49:14 +02:00
|
|
|
integration with it. Once you create a Healthchecks account and project on
|
|
|
|
their site, all you need to do is configure borgmatic with the unique "Ping
|
|
|
|
URL" for your project. Here's an example:
|
|
|
|
|
|
|
|
|
|
|
|
```yaml
|
2023-07-12 07:10:57 +02:00
|
|
|
healthchecks:
|
|
|
|
ping_url: https://hc-ping.com/addffa72-da17-40ae-be9c-ff591afb942a
|
2019-10-15 19:49:14 +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 `hooks:` section of your configuration.
|
|
|
|
|
2023-10-05 04:23:53 +02:00
|
|
|
With this configuration, borgmatic pings your Healthchecks project when a
|
2023-08-25 19:52:00 +02:00
|
|
|
backup begins, ends, or errors, but only when any of the `create`, `prune`,
|
|
|
|
`compact`, or `check` actions are run.
|
2019-11-18 01:54:27 +01:00
|
|
|
|
2019-12-13 07:54:45 +01:00
|
|
|
Then, if the actions complete successfully, borgmatic notifies Healthchecks of
|
2023-08-25 19:52:00 +02:00
|
|
|
the success and includes borgmatic logs in the payload data sent to
|
|
|
|
Healthchecks. This means that borgmatic logs show up in the Healthchecks UI,
|
2024-03-11 00:18:49 +01:00
|
|
|
although be aware that Healthchecks currently has a 100-kilobyte limit for the
|
2023-08-25 19:52:00 +02:00
|
|
|
logs in each ping.
|
2019-11-18 01:54:27 +01:00
|
|
|
|
2023-08-25 19:52:00 +02:00
|
|
|
If an error occurs during any action or hook, borgmatic notifies Healthchecks,
|
|
|
|
also tacking on logs including the error itself. But the logs are only
|
|
|
|
included for errors that occur when a `create`, `prune`, `compact`, or `check`
|
|
|
|
action is run.
|
2019-11-18 01:54:27 +01:00
|
|
|
|
2020-01-23 00:10:47 +01:00
|
|
|
You can customize the verbosity of the logs that are sent to Healthchecks with
|
2022-08-21 23:25:16 +02:00
|
|
|
borgmatic's `--monitoring-verbosity` flag. The `--list` and `--stats` flags
|
|
|
|
may also be of use. See `borgmatic create --help` for more information.
|
|
|
|
Additionally, see the [borgmatic configuration
|
2022-05-25 00:50:04 +02:00
|
|
|
file](https://torsion.org/borgmatic/docs/reference/configuration/) for
|
|
|
|
additional Healthchecks options.
|
2019-11-06 18:44:46 +01:00
|
|
|
|
|
|
|
You can configure Healthchecks to notify you by a [variety of
|
2019-10-15 19:49:14 +02:00
|
|
|
mechanisms](https://healthchecks.io/#welcome-integrations) when backups fail
|
|
|
|
or it doesn't hear from borgmatic for a certain period of time.
|
|
|
|
|
|
|
|
|
2019-11-01 19:33:15 +01:00
|
|
|
## Cronitor hook
|
|
|
|
|
|
|
|
[Cronitor](https://cronitor.io/) provides "Cron monitoring and uptime healthchecks
|
2023-08-25 19:52:00 +02:00
|
|
|
for websites, services and APIs," and borgmatic has built-in
|
2019-11-01 19:33:15 +01:00
|
|
|
integration with it. Once you create a Cronitor account and cron job monitor on
|
|
|
|
their site, all you need to do is configure borgmatic with the unique "Ping
|
|
|
|
API URL" for your monitor. Here's an example:
|
|
|
|
|
|
|
|
|
|
|
|
```yaml
|
2023-07-12 07:10:57 +02:00
|
|
|
cronitor:
|
|
|
|
ping_url: https://cronitor.link/d3x0c1
|
2019-11-01 19:33:15 +01: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 `hooks:` section of your configuration.
|
|
|
|
|
2023-10-05 04:23:53 +02:00
|
|
|
With this configuration, borgmatic pings your Cronitor monitor when a backup
|
2023-08-25 19:52:00 +02:00
|
|
|
begins, ends, or errors, but only when any of the `prune`, `compact`,
|
|
|
|
`create`, or `check` actions are run. Then, if the actions complete
|
|
|
|
successfully or errors, borgmatic notifies Cronitor accordingly.
|
2019-11-06 18:44:46 +01:00
|
|
|
|
|
|
|
You can configure Cronitor to notify you by a [variety of
|
|
|
|
mechanisms](https://cronitor.io/docs/cron-job-notifications) when backups fail
|
|
|
|
or it doesn't hear from borgmatic for a certain period of time.
|
2019-11-01 19:33:15 +01:00
|
|
|
|
|
|
|
|
2019-11-07 19:08:44 +01:00
|
|
|
## Cronhub hook
|
|
|
|
|
|
|
|
[Cronhub](https://cronhub.io/) provides "instant alerts when any of your
|
2023-08-25 19:52:00 +02:00
|
|
|
background jobs fail silently or run longer than expected," and borgmatic has
|
2019-11-07 19:08:44 +01:00
|
|
|
built-in integration with it. Once you create a Cronhub account and monitor on
|
|
|
|
their site, all you need to do is configure borgmatic with the unique "Ping
|
|
|
|
URL" for your monitor. Here's an example:
|
|
|
|
|
|
|
|
|
|
|
|
```yaml
|
2023-07-12 07:10:57 +02:00
|
|
|
cronhub:
|
|
|
|
ping_url: https://cronhub.io/start/1f5e3410-254c-11e8-b61d-55875966d031
|
2019-11-07 19:08:44 +01: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 `hooks:` section of your configuration.
|
|
|
|
|
2023-10-05 04:23:53 +02:00
|
|
|
With this configuration, borgmatic pings your Cronhub monitor when a backup
|
2023-08-25 19:52:00 +02:00
|
|
|
begins, ends, or errors, but only when any of the `prune`, `compact`,
|
|
|
|
`create`, or `check` actions are run. Then, if the actions complete
|
|
|
|
successfully or errors, borgmatic notifies Cronhub accordingly.
|
2019-11-07 19:08:44 +01:00
|
|
|
|
|
|
|
Note that even though you configure borgmatic with the "start" variant of the
|
|
|
|
ping URL, borgmatic substitutes the correct state into the URL when pinging
|
|
|
|
Cronhub ("start", "finish", or "fail").
|
|
|
|
|
|
|
|
You can configure Cronhub to notify you by a [variety of
|
|
|
|
mechanisms](https://docs.cronhub.io/integrations.html) when backups fail
|
|
|
|
or it doesn't hear from borgmatic for a certain period of time.
|
|
|
|
|
|
|
|
|
2020-01-28 00:32:09 +01:00
|
|
|
## PagerDuty hook
|
|
|
|
|
2020-02-13 22:11:25 +01:00
|
|
|
In case you're new here: [borgmatic](https://torsion.org/borgmatic/) is
|
|
|
|
simple, configuration-driven backup software for servers and workstations,
|
|
|
|
powered by [Borg Backup](https://www.borgbackup.org/).
|
|
|
|
|
2020-02-01 22:43:37 +01:00
|
|
|
[PagerDuty](https://www.pagerduty.com/) provides incident monitoring and
|
2020-02-13 22:11:25 +01:00
|
|
|
alerting. borgmatic has built-in integration that can notify you via PagerDuty
|
|
|
|
as soon as a backup fails, so you can make sure your backups keep working.
|
|
|
|
|
|
|
|
First, create a PagerDuty account and <a
|
2020-01-28 00:32:09 +01:00
|
|
|
href="https://support.pagerduty.com/docs/services-and-integrations">service</a>
|
2020-03-26 22:14:53 +01:00
|
|
|
on their site. On the service, add an integration and set the Integration Type
|
|
|
|
to "borgmatic".
|
2020-02-13 22:11:25 +01:00
|
|
|
|
|
|
|
Then, configure borgmatic with the unique "Integration Key" for your service.
|
|
|
|
Here's an example:
|
2020-01-28 00:32:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
```yaml
|
2023-07-12 07:10:57 +02:00
|
|
|
pagerduty:
|
|
|
|
integration_key: a177cad45bd374409f78906a810a3074
|
2020-01-28 00:32:09 +01: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 `hooks:` section of your configuration.
|
|
|
|
|
2023-10-05 04:23:53 +02:00
|
|
|
With this configuration, borgmatic creates a PagerDuty event for your service
|
2023-08-25 19:52:00 +02:00
|
|
|
whenever backups fail, but only when any of the `create`, `prune`, `compact`,
|
|
|
|
or `check` actions are run. Note that borgmatic does not contact PagerDuty
|
|
|
|
when a backup starts or when it ends without error.
|
2020-01-28 00:32:09 +01:00
|
|
|
|
|
|
|
You can configure PagerDuty to notify you by a [variety of
|
|
|
|
mechanisms](https://support.pagerduty.com/docs/notifications) when backups
|
|
|
|
fail.
|
|
|
|
|
2020-02-13 22:11:25 +01:00
|
|
|
If you have any issues with the integration, [please contact
|
|
|
|
us](https://torsion.org/borgmatic/#support-and-contributing).
|
|
|
|
|
2020-01-28 00:32:09 +01:00
|
|
|
|
2022-06-09 22:41:22 +02:00
|
|
|
## ntfy hook
|
2022-06-09 22:10:34 +02:00
|
|
|
|
2023-08-28 05:30:13 +02:00
|
|
|
<span class="minilink minilink-addedin">New in version 1.6.3</span>
|
|
|
|
[ntfy](https://ntfy.sh) is a free, simple, service (either hosted or
|
|
|
|
self-hosted) which offers simple pub/sub push notifications to multiple
|
|
|
|
platforms including [web](https://ntfy.sh/stats),
|
|
|
|
[Android](https://play.google.com/store/apps/details?id=io.heckel.ntfy) and
|
|
|
|
[iOS](https://apps.apple.com/us/app/ntfy/id1625396347).
|
2022-06-09 22:10:34 +02:00
|
|
|
|
|
|
|
Since push notifications for regular events might soon become quite annoying,
|
2024-03-11 20:48:58 +01:00
|
|
|
this hook only fires on any errors by default in order to instantly alert you
|
|
|
|
to issues. The `states` list can override this. Each state can have its own
|
|
|
|
custom messages, priorities and tags or, if none are provided, will use the
|
|
|
|
default.
|
2022-06-09 22:10:34 +02:00
|
|
|
|
2024-03-11 20:48:58 +01:00
|
|
|
An example configuration is shown here with all the available options,
|
|
|
|
including [priorities](https://ntfy.sh/docs/publish/#message-priority) and
|
2022-06-09 22:10:34 +02:00
|
|
|
[tags](https://ntfy.sh/docs/publish/#tags-emojis):
|
|
|
|
|
|
|
|
```yaml
|
2023-07-12 07:10:57 +02:00
|
|
|
ntfy:
|
|
|
|
topic: my-unique-topic
|
|
|
|
server: https://ntfy.my-domain.com
|
2024-03-11 20:48:58 +01:00
|
|
|
username: myuser
|
|
|
|
password: secret
|
|
|
|
|
2023-07-12 07:10:57 +02:00
|
|
|
start:
|
2023-07-27 08:38:08 +02:00
|
|
|
title: A borgmatic backup started
|
2023-07-12 07:10:57 +02:00
|
|
|
message: Watch this space...
|
|
|
|
tags: borgmatic
|
|
|
|
priority: min
|
|
|
|
finish:
|
2023-07-27 08:38:08 +02:00
|
|
|
title: A borgmatic backup completed successfully
|
2023-07-12 07:10:57 +02:00
|
|
|
message: Nice!
|
|
|
|
tags: borgmatic,+1
|
|
|
|
priority: min
|
|
|
|
fail:
|
2023-07-27 08:38:08 +02:00
|
|
|
title: A borgmatic backup failed
|
2023-07-12 07:10:57 +02:00
|
|
|
message: You should probably fix it
|
|
|
|
tags: borgmatic,-1,skull
|
|
|
|
priority: max
|
|
|
|
states:
|
|
|
|
- start
|
|
|
|
- finish
|
|
|
|
- fail
|
2022-06-09 22:10:34 +02:00
|
|
|
```
|
|
|
|
|
2023-07-12 07:10:57 +02:00
|
|
|
<span class="minilink minilink-addedin">Prior to version 1.8.0</span> Put
|
|
|
|
the `ntfy:` option in the `hooks:` section of your configuration.
|
|
|
|
|
2024-03-11 20:48:58 +01:00
|
|
|
<span class="minilink minilink-addedin">New in version 1.8.9</span> Instead of
|
|
|
|
`username`/`password`, you can specify an [ntfy access
|
|
|
|
token](https://docs.ntfy.sh/config/#access-tokens):
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
ntfy:
|
|
|
|
topic: my-unique-topic
|
|
|
|
server: https://ntfy.my-domain.com
|
|
|
|
access_token: tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2
|
|
|
|
````
|
2023-07-12 07:10:57 +02:00
|
|
|
|
2023-08-25 19:52:00 +02:00
|
|
|
## Loki hook
|
|
|
|
|
2023-08-28 05:30:13 +02:00
|
|
|
<span class="minilink minilink-addedin">New in version 1.8.3</span> [Grafana
|
|
|
|
Loki](https://grafana.com/oss/loki/) is a "horizontally scalable, highly
|
|
|
|
available, multi-tenant log aggregation system inspired by Prometheus."
|
2023-08-25 19:52:00 +02:00
|
|
|
borgmatic has built-in integration with Loki, sending both backup status and
|
|
|
|
borgmatic logs.
|
|
|
|
|
|
|
|
You can configure borgmatic to use either a [self-hosted Loki
|
|
|
|
instance](https://grafana.com/docs/loki/latest/installation/) or [a Grafana
|
|
|
|
Cloud account](https://grafana.com/auth/sign-up/create-user). Start by setting
|
|
|
|
your Loki API push URL. Here's an example:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
loki:
|
|
|
|
url: http://localhost:3100/loki/api/v1/push
|
|
|
|
```
|
|
|
|
|
2023-10-05 04:23:53 +02:00
|
|
|
With this configuration, borgmatic sends its logs to your Loki instance as any
|
2023-08-25 19:52:00 +02:00
|
|
|
of the `prune`, `compact`, `create`, or `check` actions are run. Then, after
|
|
|
|
the actions complete, borgmatic notifies Loki of success or failure.
|
|
|
|
|
|
|
|
This hook supports sending arbitrary labels to Loki. For instance:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
loki:
|
|
|
|
url: http://localhost:3100/loki/api/v1/push
|
|
|
|
|
|
|
|
labels:
|
|
|
|
app: borgmatic
|
|
|
|
hostname: example.org
|
|
|
|
```
|
|
|
|
|
|
|
|
There are also a few placeholders you can optionally use as label values:
|
|
|
|
|
|
|
|
* `__config`: name of the borgmatic configuration file
|
|
|
|
* `__config_path`: full path of the borgmatic configuration file
|
|
|
|
* `__hostname`: the local machine hostname
|
|
|
|
|
|
|
|
These placeholders are only substituted for the whole label value, not
|
|
|
|
interpolated into a larger string. For instance:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
loki:
|
|
|
|
url: http://localhost:3100/loki/api/v1/push
|
|
|
|
|
|
|
|
labels:
|
|
|
|
app: borgmatic
|
|
|
|
config: __config
|
|
|
|
hostname: __hostname
|
|
|
|
```
|
|
|
|
|
2024-03-22 19:25:33 +01:00
|
|
|
Also check out this [Loki dashboard for
|
|
|
|
borgmatic](https://grafana.com/grafana/dashboards/20736-borgmatic-logs/) if
|
|
|
|
you'd like to see your backup logs and statistics in one place.
|
|
|
|
|
2023-08-25 19:52:00 +02:00
|
|
|
|
2023-10-05 04:23:53 +02:00
|
|
|
## Apprise hook
|
|
|
|
|
|
|
|
<span class="minilink minilink-addedin">New in version 1.8.4</span>
|
2023-10-05 18:06:06 +02:00
|
|
|
[Apprise](https://github.com/caronc/apprise/wiki) is a local notification library
|
2023-10-05 04:23:53 +02:00
|
|
|
that "allows you to send a notification to almost all of the most popular
|
|
|
|
[notification services](https://github.com/caronc/apprise/wiki) available to
|
|
|
|
us today such as: Telegram, Discord, Slack, Amazon SNS, Gotify, etc."
|
|
|
|
|
|
|
|
Depending on how you installed borgmatic, it may not have come with Apprise.
|
|
|
|
For instance, if you originally [installed borgmatic with
|
|
|
|
pipx](https://torsion.org/borgmatic/docs/how-to/set-up-backups/#installation),
|
|
|
|
run the following to install Apprise so borgmatic can use it:
|
|
|
|
|
|
|
|
```bash
|
2024-03-11 00:18:49 +01:00
|
|
|
sudo pipx install --force borgmatic[Apprise]
|
2023-10-05 04:23:53 +02:00
|
|
|
```
|
|
|
|
|
2023-10-05 07:54:11 +02:00
|
|
|
Omit `sudo` if borgmatic is installed as a non-root user.
|
|
|
|
|
2023-10-05 04:23:53 +02:00
|
|
|
Once Apprise is installed, configure borgmatic to notify one or more [Apprise
|
|
|
|
services](https://github.com/caronc/apprise/wiki). For example:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
apprise:
|
|
|
|
services:
|
|
|
|
- url: gotify://hostname/token
|
|
|
|
label: gotify
|
|
|
|
- url: mastodons://access_key@hostname/@user
|
|
|
|
label: mastodon
|
|
|
|
```
|
|
|
|
|
|
|
|
With this configuration, borgmatic pings each of the configured Apprise
|
|
|
|
services when a backup begins, ends, or errors, but only when any of the
|
|
|
|
`prune`, `compact`, `create`, or `check` actions are run.
|
|
|
|
|
|
|
|
You can optionally customize the contents of the default messages sent to
|
|
|
|
these services:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
apprise:
|
|
|
|
services:
|
|
|
|
- url: gotify://hostname/token
|
|
|
|
label: gotify
|
|
|
|
start:
|
|
|
|
title: Ping!
|
|
|
|
body: Starting backup process.
|
|
|
|
finish:
|
|
|
|
title: Ping!
|
|
|
|
body: Backups successfully made.
|
|
|
|
fail:
|
|
|
|
title: Ping!
|
|
|
|
body: Your backups have failed.
|
|
|
|
states:
|
|
|
|
- start
|
|
|
|
- finish
|
|
|
|
- fail
|
|
|
|
```
|
|
|
|
|
2024-03-11 00:18:49 +01:00
|
|
|
<span class="minilink minilink-addedin">New in version 1.8.9</span> borgmatic
|
|
|
|
logs are automatically included in the body data sent to your Apprise services
|
|
|
|
when a backup finishes or fails.
|
|
|
|
|
|
|
|
You can customize the verbosity of the logs that are sent with borgmatic's
|
|
|
|
`--monitoring-verbosity` flag. The `--list` and `--stats` flags may also be of
|
|
|
|
use. See `borgmatic create --help` for more information.
|
|
|
|
|
|
|
|
If you don't want any logs sent, you can disable this feature by setting
|
|
|
|
`send_logs` to `false`:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
apprise:
|
|
|
|
services:
|
|
|
|
- url: gotify://hostname/token
|
|
|
|
label: gotify
|
|
|
|
send_logs: false
|
|
|
|
```
|
|
|
|
|
|
|
|
Or to limit the size of logs sent to Apprise services:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
apprise:
|
|
|
|
services:
|
|
|
|
- url: gotify://hostname/token
|
|
|
|
label: gotify
|
|
|
|
logs_size_limit: 500
|
|
|
|
```
|
|
|
|
|
|
|
|
This may be necessary for some services that reject large requests.
|
|
|
|
|
2023-10-05 04:23:53 +02:00
|
|
|
See the [configuration
|
|
|
|
reference](https://torsion.org/borgmatic/docs/reference/configuration/) for
|
|
|
|
details.
|
|
|
|
|
|
|
|
|
2019-10-15 19:49:14 +02:00
|
|
|
## Scripting borgmatic
|
|
|
|
|
|
|
|
To consume the output of borgmatic in other software, you can include an
|
2022-08-18 19:19:11 +02:00
|
|
|
optional `--json` flag with `create`, `rlist`, `rinfo`, or `info` to get the
|
|
|
|
output formatted as JSON.
|
2019-10-15 19:49:14 +02:00
|
|
|
|
|
|
|
Note that when you specify the `--json` flag, Borg's other non-JSON output is
|
|
|
|
suppressed so as not to interfere with the captured JSON. Also note that JSON
|
2023-07-19 08:27:45 +02:00
|
|
|
output only shows up at the console and not in syslog.
|
2019-10-15 19:49:14 +02:00
|
|
|
|
|
|
|
|
2020-01-30 02:08:03 +01:00
|
|
|
### Latest backups
|
|
|
|
|
2022-08-16 00:04:40 +02:00
|
|
|
All borgmatic actions that accept an `--archive` flag allow you to specify an
|
|
|
|
archive name of `latest`. This lets you get the latest archive without having
|
|
|
|
to first run `borgmatic rlist` manually, which can be handy in automated
|
2022-06-03 05:35:39 +02:00
|
|
|
scripts. Here's an example:
|
2020-01-30 02:08:03 +01:00
|
|
|
|
|
|
|
```bash
|
|
|
|
borgmatic info --archive latest
|
|
|
|
```
|