Automatically send network device configurations to your support partner

In the last part of the Rancid set-up I created a simple Bash scripts which e-mails the configurations of the network devices to myself and our support partner once a week. This because when your network is down, you always want access to your configurations. Further for our “sub” locations, we have a support partner which fixes the issues on these locations and it would be nice if they always have the up-to-date configuration files. Since there is not much changing in these configurations sending them once a week is more then enough, but this is of course up to you.

The script, works fairly simple, it is important that you have set-up the right SMTP server!

#!/bin/bash
# Script for mailing the network device configurations

# Make a directory where we can temporarily place the configurations
mkdir -p /tmp/backup/switch

# Looking for files starting with “sw” and that are greater then 0 bytes. Copy them to # the just created temporarily folder.

find /usr/local/rancid/var/ -name “sw*” -not -name “*svn*” -prune  -size +0 -exec cp ‘{}’ /tmp/backup/switch/ ;

# Put the files together in one tar file.
cd /tmp/backup/switch
tar -cf /tmp/backup/switch/bck_switch_cfg_week$(date +%U).tar *

#Mailing the just created tar file
echo “Backup netwerkdevices week $(date +%U)” | mailx -s “Switch backup week $(date +%U)” -a bck_switch_cfg_week$(date +%U).tar -r backup@_nospam_robmaas.eu  rob@_nospam_robmaas.eu support@partner_xx.com

# Delete the just created folder and files
rm -Rf /tmp/backup/switch

That’s all, keep in mind that the find and mailing (echo) commands are on one line, otherwise they will fail. Also you may want to change the –name parameter of the find command.

No we have a working script we only have to schedule it to run regularly. This can easy be accomplished with cron. I created a cronjob in the /etc/cron.d/mailbackups with the following cronjob.

@weekly /usr/local/bin/backup_switch_cfg.sh 2>&1

We are done, now every week the configurations are mailed to the given mail addresses.

Facebooktwittergoogle_plusredditpinterestlinkedinmailby feather

Leave a Reply

Your email address will not be published. Required fields are marked *

*