Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # Enhanced backup script
- # Sends messages to Zabbix based on exit code of borg executable
- #
- # email removed
- # Shellcheck will still kvetch at you if notices are enabled
- #
- # This script will not work AS-IS but is only provided as such
- # NO WARRANTIES
- # This work is licensed under a Creative Commons Attribution 4.0 International License.
- # https://creativecommons.org/licenses/by/4.0/
- #
- # 2017-08-10
- ####################
- # SETUP
- ####################
- ZABBIX_SERVER=monitor01.example.net
- RUN_HOST="$(hostname)"
- RUN_DATE="$(date +%Y-%m-%d-%R)"
- SEND_CMD=/bin/zabbix_sender
- BORG_CMD=/usr/local/bin/borg
- REPOSITORY=borgbackup@backup01.example.net:/backup/${RUN_HOST}
- export BORG_PASSPHRASE='REPLACEME'
- ####################
- # BACKUP
- ####################
- if [ -x ${BORG_CMD} ]
- then
- echo "Starting backup on ${RUN_DATE}"
- ${BORG_CMD} create -v --stats \
- "${REPOSITORY}"::"${RUN_HOST}"-"${RUN_DATE}" \
- /root \
- /home \
- /etc \
- /opt \
- /var/www/html
- else
- echo "error with borg executable"
- ${SEND_CMD} -z ${ZABBIX_SERVER} -s "${RUN_HOST}" -k system.backup.state -o 3
- exit 1
- fi
- ####################
- # EXIT CODE CHECK
- ####################
- case $? in
- 0)
- # Success
- echo "Backup completed successfully"
- ${SEND_CMD} -z ${ZABBIX_SERVER} -s "${RUN_HOST}" -k system.backup.state -o 0
- ;;
- 1)
- # Warning
- echo "Backup completed with warnings"
- ${SEND_CMD} -z ${ZABBIX_SERVER} -s "${RUN_HOST}" -k system.backup.state -o 1
- ;;
- 2)
- # Failure
- echo "Backup failed!"
- ${SEND_CMD} -z ${ZABBIX_SERVER} -s "${RUN_HOST}" -k system.backup.state -o 2
- exit 1
- ;;
- *)
- # Unknown status
- echo "Backup status unknown"
- ${SEND_CMD} -z ${ZABBIX_SERVER} -s "${RUN_HOST}" -k system.backup.state -o 3
- ;;
- esac
- ####################
- # POST BACKUP PRUNE
- ####################
- echo "Starting backup pruning"
- ${BORG_CMD} prune -v "$REPOSITORY" --prefix "${RUN_HOST}"- \
- --keep-daily=7 --keep-weekly=4 --keep-monthly=6
Add Comment
Please, Sign In to add comment