diff --git a/stream8_backups/backup.sh b/stream8_backups/backup.sh index d6aa7b8beb9f826339d9cdddd79437f2a169226b..abda4b772906b387a29596d8312320476827e72b 100755 --- a/stream8_backups/backup.sh +++ b/stream8_backups/backup.sh @@ -7,21 +7,28 @@ source common.sh # Let's just backup $TODAY, ignoring symlink snaps (zero updates) as well EXCLUDE_LIST=`mktemp` RESTIC_LOGFILE=`mktemp` + +$RESTIC snapshots +if [[ $? -ne 0 ]]; then + echo "Lock detected, attempting to unlock" | tee -a $RESTIC_LOGFILE + $RESTIC unlock 2>&1 | tee -a $RESTIC_LOGFILE +fi + find $SOURCE -mindepth 1 -maxdepth 1 \( -type l -o -type d \) ! -path "*$TODAY" > $EXCLUDE_LIST -$RESTIC backup --tag $TODAY --exclude-file=$EXCLUDE_LIST $SOURCE &>> $RESTIC_LOGFILE +echo "Performing backup..." +$RESTIC backup --tag $TODAY --exclude-file=$EXCLUDE_LIST $SOURCE 2>&1 | tee -a $RESTIC_LOGFILE +echo "Backup concluded with exit code $?" rm -f $EXCLUDE_LIST # Check if there are any snapshots to forget/purge +echo "Checking for old snapshots..." SNAPS_TO_REMOVE=`$RESTIC forget --dry-run --group-by paths --keep-within $PRUNE_SNAPSHOTS_OLDER_THAN | grep "remove .* snapshots" | awk '{print $2}'` if [ ! -z $SNAPS_TO_REMOVE ]; then - echo "Found $SNAPS_TO_REMOVE snapshots that are older than $PRUNE_SNAPSHOTS_OLDER_THAN. Purging from restic store ..." >> $RESTIC_LOGFILE - $RESTIC unlock &>> $RESTIC_LOGFILE - $RESTIC forget --group-by paths --keep-within $PRUNE_SNAPSHOTS_OLDER_THAN --prune &>> $RESTIC_LOGFILE + echo "Found $SNAPS_TO_REMOVE snapshots that are older than $PRUNE_SNAPSHOTS_OLDER_THAN. Purging from restic store ..." 2>&1 | tee -a $RESTIC_LOGFILE + $RESTIC unlock 2>&1 | tee -a $RESTIC_LOGFILE + $RESTIC forget --group-by paths --keep-within $PRUNE_SNAPSHOTS_OLDER_THAN --prune 2>&1 | tee -a $RESTIC_LOGFILE fi -# Just in case the log is too big and the mail doesn't make it... -cat $RESTIC_LOGFILE - echo "Sending email of $RESTIC_LOGFILE to admins" export TODAY="$TODAY"