• How to keep last X startup configs

 
 
Print Friendly, PDF & Email

If you would like to keep track of last 10 (or more, or less) configuration changes, here’s the event-handler code to do that:


event-handler config-versioning    trigger on-startup-config action bash FN=/mnt/flash/startup-config; LFN="`ls -1 $FN.*-* | tail -n 1`"; if [ -z "$LFN" -o -n "`diff -I 'last modified' $FN $LFN`" ]; then cp $FN $FN.`date +%Y%m%d-%H%M%S`; ls -1r $FN.*-* | tail -n +11 | xargs -I % rm %; fi    delay 0

Description:

Every time the startup config gets changed, this event handler will be executed (“trigger on-startup-config”). You could increase the delay, if you wish, but now it’s engaged immediately after the config change (“delay 0”).

We store a time-stamped copy of the startup config (named like “startup-config.20150423-174712”), and remove older copies, keeping just the recent X ones (+11 in the code above defines that we keep only 10, the 11th one and older will be deleted).

Important:

Do NOT use quotes for this action, as this would also quote the “*” in the filename and the script couldn’t work.

Tip:

You can quickly revert back (without reboot!) to one of these saved configs using “config replace” (supported with EOS 4.14.0 or higher)

EOS# config replace flash:startup-config.20150423-174712 [force]

To find the right file to revert to, you can use “diff”, which will show the exact differences between the running config (or startup config, or any other file) and the file you’re considering. Furthermore, you can use name-completion using <TAB> and “?” to make your life easier.

EOS(config-if-Et1)#diff running-config flash:startup-config?
flash:startup-config                  flash:startup-config.20141222-214804
flash:startup-config.20141222-214819  flash:startup-config.20141222-215945
flash:startup-config.20141222-215957  flash:startup-config.20141222-220013
flash:startup-config.20141222-220025  flash:startup-config.20141222-220143
flash:startup-config.20141222-220837  flash:startup-config.20141222-220849
flash:startup-config.20141222-220857

EOS(config-if-Et1)#diff running-config flash:startup-config.20141222-220857

Follow

Get every new post on this blog delivered to your Inbox.

Join other followers: