2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
5 source /a
/bin
/errhandle
/err
7 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
10 err
() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $pre: $*" >&2; }
12 ## begin check on syncthing
13 if ! systemctl show
--no-page syncthing@ziva |
sed -n 's/^MainPID=//p' |
egrep '^[0-9]+$' &>/dev
/null
; then
14 err no pid
for syncthing@ziva. systemctl status
:
15 systemctl status syncthing@ziva
17 ## end check on syncthing
20 ## begin check on btrbk
21 age_limit_sec
=$
(( 60 * 60 * 24 * 7 )) # 7 days.
22 for prefix
in root boot
; do
23 if [[ $prefix == boot
]]; then
24 # its not uncommon for the /boot subvol to have no changes, and thus
25 # no new backups for 10 days or so. todo: instead of this error
26 # prone check, we should make it so the ziva computer will
27 # touch a file on our computer whenever btrbk succeeds
28 age_limit_sec
=$
(( age_limit_sec
+ 60* 60 * 24 * 35 ))
30 vol
=${prefix}_ubuntubionic
31 snaps
=(/mnt
/r
7/amy
/$prefix/btrbk
/${vol}.20*)
32 if [[ ! ${snaps[*]} ]]; then
33 err no snapshots starting with
/mnt
/r
7/amy
/$prefix/btrbk
/${vol}.20
37 read last_snap_sec last_snap
< <(
38 for s
in ${snaps[@]}; do
40 unix_time
=$
(date -d $
(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${f#$vol.}) +%s
)
41 printf "%s %s\n" $unix_time $s # part of the pipeline
42 done |
sort -r |
head -n 1 ||
:
44 if [[ ! $last_snap ]]; then
46 err
"could not find latest snapshot for $svp among ${snaps[*]}"
49 if (( last_snap_sec
< EPOCHSECONDS
- age_limit_sec
)); then
50 err vol
$vol last backup older than
50 hours
: $last_snap