No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

home_deploy_backup-root_sh.j2 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/sh
  2. mount {{ backup_repo_dir }}
  3. # Setting this, so the repo does not need to be given on the commandline:
  4. export BORG_REPO={{ backup_destination }}
  5. # Setting this, so you won't be asked for your repository passphrase:
  6. export BORG_PASSPHRASE='{{ backup_borg_passphrase }}'
  7. # some helpers and error handling:
  8. info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
  9. trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM
  10. info "Starting backup"
  11. # Backup the most important directories into an archive named after
  12. # the machine this script is currently running on:
  13. borg create \
  14. --verbose \
  15. --filter AME \
  16. --stats \
  17. --show-rc \
  18. --compression lz4 \
  19. --exclude-caches \
  20. {% for path in backup_excludes %}
  21. --exclude '{{ path }}' \
  22. {% endfor %}
  23. ::'{hostname}-{now}' \
  24. {{ backup_source }} \
  25. backup_exit=$?
  26. info "Pruning repository"
  27. # Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly
  28. # archives of THIS machine. The '{hostname}-' prefix is very important to
  29. # limit prune's operation to this machine's archives and not apply to
  30. # other machines' archives also:
  31. borg prune \
  32. --list \
  33. --prefix '{hostname}-' \
  34. --show-rc \
  35. --keep-daily {{ backup_daily }} \
  36. --keep-weekly {{ backup_weekly }} \
  37. --keep-monthly {{ backup_monthly }} \
  38. prune_exit=$?
  39. # use highest exit code as global exit code
  40. global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit ))
  41. if [ ${global_exit} -eq 1 ];
  42. then
  43. info "Backup and/or Prune finished with a warning"
  44. fi
  45. if [ ${global_exit} -gt 1 ];
  46. then
  47. info "Backup and/or Prune finished with an error"
  48. fi
  49. umount -l {{ backup_repo_dir }}
  50. exit ${global_exit}