Compare commits

..

No commits in common. "bcd39666f41458b8ac943966e27af7ccb42327db" and "998687fdbe6f0b8978af2c6d099a4a4ebe3df4b5" have entirely different histories.

4 changed files with 20 additions and 25 deletions

View file

@ -1,6 +1,9 @@
#! /bin/bash
set -uo pipefail
#backup li run
#backup li
display_usage() {
echo "Usage: $0 <repo> (local|monitor <host> <warning> <critical>|restic arguments)" >&2
}
@ -10,6 +13,7 @@ if [ "$#" -lt 2 ]; then
exit 1
fi
TARGET=$1
ACTION=$2
RESTIC=$(which restic)
@ -31,20 +35,19 @@ check_config() {
echo "Restic binary not found"
exit 1
fi
}
handle_params () {
. /etc/backup/local.config
if [ $2 == "local" ]; then
do_local_backup
elif [ $2 == "monitor" ]; then
do_monitor $@
else
shift 1
# define an empty default if RESTIC_ARGS is not set
RESTIC_ARGS=${RESTIC_ARGS:-""}
$RESTIC $RESTIC_ARGS $@
$RESTIC $@
fi
}
@ -57,14 +60,11 @@ do_local_backup () {
. /etc/backup/local.config
# define an empty default if BACKUP_ARGS is not set
BACKUP_ARGS=${BACKUP_ARGS:-""}
if [[ -x /etc/backup/local.pre ]]; then
/etc/backup/local.pre $TARGET
fi
$RESTIC --exclude-file /etc/backup/local.exclude backup --host $BACKUP_HOSTNAME $BACKUP_ARGS $BACKUP_DIR
$RESTIC --exclude-file /etc/backup/local.exclude backup --hostname $BACKUP_HOSTNAME $BACKUP_DIR
if [[ -x /etc/backup/local.post ]]; then
/etc/backup/local.post $TARGET
@ -85,12 +85,8 @@ do_monitor () {
WARN=$4
CRIT=$5
# define an empty default if RESTIC_ARGS is not set
RESTIC_ARGS=${RESTIC_ARGS:-""}
SNAPS=`$RESTIC $RESTIC_ARGS snapshots --compact --no-lock -H $3`
# Get last line and parse into variables. Removes header and is empty when no snapshot exists for host
LAST=`sed 1,2d <<< $SNAPS | head -n -2 | tail -n 1`
COUNT=`tail -n 1 <<< $SNAPS | cut -d " " -f 1`
LAST=`$RESTIC snapshots --compact --no-lock -H $3 | sed 1,2d | tail -n 1`
if [ ! $? -eq 0 ]; then
echo "WARNING - restic command returned an error"
exit 1;
@ -113,13 +109,12 @@ do_monitor () {
BACKUP_TST=$(date -d "$DATE $TIME" +"%s" )
;;
esac
NOW_TST=$(date +%s)
DIFF_S=`expr $NOW_TST - $BACKUP_TST`
DIFF_H=`expr $DIFF_S / 3600`
MESSAGE="Last snapshot #$HASH ${DIFF_H}h ago|snapshots=$COUNT; age=$DIFF_H"
MESSAGE="Last snapshot #$HASH ${DIFF_H}h ago"
RET=0
RET_H="OK"
@ -138,5 +133,9 @@ do_monitor () {
return $RET
}
check_config $@
handle_params $@

View file

@ -1,5 +1,3 @@
BACKUP_HOSTNAME=$(hostname -f)
BACKUP_HOSTNAME="backuphost.example.org"
BACKUP_DIR="/"
BACKUP_ARGS="--tag filesystem"
# HEALTHCHECK_URL="<URL from https://healthchecks.io/checks/ to notify>"
# RESTIC_ARGS="<optional restic args appended to all commands>"

View file

@ -1 +0,0 @@
# run commands after the backup (script must be executable)

View file

@ -1 +0,0 @@
# run commands before the backup (script must be executable)