#86 Add option to show last successful backup

Open
opened 11 months ago by varac · 7 comments
varac commented 11 months ago

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.
witten commented 11 months ago
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]' ```

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} ) )) ```
varac commented 11 months ago
Poster

@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 ```
witten commented 11 months ago
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.
varac commented 11 months ago
Poster

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

@witten: Nice! I agree this would be good to integrate into borgmatic.
witten commented 9 months ago
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 ```
henfri commented 6 months ago

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
Sign in to join this conversation.
No Milestone
No Assignees
4 Participants
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
Cancel
Save
There is no content yet.