#! /bin/bash REPO="bryan@172.16.1.83:~/borg-backups" PASSPHRASE="uD6Db2MrhxdCoKmD4gpW" SSH_KEY="/mnt/data/home/bryan/.ssh/id_rsa" EXCLUDE_FILE="./backup-exclude" DIR_TO_BACKUP="/" export BORG_REPO="${REPO}" export BORG_PASSPHRASE="${PASSPHRASE}" export BORG_RSH="ssh -i ${SSH_KEY}" info(){ printf "\n%s %s\n\n" "$( date )" "$*" >&2; } trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM info "Starting backup" borg create \ --verbose \ --filter AME \ --list \ --stats \ --show-rc \ --compression lz4 \ --exclude-caches \ --exclude-from "${EXCLUDE_FILE}" \ ::'{hostname}-{now}' \ "${DIR_TO_BACKUP}" backup_exit=$? info "Pruning repository" borg prune \ --list \ --prefix '{hostname}-' \ --show-rc \ --keep-daily 7 \ --keep-weekly 4 \ --keep-monthly 6 \ prune_exit=$? # use highest exit code as global exit code global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit )) if [ ${global_exit} -eq 0 ]; then info "Backup and Prune finished successfully" elif [ ${global_exit} -eq 1 ]; then info "Backup and/or Prune finished with warnings" else info "Backup and/or Prune finished with errors" fi exit ${global_exit}