Add option to show last successful backup #86

Closed
opened 2018-08-15 21:17:57 +00:00 by varac · 12 comments

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.

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.
Owner

Will this do it?

borgmatic --list | tail -n 1

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]' ```
Contributor

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} ) )) ```
Author

@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 ```
Owner

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.

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.
Author

@witten: Nice! I agree this would be good to integrate into borgmatic.

@witten: Nice! I agree this would be good to integrate into borgmatic.
Owner

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:

borgmatic --list | print-only-the-last-successful-archive
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 ```

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

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
Owner

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!
Author

@witten: Awesome !!

@witten: Awesome !!
Author

This shows the time the last successful backup was made:

 borgmatic list --successful --last 1 --json | jq .[0].archives[0].time
This shows the time the last successful backup was made: borgmatic list --successful --last 1 --json | jq .[0].archives[0].time
Owner
Cool! Docs are here: https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#successful-backups
Owner
https://projects.torsion.org/witten/borgmatic/issues/224 :disappointed:
Sign in to join this conversation.
No Milestone
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: borgmatic-collective/borgmatic#86
No description provided.