restic-backup/run-restic.sh

67 lines
1.6 KiB
Bash
Raw Permalink Normal View History

#!/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() {
2019-10-14 17:31:29 +13:00
# a timestamp for logging purposes
TIMESTAMP=`date '+%Y-%m-%d %H:%M.%S'`
}
#
# function to direct a message...
log() {
2019-10-14 17:31:29 +13:00
#
# a timestamp for logging purposes
timestamp
if test -w $LOG ; then
echo "$SCRNAME: $TIMESTAMP $@" >> $LOG
fi
}
2019-10-14 17:31:29 +13:00
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
2022-08-26 10:53:44 +12:00
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
2022-08-26 11:08:46 +12:00
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"
2019-10-14 17:31:29 +13:00
space