SHARE
TWEET

Untitled

a guest Mar 25th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. # Enhanced backup script
  3. # Sends messages to Zabbix based on exit code of borg executable
  4. #
  5. # email removed
  6. # Shellcheck will still kvetch at you if notices are enabled
  7. #
  8. # This script will not work AS-IS but is only provided as such
  9. # NO WARRANTIES
  10. # This work is licensed under a Creative Commons Attribution 4.0 International License.
  11. # https://creativecommons.org/licenses/by/4.0/
  12. #
  13. # 2017-08-10
  14.  
  15. ####################
  16. # SETUP
  17. ####################
  18. ZABBIX_SERVER=monitor01.example.net
  19. RUN_HOST="$(hostname)"
  20. RUN_DATE="$(date +%Y-%m-%d-%R)"
  21. SEND_CMD=/bin/zabbix_sender
  22. BORG_CMD=/usr/local/bin/borg
  23. REPOSITORY=borgbackup@backup01.example.net:/backup/${RUN_HOST}
  24. export BORG_PASSPHRASE='REPLACEME'
  25.  
  26. ####################
  27. # BACKUP
  28. ####################
  29. if [ -x ${BORG_CMD} ]
  30. then
  31.   echo "Starting backup on ${RUN_DATE}"
  32.   ${BORG_CMD} create -v --stats            \
  33.       $REPOSITORY::${RUN_HOST}-${RUN_DATE} \
  34.       /root                                \
  35.       /home                                \
  36.       /etc                                 \
  37.       /opt                                 \
  38.       /var/www/html
  39. else
  40.   echo "error with borg executable"
  41.   ${SEND_CMD} -z ${ZABBIX_SERVER} -s ${RUN_HOST} -k system.backup.state -o 3
  42.   exit 1
  43. fi
  44.  
  45. ####################
  46. # EXIT CODE CHECK
  47. ####################
  48. case $? in
  49. 0)
  50.   # Success
  51.   echo "Backup completed successfully"
  52.   ${SEND_CMD} -z ${ZABBIX_SERVER} -s ${RUN_HOST} -k system.backup.state -o 0
  53.   ;;
  54. 1)
  55.   # Warning
  56.   echo "Backup completed with warnings"
  57.   ${SEND_CMD} -z ${ZABBIX_SERVER} -s ${RUN_HOST} -k system.backup.state -o 1
  58.   ;;
  59. 2)
  60.   # Failure
  61.   echo "Backup failed!"
  62.   ${SEND_CMD} -z ${ZABBIX_SERVER} -s ${RUN_HOST} -k system.backup.state -o 2
  63.   exit 1
  64.   ;;
  65. *)
  66.   # Unknown status
  67.   echo "Backup status unknown"
  68.   ${SEND_CMD} -z ${ZABBIX_SERVER} -s ${RUN_HOST} -k system.backup.state -o 3
  69.   ;;
  70. esac
  71.  
  72. ####################
  73. # POST BACKUP PRUNE
  74. ####################
  75. echo "Starting backup pruning"
  76. ${BORG_CMD} prune -v $REPOSITORY --prefix ${RUN_HOST}- \
  77.     --keep-daily=7 --keep-weekly=4 --keep-monthly=6
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top