commit c8def429cdd397e52bed2cd22263857f3573a25c Author: Bryan Date: Wed Jun 24 10:09:07 2020 -0600 Initial commit diff --git a/backup.sh b/backup.sh new file mode 100644 index 0000000..b512539 --- /dev/null +++ b/backup.sh @@ -0,0 +1,55 @@ +#! /bin/bash + +REPO="" +PASSPHRASE="" + +export BORG_REPO=$REPO +export BORG_PASSPHRASE=$PASSPHRASE + +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 \ + \ + ####---put exclude directories here + ::'{hostname}-{now}'\ + #####---put directories to be backed up here + +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} +