Blob Blame History Raw
#!/bin/bash

. $(dirname $0)/borg-backup-env

errorexit() {
    mail -s 'BorgBackup' root < $LOG
    exit $?
}

##
## write output to logfile
##

exec > >(tee -i ${LOG})
exec 2>&1

echo "###### Backup started: $(date) ######"

##
## You can do some tasks before starting the backup here, for example
## - create a list of installed software
## - create database dumps
##

##
## Transfer files to repository
##

borg create -v --stats                   \
    --compression zstd,18                \
    $REPOSITORY::'{now:%Y-%m-%d_%H-%M}'  \
    /                                    \
    --exclude /backup                    \
    --exclude /dev                       \
    --exclude /lost+found                \
    --exclude /mnt                       \
    --exclude /proc                      \
    --exclude /run                       \
    --exclude /sys                       \
    --exclude /var/run                   \
|| { echo "Error $? during backup, aborting" ; errorexit 1; }

echo
echo
echo "Deleting old backups..."
borg prune                          \
    --stats                         \
    --list                          \
    --keep-hourly   12              \
    --keep-daily    7               \
    --keep-weekly   4               \
    --keep-monthly  6               \
|| { echo "Error $? while deleting old backups, aborting" ; errorexit 2; }

echo "###### Backup finished: $(date) ######"

errorexit 0