X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=ziva-backup-check;h=2a68af87dfb1769f93b060eeb6b235d342a97e40;hb=HEAD;hp=3db63fcd253a9bf743ebf4a3a1ec531c1bde7dc1;hpb=6cc73025405b7a540eec371d1d8f7d9d13d8e019;p=distro-setup diff --git a/ziva-backup-check b/ziva-backup-check index 3db63fc..2a68af8 100755 --- a/ziva-backup-check +++ b/ziva-backup-check @@ -1,8 +1,27 @@ #!/bin/bash -# Copyright (C) 2019 Ian Kelling -# SPDX-License-Identifier: AGPL-3.0-or-later +# I, Ian Kelling, follow the GNU license recommendations at +# https://www.gnu.org/licenses/license-recommendations.en.html. They +# recommend that small programs, < 300 lines, be licensed under the +# Apache License 2.0. This file contains or is part of one or more small +# programs. If a small program grows beyond 300 lines, I plan to switch +# its license to GPL. -source /a/bin/errhandle/err +# Copyright 2024 Ian Kelling + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +source /a/bin/bash-bear-trap/bash-bear [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" @@ -10,7 +29,7 @@ pre="${0##*/}:" err() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $pre: $*" >&2; } ## begin check on syncthing -if ! systemctl show --no-page syncthing@ziva | sed -n 's/^MainPID=//p' | egrep '^[0-9]+$' &>/dev/null; then +if ! systemctl show --no-page syncthing@ziva | sed -n 's/^MainPID=//p' | grep -E '^[0-9]+$' &>/dev/null; then err no pid for syncthing@ziva. systemctl status: systemctl status syncthing@ziva fi @@ -34,16 +53,16 @@ for prefix in root boot; do break fi - read last_snap_sec last_snap < <( + read -r last_snap_sec last_snap < <( for s in ${snaps[@]}; do f=${s##*/} - unix_time=$(date -d $(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${f#$vol.}) +%s) + unix_time=$(date -d "$(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${f#"$vol".})" +%s) printf "%s %s\n" $unix_time $s # part of the pipeline done | sort -r | head -n 1 ||: ) if [[ ! $last_snap ]]; then # should not happen. - err "could not find latest snapshot for $svp among ${snaps[*]}" + err "could not find latest snapshot for $vol among ${snaps[*]}" exit 1 fi if (( last_snap_sec < EPOCHSECONDS - age_limit_sec )); then