I need to integrate a check for successful backups in our monitoring system.
If would be nice if borgmatic could have a command like borgmatic --last-success containing the details (time, archive name) of the last successful backup (excluding checkpoint archives).
I agree with the borg maintainer: it seems like this is rather something for a on-top-of-borg management tool., which is why I’m asking here for implementation.
from https://github.com/borgbackup/borg/issues/4047:
I need to integrate a check for successful backups in our monitoring system.
If would be nice if borgmatic could have a command like `borgmatic --last-success` containing the details (time, archive name) of the last successful backup (excluding checkpoint archives).
I agree with the borg maintainer: `it seems like this is rather something for a on-top-of-borg management tool.`, which is why I'm asking here for implementation.
Or, if you want to get that in JSON form, and are using using a recent version of jq:
borgmatic --list --json | jq '.[0].archives[-1]'
Will this do it?
```shell
borgmatic --list | tail -n 1
```
Or, if you want to get that in JSON form, and are using using a recent version of [jq](https://stedolan.github.io/jq/):
```shell
borgmatic --list --json | jq '.[0].archives[-1]'
```
Here’s an snippet from a bash script I use for monitoring the age of the last archive with borg:
local repo="/var/borgbackup/some/borg/repo"
last_archive_timestamp=$(borg list "$repo" --lock-wait 30 --last 1 --json | jq --raw-output '.archives[0].time' | date +%s -f -)
age=$(( ( $(date +%s) - ${last_archive_timestamp} ) ))
Here's an snippet from a bash script I use for monitoring the age of the last archive with borg:
```bash
local repo="/var/borgbackup/some/borg/repo"
last_archive_timestamp=$(borg list "$repo" --lock-wait 30 --last 1 --json | jq --raw-output '.archives[0].time' | date +%s -f -)
age=$(( ( $(date +%s) - ${last_archive_timestamp} ) ))
```
@witten, $thomasleveil: Using --last 1 will eventually show a checkpoint archive, which I not consider a successful archive.
I now use this to show the last successful backup timestamp in the repo:
borg list --sort timestamp --format '{time}{TAB}{name}{NEWLINE}' $REPOSITORY | grep -v '\.checkpoint$' | tail -1 | cut -f 1
@witten, $thomasleveil: Using `--last 1` will eventually show a checkpoint archive, which I not consider a successful archive.
I now use this to show the last successful backup timestamp in the repo:
```
borg list --sort timestamp --format '{time}{TAB}{name}{NEWLINE}' $REPOSITORY | grep -v '\.checkpoint$' | tail -1 | cut -f 1
```
But that’s not very ergonomic, so I could see the utility in having a feature like this more baked into borgmatic.
Well, I convinced myself it's possible to get the timestamp of the most recent non-checkpoint archive with jq:
```
borgmatic --list --json | jq -r '.[0].archives | map(select(.name | test("\\.checkpoint$") | not)) | last | .time'
```
But that's not very ergonomic, so I could see the utility in having a feature like this more baked into borgmatic.
Mentioned another implementation idea for this ticket in comments on #97. Basically, the “gimme the last successful backup” feature could be in a separate piped command that specializes in dealing with and parsing Borg JSON output. Example:
Mentioned another implementation idea for this ticket in comments on #97. Basically, the "gimme the last successful backup" feature *could* be in a separate piped command that specializes in dealing with and parsing Borg JSON output. Example:
```bash
borgmatic --list | print-only-the-last-successful-archive
```
one point that I see as a problem with relying on borg list is, that the backup target may be offline. Thus, I suggest to cache this information. I.e. borgmatic --list would just print the output of the borg list command that is run after each borgmatic run.
Greetings,
Hendrik
Hello,
one point that I see as a problem with relying on borg list is, that the backup target may be offline. Thus, I suggest to cache this information. I.e. borgmatic --list would just print the output of the borg list command that is run after each borgmatic run.
Greetings,
Hendrik
Just released borgmatic 1.3.24 with a new borgmatic list --successful flag to hopefully satisfy this ask. It simply excludes Borg checkpoint archives from the list. So if you want just the last one, you can do something like this:
borgmatic list --successful --last 1
And then of course you can use --json if you’d like to parse out additional information about a particular archive (like the time).
Let me know how this works for you!
Just released borgmatic 1.3.24 with a new `borgmatic list --successful` flag to hopefully satisfy this ask. It simply excludes Borg checkpoint archives from the list. So if you want just the last one, you can do something like this:
```bash
borgmatic list --successful --last 1
```
And then of course you can use `--json` if you'd like to parse out additional information about a particular archive (like the time).
Let me know how this works for you!
from https://github.com/borgbackup/borg/issues/4047:
I need to integrate a check for successful backups in our monitoring system.
If would be nice if borgmatic could have a command like
borgmatic --last-success
containing the details (time, archive name) of the last successful backup (excluding checkpoint archives).I agree with the borg maintainer:
it seems like this is rather something for a on-top-of-borg management tool.
, which is why I’m asking here for implementation.Will this do it?
Or, if you want to get that in JSON form, and are using using a recent version of jq:
Here’s an snippet from a bash script I use for monitoring the age of the last archive with borg:
@witten, $thomasleveil: Using
--last 1
will eventually show a checkpoint archive, which I not consider a successful archive.I now use this to show the last successful backup timestamp in the repo:
Well, I convinced myself it’s possible to get the timestamp of the most recent non-checkpoint archive with jq:
But that’s not very ergonomic, so I could see the utility in having a feature like this more baked into borgmatic.
@witten: Nice! I agree this would be good to integrate into borgmatic.
Mentioned another implementation idea for this ticket in comments on #97. Basically, the “gimme the last successful backup” feature could be in a separate piped command that specializes in dealing with and parsing Borg JSON output. Example:
Hello,
one point that I see as a problem with relying on borg list is, that the backup target may be offline. Thus, I suggest to cache this information. I.e. borgmatic --list would just print the output of the borg list command that is run after each borgmatic run.
Greetings, Hendrik
Just released borgmatic 1.3.24 with a new
borgmatic list --successful
flag to hopefully satisfy this ask. It simply excludes Borg checkpoint archives from the list. So if you want just the last one, you can do something like this:And then of course you can use
--json
if you’d like to parse out additional information about a particular archive (like the time).Let me know how this works for you!
@witten: Awesome !!
This shows the time the last successful backup was made:
Cool! Docs are here: https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#successful-backups
:disappointed: