From 2115e9b64688cc41a67ed2405b6124ae5ef2990a Mon Sep 17 00:00:00 2001 From: Dave Lane Date: Mon, 14 Oct 2019 04:29:44 +0000 Subject: [PATCH] added functions and test for DST variable being set --- run-restic.sh | 50 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/run-restic.sh b/run-restic.sh index 981358f..d75bd5b 100755 --- a/run-restic.sh +++ b/run-restic.sh @@ -3,34 +3,58 @@ # OER Foundation backup routine: Restic # 20190930 dave@oerfoundation.org # +# Defaults NICE='ionice -c2 nice -n19' CMD=/usr/bin/restic SCR=$0 CONF=site.conf DIR=`dirname $SCR` SCRNAME=`basename $SCR` -if [ -f $DIR/$CONF ] ; then +PW=/root/restic.pw +TAG="daily" +LOG=/var/log/restic.log +# +# functions +timestamp() { + # a timestamp for logging purposes + TIMESTAMP=`date '+%Y-%m-%d %H:%M.%S'` +} +# +# function to direct a message... +log() { + # + # a timestamp for logging purposes + timestamp + if test -w $LOG ; then + echo "$SCRNAME: $TIMESTAMP $@" >> $LOG + fi +} +# +# provide the DST and override defaults +if test -f $DIR/$CONF ; then source $DIR/$CONF + if test -n $DST ; then + log "creating a snapshot: $DST" + else + log "no destination (DST) provided - you must define DST in $DIR/$CONF for this script to run." + error 1 + fi else echo "You need to create a site.conf in the same directory as $SCRNAME, i.e. $DIR." exit 1 fi -DST=sftp:try.oerfoundation.org:/backup/make -PW=/root/restic.pw -TAG="daily" -LOG=/var/log/restic.log +# commands to... +# run the snapshot ARGS="-r $DST --password-file $PW backup --tag $TAG --exclude-file=/restic.excludes --files-from /restic.files" +# clean up old snapshots CLEAN="-r $DST --password-file $PW forget --tag $TAG --keep-daily 7 --keep-weekly 5 --keep-monthly 12 --keep-yearly 7" # create a snapshot -DATE=`date` -echo "running snapshot $DATE" >> $LOG +log "running snapshot" $NICE $CMD $ARGS >> $LOG # remove old snapshots -DATE=`date` -echo "running cleanup $DATE" >> $LOG +log "running cleanup" $NICE $CMD $CLEAN >> $LOG # leave extra spaces -DATE=`date` -echo "done $DATE" >> $LOG -echo "" >> $LOG -echo "" >> $LOG +log "done" +log "" +log ""