ToolBox/borg-file-backup.sh

54 lines
1.2 KiB
Bash

#!/bin/sh
# Borg repo location
REPOSITORY=/var/backup/files.borg/
# Example of remote repo
# REPOSITORY=ssh://backuper@192.168.1.100/var/backup/files.borg/
borgDoBackup() {
echo "`date +[%F/%T]` Starting the backup"
borg create -v --compression lzma,6 --stats $REPOSITORY::`date +%Y-%m-%d-%H:%M` /etc/ /var/www/ /var/spool/ --exclude=*.log
borg prune -v $REPOSITORY --keep-daily=3 --keep-weekly=2 --keep-monthly=12
echo "`date +[%F/%T]` Done!"
}
repoid=$(grep "id" $REPOSITORY/config | awk '{print $3}')
procid=$(pgrep borg | tail -1)
if [ -d $REPOSITORY/lock.exclusive ] || [ -d /root/.cache/borg/$repoid/lock.exclusive ]; then
if [ ! -z $procid ]; then
echo "`date +[%F/%T]` Seems like the borg repo is busy at the moment, I will try again in 30 min"
at now + 30 minutes -f $0
exit
else
if [ -d $REPOSITORY/lock.exclusive ]; then
rm -r $REPOSITORY/lock.*
fi
if [ -d /root/.cache/borg/$repoid/lock.exclusive ]; then
rm -r /root/.cache/borg/$repoid/lock.*
fi
borgDoBackup
fi
else
borgDoBackup
fi
exit