From 450165ed996fc9c79fc41911e71267282157af16 Mon Sep 17 00:00:00 2001 From: Felix Bartels Date: Sun, 21 Jan 2018 11:28:14 +0100 Subject: [PATCH 1/3] remove obsolete comment and trim unnecessary whitespace and lines Signed-off-by: Felix Bartels --- bin/backup | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/bin/backup b/bin/backup index 94787a0..2a8d154 100755 --- a/bin/backup +++ b/bin/backup @@ -1,19 +1,15 @@ #! /bin/bash set -uo pipefail -#backup li run -#backup li - -display_usage() { +display_usage() { echo "Usage: $0 (local|monitor |restic arguments)" >&2 -} +} if [ "$#" -lt 2 ]; then display_usage exit 1 fi - TARGET=$1 ACTION=$2 RESTIC=$(which restic) @@ -26,7 +22,7 @@ check_config() { exit 1 else set -a - source $CONFIG + source $CONFIG set +a fi @@ -35,8 +31,6 @@ check_config() { echo "Restic binary not found" exit 1 fi - - } handle_params () { @@ -64,7 +58,7 @@ do_local_backup () { /etc/backup/local.pre $TARGET fi - $RESTIC --exclude-file /etc/backup/local.exclude backup --hostname $BACKUP_HOSTNAME $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 @@ -94,7 +88,7 @@ do_monitor () { IFS=' ' read HASH DATE TIME HOST DIR <<< "$LAST" - if [ -z "$HASH" ]; then + if [ -z "$HASH" ]; then echo "UNKNOWN - No snapshot found for $3" exit 4; fi @@ -109,6 +103,7 @@ do_monitor () { BACKUP_TST=$(date -d "$DATE $TIME" +"%s" ) ;; esac + NOW_TST=$(date +%s) DIFF_S=`expr $NOW_TST - $BACKUP_TST` @@ -124,7 +119,7 @@ do_monitor () { elif [ $DIFF_H -lt $CRIT ]; then RET=1 RET_H="WARNING" - else + else RET=2 RET_H="CRITICAL" @@ -133,9 +128,5 @@ do_monitor () { return $RET } - - check_config $@ handle_params $@ - - From 448b04a3da2302a90886d851cd48bd2be8c132c4 Mon Sep 17 00:00:00 2001 From: Felix Bartels Date: Sun, 21 Jan 2018 11:35:15 +0100 Subject: [PATCH 2/3] add example pre and post scripts Signed-off-by: Felix Bartels --- etc/backup/local.post | 1 + etc/backup/local.pre | 1 + 2 files changed, 2 insertions(+) create mode 100755 etc/backup/local.post create mode 100755 etc/backup/local.pre diff --git a/etc/backup/local.post b/etc/backup/local.post new file mode 100755 index 0000000..25de5db --- /dev/null +++ b/etc/backup/local.post @@ -0,0 +1 @@ +# run commands after the backup (script must be executable) diff --git a/etc/backup/local.pre b/etc/backup/local.pre new file mode 100755 index 0000000..24cd2f9 --- /dev/null +++ b/etc/backup/local.pre @@ -0,0 +1 @@ +# run commands before the backup (script must be executable) From 696f416aa2cd396a0494124f17c1db0674411815 Mon Sep 17 00:00:00 2001 From: Felix Bartels Date: Sun, 21 Jan 2018 11:39:00 +0100 Subject: [PATCH 3/3] introduce new config option BACKUP_ARGS to add additional parameters to backup job (like tagging the backup) new option is set to empty if not specified otherwise. as suggested in https://github.com/binarybucks/restic-tools/pull/14#issuecomment-359700589 Signed-off-by: Felix Bartels --- bin/backup | 5 ++++- etc/backup/local.config | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/backup b/bin/backup index 2a8d154..13a07e0 100755 --- a/bin/backup +++ b/bin/backup @@ -54,11 +54,14 @@ 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 --hostname $BACKUP_HOSTNAME $BACKUP_DIR + $RESTIC --exclude-file /etc/backup/local.exclude backup --hostname $BACKUP_HOSTNAME $BACKUP_ARGS $BACKUP_DIR if [[ -x /etc/backup/local.post ]]; then /etc/backup/local.post $TARGET diff --git a/etc/backup/local.config b/etc/backup/local.config index 6f37118..a59749c 100644 --- a/etc/backup/local.config +++ b/etc/backup/local.config @@ -1,3 +1,4 @@ BACKUP_HOSTNAME="backuphost.example.org" BACKUP_DIR="/" +BACKUP_ARGS="--tag filesystem" # HEALTHCHECK_URL=""