A poor man’s config manager

There are multiple ways to make automated copies of a current running config of Cisco devices, but getting everything backed up and checked into an existing git server is another story. I know there is rancid (only SVN) and rancid-git but i had a look at the documentation and got scared…

After a little scripting and searching we can now do config backups automatically every day and every time the config on the Switch is saved

You will need

  • an FTP server where the config is backed up
  • a small shell script to move/rename the config
  • a GIT Server where the config is stored

First, set up an FTP Server which is reachable by all devices you want to back up, then configure the automated FTP backup on the switch:

Please edit the ftp user/password/server and replace the tags with your own information

$h.txt will translate to the host name of the device. Unfortunately a time stamp will be added to the file name which is not configurable. To get rid of that time stamp (which we do not need as this info is contained in the git commit automatically) a little script is needed on the FTP Server which will rename the file to something more useful. This script can either be triggered via a cron job on the Linux server or by using a small tool named “inotify” ( apt-get install inotify-tools ) which will monitor a given directory for certain file system events and act upon these events (literally a cron daemon for file system events).

The icrontab entry on the server looks like this:

So on every successful “IN_CLOSE_WRITE” event in the watched folder (every time a file has been successfully written and closed) the script <path>/rename-and-git.sh is called with the watched folder and the found file as arguments.

Please be careful in the rename line. You will have to escape the folder path correctly. the general syntax for rename is  rename -f 's/<what to search>/<rename to>/' <file> using standard regex search and replace. Also make sure you have a working git checkout on the folder you are moving the file to.

Daily Backup

Now you will have a backup solution which will automatically get the current running config whenever a new config is saved on the Switch. To force a daily “rwite mem” on the switch, Cisco has implemented a Cron – System. which can be configured like this:

This will run the three command every day at 1:14 which will trigger the configure archive command.

Leave a Reply

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