Last active
October 12, 2018 20:34
-
-
Save voice1/8e9208e01b37db31c473bf12febd0c77 to your computer and use it in GitHub Desktop.
VyOS EdgeOS Automated backup and Change Notificaiton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Description: | |
# Demo of how to download EdgeOS configuration and check if a change exists. | |
# If a change exists send a notification to a Zabbix server. | |
# | |
# **************************************************************************************** | |
# This script is provided as a demo to show how to backup configurations automatically | |
# You should not consider this a production script. If you are interested in a production | |
# script please contact me @ support[at]voice1[dot]me or feel free to modify this to your | |
# own needs. | |
# | |
# Uncomment the dated-backup line if you want to save a local file with the date. | |
# | |
# **************************************************************************************** | |
# | |
# By: VOICE1, LLC | |
# LICENSE: BSD | |
# | |
DEVICE=10.0.0.1 | |
ZABBIX_SERVER=10.0.0.200 | |
ZABBIX_HOST='edgeOS-device' | |
DATE=`date +%Y-%m-%d:%H:%M:%S` | |
# This overrides any existing file by the same name. | |
ssh ubnt@$DEVICE "/opt/vyatta/sbin/vyatta-config-gen-sets.pl" > edgeOS-$DEVICE-backup.cfg | |
# dated-backup; | |
# Uncomment to save currently backed up file with a date suffix. | |
#cp edgeOS-$DEVICE-backup.cfg edgeOS-$DEVICE-backup-$DATE.cfg | |
# Basic File rotation. | |
if [ ! -f edgeOS-$DEVICE-backup-new.cfg ]; then | |
# There is no "new" file, our current one becomes the new file. | |
cp edgeOS-$DEVICE-backup.cfg edgeOS-$DEVICE-backup-new.cfg | |
else | |
# The "new" file exists, but its now the old file because we just downloaded | |
# the latest config. This overrides the old config. Make sure you have it backed up! | |
cp edgeOS-$DEVICE-backup-new.cfg edgeOS-$DEVICE-backup-old.cfg | |
fi | |
if [ ! -f edgeOS-$DEVICE-backup-old.cfg ]; then | |
# There is no "older file, so theres really nothing to compare to. | |
# cp edgeOS-$DEVICE-backup.cfg edgeOS-$DEVICE-backup-old.cfg | |
echo "No older config to compare to. Pull another copy first." | |
exit(0) | |
fi | |
# Diff | |
CHANGES=$(diff -qs edgeOS-$DEVICE-backup-old.cfg edgeOS-$DEVICE-backup-new.cfg) | |
# change-notification; | |
# Check the $CHANGES for either 'identical' or 'differ' | |
# And notify zabbix of a change. | |
# | |
# You can use any form of notification you want here, this is only a sample. | |
if [[ $CHANGES = *differ* ]]; then | |
zabbix_sender -z $ZABBIX_SERVER -s $ZABBIX_HOST -k edgeOS.config -o 'differ' | |
else | |
# No Changes Comment out if you do not want to receive notices of the same file. | |
echo "No changes detected." | |
zabbix_sender -z $ZABBIX_SERVER -s $ZABBIX_HOST -k edgeOS.config -o 'identical' | |
fi | |
exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment