added functions and test for DST variable being set
This commit is contained in:
parent
0d540cc3ab
commit
2115e9b646
1 changed files with 37 additions and 13 deletions
|
@ -3,34 +3,58 @@
|
||||||
# OER Foundation backup routine: Restic
|
# OER Foundation backup routine: Restic
|
||||||
# 20190930 dave@oerfoundation.org
|
# 20190930 dave@oerfoundation.org
|
||||||
#
|
#
|
||||||
|
# Defaults
|
||||||
NICE='ionice -c2 nice -n19'
|
NICE='ionice -c2 nice -n19'
|
||||||
CMD=/usr/bin/restic
|
CMD=/usr/bin/restic
|
||||||
SCR=$0
|
SCR=$0
|
||||||
CONF=site.conf
|
CONF=site.conf
|
||||||
DIR=`dirname $SCR`
|
DIR=`dirname $SCR`
|
||||||
SCRNAME=`basename $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
|
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
|
else
|
||||||
echo "You need to create a site.conf in the same directory as $SCRNAME, i.e. $DIR."
|
echo "You need to create a site.conf in the same directory as $SCRNAME, i.e. $DIR."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
DST=sftp:try.oerfoundation.org:/backup/make
|
# commands to...
|
||||||
PW=/root/restic.pw
|
# run the snapshot
|
||||||
TAG="daily"
|
|
||||||
LOG=/var/log/restic.log
|
|
||||||
ARGS="-r $DST --password-file $PW backup --tag $TAG --exclude-file=/restic.excludes --files-from /restic.files"
|
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"
|
CLEAN="-r $DST --password-file $PW forget --tag $TAG --keep-daily 7 --keep-weekly 5 --keep-monthly 12 --keep-yearly 7"
|
||||||
# create a snapshot
|
# create a snapshot
|
||||||
DATE=`date`
|
log "running snapshot"
|
||||||
echo "running snapshot $DATE" >> $LOG
|
|
||||||
$NICE $CMD $ARGS >> $LOG
|
$NICE $CMD $ARGS >> $LOG
|
||||||
# remove old snapshots
|
# remove old snapshots
|
||||||
DATE=`date`
|
log "running cleanup"
|
||||||
echo "running cleanup $DATE" >> $LOG
|
|
||||||
$NICE $CMD $CLEAN >> $LOG
|
$NICE $CMD $CLEAN >> $LOG
|
||||||
# leave extra spaces
|
# leave extra spaces
|
||||||
DATE=`date`
|
log "done"
|
||||||
echo "done $DATE" >> $LOG
|
log ""
|
||||||
echo "" >> $LOG
|
log ""
|
||||||
echo "" >> $LOG
|
|
||||||
|
|
Loading…
Reference in a new issue