2019-10-14 15:54:32 +13:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# OER Foundation backup routine: Restic
|
|
|
|
# 20190930 dave@oerfoundation.org
|
|
|
|
#
|
2019-10-14 17:29:44 +13:00
|
|
|
# Defaults
|
2019-10-14 15:54:32 +13:00
|
|
|
NICE='ionice -c2 nice -n19'
|
|
|
|
CMD=/usr/bin/restic
|
|
|
|
SCR=$0
|
|
|
|
CONF=site.conf
|
|
|
|
DIR=`dirname $SCR`
|
|
|
|
SCRNAME=`basename $SCR`
|
2019-10-14 17:29:44 +13:00
|
|
|
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'`
|
2019-10-14 17:29:44 +13:00
|
|
|
}
|
|
|
|
#
|
|
|
|
# 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:29:44 +13:00
|
|
|
}
|
2019-10-14 17:31:29 +13:00
|
|
|
space() {
|
|
|
|
echo "" >> $LOG
|
|
|
|
echo "" >> $LOG
|
|
|
|
}
|
2019-10-14 17:29:44 +13:00
|
|
|
#
|
|
|
|
# provide the DST and override defaults
|
|
|
|
if test -f $DIR/$CONF ; then
|
2019-10-14 15:54:32 +13:00
|
|
|
source $DIR/$CONF
|
2019-10-14 17:29:44 +13:00
|
|
|
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
|
2019-10-14 15:54:32 +13:00
|
|
|
else
|
|
|
|
echo "You need to create a site.conf in the same directory as $SCRNAME, i.e. $DIR."
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-10-14 17:29:44 +13:00
|
|
|
# commands to...
|
|
|
|
# run the snapshot
|
2019-10-14 15:54:32 +13:00
|
|
|
ARGS="-r $DST --password-file $PW backup --tag $TAG --exclude-file=/restic.excludes --files-from /restic.files"
|
2019-10-14 17:29:44 +13:00
|
|
|
# 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"
|
2022-08-26 10:48:22 +12:00
|
|
|
# prune 'forgotten' snapshots
|
2022-08-26 11:08:46 +12:00
|
|
|
PRUNE="-r $DST --password-file $PW prune"
|
2019-10-14 15:54:32 +13:00
|
|
|
# create a snapshot
|
2019-10-14 17:29:44 +13:00
|
|
|
log "running snapshot"
|
2019-10-14 15:54:32 +13:00
|
|
|
$NICE $CMD $ARGS >> $LOG
|
|
|
|
# remove old snapshots
|
2019-10-14 17:29:44 +13:00
|
|
|
log "running cleanup"
|
2019-10-14 15:54:32 +13:00
|
|
|
$NICE $CMD $CLEAN >> $LOG
|
2022-08-26 10:48:22 +12:00
|
|
|
$NICE $CMD $PRUNE >> $LOG
|
2019-10-14 15:54:32 +13:00
|
|
|
# leave extra spaces
|
2019-10-14 17:29:44 +13:00
|
|
|
log "done"
|
2019-10-14 17:31:29 +13:00
|
|
|
space
|