2 # I, Ian Kelling, follow the GNU license recommendations at
3 # https://www.gnu.org/licenses/license-recommendations.en.html. They
4 # recommend that small programs, < 300 lines, be licensed under the
5 # Apache License 2.0. This file contains or is part of one or more small
6 # programs. If a small program grows beyond 300 lines, I plan to switch
9 # Copyright 2024 Ian Kelling
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
15 # http://www.apache.org/licenses/LICENSE-2.0
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
24 source /a
/bin
/bash-bear-trap
/bash-bear
26 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
29 err
() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $pre: $*" >&2; }
31 ## begin check on syncthing
32 if ! systemctl show
--no-page syncthing@ziva |
sed -n 's/^MainPID=//p' |
grep -E '^[0-9]+$' &>/dev
/null
; then
33 err no pid
for syncthing@ziva. systemctl status
:
34 systemctl status syncthing@ziva
36 ## end check on syncthing
39 ## begin check on btrbk
40 age_limit_sec
=$
(( 60 * 60 * 24 * 7 )) # 7 days.
41 for prefix
in root boot
; do
42 if [[ $prefix == boot
]]; then
43 # its not uncommon for the /boot subvol to have no changes, and thus
44 # no new backups for 10 days or so. todo: instead of this error
45 # prone check, we should make it so the ziva computer will
46 # touch a file on our computer whenever btrbk succeeds
47 age_limit_sec
=$
(( age_limit_sec
+ 60* 60 * 24 * 35 ))
49 vol
=${prefix}_ubuntubionic
50 snaps
=(/mnt
/r
7/amy
/$prefix/btrbk
/${vol}.20*)
51 if [[ ! ${snaps[*]} ]]; then
52 err no snapshots starting with
/mnt
/r
7/amy
/$prefix/btrbk
/${vol}.20
56 read -r last_snap_sec last_snap
< <(
57 for s
in ${snaps[@]}; do
59 unix_time
=$
(date -d "$(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${f#"$vol".})" +%s
)
60 printf "%s %s\n" $unix_time $s # part of the pipeline
61 done |
sort -r |
head -n 1 ||
:
63 if [[ ! $last_snap ]]; then
65 err
"could not find latest snapshot for $vol among ${snaps[*]}"
68 if (( last_snap_sec
< EPOCHSECONDS
- age_limit_sec
)); then
69 err vol
$vol last backup older than
50 hours
: $last_snap