#86 Add option to show last successful backup

Закрито
1 рік тому відкрито varac · 12 коментарів
varac прокоментував(ла) 1 рік тому

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 прокоментував(ла) 1 рік тому
Власник

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]' ```
thomasleveil прокоментував(ла) 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 прокоментував(ла) 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, $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 прокоментував(ла) 1 рік тому
Власник

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 прокоментував(ла) 1 рік тому
Автор

@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 прокоментував(ла) 1 рік тому
Власник

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 прокоментував(ла) 11 місяці тому

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
witten прокоментував(ла) 2 місяці тому
Власник

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!
varac прокоментував(ла) 2 місяці тому
Автор

@witten: Awesome !!

@witten: Awesome !!
varac прокоментував(ла) 2 місяці тому
Автор

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
witten прокоментував(ла) 2 місяці тому
Власник
Cool! Docs are here: https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#successful-backups
witten прокоментував(ла) 1 місяць тому
Власник
#224

:disappointed:

https://projects.torsion.org/witten/borgmatic/issues/224 :disappointed:
Підпишіться щоб приєднатися до обговорення.
Етап відсутній
Немає виконавеця
4 учасників
Дата завершення

Термін виконання не встановлений.

Залежності

Ця проблема в даний час не має залежностей.

Завантаження…
Відмінити
Зберегти
Тут ще немає жодного змісту.