#!/bin/bash # # 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` 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 } space() { echo "" >> $LOG echo "" >> $LOG } # # 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 # 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 --prune --cleanup-cache --tag $TAG --keep-daily 4 --keep-weekly 3 --keep-monthly 6 --keep-yearly 3" # prune 'forgotten' snapshots PRUNE="-r $DST --password-file $PW prune" # create a snapshot log "running snapshot" $NICE $CMD $ARGS >> $LOG # remove old snapshots log "running cleanup" $NICE $CMD $CLEAN >> $LOG $NICE $CMD $PRUNE >> $LOG # leave extra spaces log "done" space