Cisco – Config Archive Variables
Posted by Josh on Wed 30 Jul 2008Categories: Cisco , Cisco Routers - [15] Comments
I was browsing videos on brainbump.net last Friday and noticed a different take on a tutorial I did regarding automatic configuration backups with the ‘archive’ command. While watching the video, I learned a new trick. The file name in the ‘path’ command may contain two different variables.
One variable is available for the date & time and another for the router’s hostname. To include the router hostname in the archive file filename, enter the characters $h. To include the date and time in the archive file filename, enter the characters $t. They can be used independant of each other, together or as a prefix/suffix to another word.
Examples:
SCP: path scp://10.100.100.50//cygdrive/c/tftp/$h
TFTP: path tftp://10.100.100.50/sunny-branch-$t
Local: path flash:$h$t
Problems:
Although the date/time variable is documented to work on Cisco’s site, I have not had any luck. In all my testing, I get error when I try to use the date/time variable. I also get a permission denied error when I try to use the timestamp variable with my tftp server. If anyone has a solution for this, I would be interested to find a solution. Here is an example of the error I get when storing to flash.
Router(config)#archive
Router(config-archive)#path $h$t
Invalid path, please include a : character
Router(config-archive)#path flash:$h$t
Router(config-archive)#wr
Router(config-archive)#^Z
Router#wr
Building configuration…
*Mar 1 00:02:21.315: %SYS-5-CONFIG_I: Configured from console by console[OK]
%Error opening flash:Router-Mar–1-00:02:28.427-1 (Illegal file character)
Router#
Update:
Shortly after I wrote my first draft of this post, a visitor left a very interesting comment on my previous posts. He answered some of the questions I presented above and shared his own struggles. I thought about rewriting the post, but I thought it would be better to leave it. Here is the comment. Thanks Darren!
==========
To use the timestamps you have to append “$t” to your filename. However it puts the time format in the following:
Jul-28-05:10:23.794
Thus windows will not read this, all you will get is “23.794″ followed but -1 or whatever sequence number you are upto.
When I deployed this a month ago I was having great difficulty with the “time-period” command, it never worked ![]()
Here is how I managed to get scheduling working:
kron occurrence backup at 2:30 1 recurring
policy-list backup
!
kron policy-list backup
cli archive config
This backs up my config on the 1st of every month at 2:30am. You can also use the EEM (embedded event manager) to do something similar.
Hope this helps
==========
July 31st, 2008 at 9:43 am
Just used the path flash:$h$t variable on a customer’s 1811 router and worked great! no issues.
August 2nd, 2008 at 10:21 pm
James,
Thanks for sharing your experience.
I still don’t know what my problem was. It could have been that I was using GNS3 at the time or the tftp server I was using may have not worked correctly either.
Josh
September 8th, 2008 at 4:26 pm
I’m testing this at the moment. Saving to a subdirectory on flash disk. It all works fine except when I use the “$t” variable. It saves with a filename like this:
disk2:archives/Sep–8-23:21:30.588-IST-1
However the “sh archive config diff” command cannot read the file:
Error: Could not open file disk2:archives/Sep–8-23:21:30.588-IST-2 for reading
When I do not use the “$t” variable, config diff works fine. “configure replace” works fine, regardless.
September 23rd, 2008 at 7:58 pm
Hi Darren here (from Josh’s post above). Thanks for your kind words josh, keep it up and I don’t know if I’ll be able to fit my head through the door haha.
Paul:
when you say “it saves with a filename like this”, did you just obtain that from running the command “sh archive”? the reason why I bring this up is because that is how the your device will see the filename (regardless if the OS can write that filename or not).
Also what is the output after you run your write mem.
This is the output of one of my switches using automatic archive:
hostname#wr me
Building configuration…
[OK]!
notice the “!”, if you see this the auto archive has worked. if you see a number of “.” it means it has not worked for one reason or another (say network connection, incompatible filename with the OS etc).
September 23rd, 2008 at 10:09 pm
you may see more “!”, depending on how long it takes to copy across your config (size/network speed etc)
October 1st, 2008 at 1:38 pm
Hi Darren,
thanks for the response. That is the exact filename on the filesystem using “dir”. The “OS” in question is the cisco IOS itself – I am saving to a local flash disk on the router. The config archives successfully (I see the ‘!’), but whatever way the code is written, the “sh archive config diff” command doesn’t like the filename, while “configure replace” can deal with it. I suspect the colons are what’s upsetting it…
October 13th, 2008 at 12:33 pm
What if you manually gave the archive a name (something that doesn’t have special characters)? Do you get the same problem?
October 13th, 2008 at 12:39 pm
dazamaz,
I don’t have any issues if I specify a name only when I try the time variable.
Josh
October 14th, 2008 at 8:07 am
could possibly be as paul suggested, maybe it is not liking the colons…
I will do some testing as well and get back to you guys
January 4th, 2009 at 5:49 pm
Something that is very interesting about particular IOS versions and running kron…
Arrived back in the office this morning after 2 weeks holidays and found out that there had been a bug in some IOS versions causes by kron running at/near the end of the calender year. I do not have the full details as of yet but from what I have been told so far this crashed our BGP routers and completely brought down our WAN!!!
The reason why this brought down our remote office BGP routers was because they got stuck in a loop after the BGP routers in our DC crashed.
We had Dimension Data (our support guys) help us on this one. Here is what they said:
the issue was caused by an IOS bug. Cisco Bug ID: CSCsm20994
The details of the bug can be found in the following URL:
http://tools.cisco.com/Support/BugToolKit/search/getBugDetails.do?method=fetchBugDetails&bugId=CSCsm25847
I am unable to view this link as I only have a cisco guest account, however am still researching
January 5th, 2009 at 8:53 pm
dazamaz,
One of the guys in our office found something very similar to this! His problem was a bug having something to do with scp copies and kron.
Very strange and very random! Thanks for the information!
Josh
January 22nd, 2009 at 6:36 pm
Extremely bad bug with the “kron” command!!!!
When using kron in conjunction with its ‘at’ command the service hogs the cpu, and in some cases reboots the router, constantly!
This is Cisco’s bug that explains the problem best:
http://tools.cisco.com/Support/BugToolKit/search/getBugDetails.do?method=fetchBugDetails&bugId=CSCsm99079
However they only label it as a severity 2 case, when in actual fact its much worse then this!
January 22nd, 2009 at 6:39 pm
Josh,
while perusing though the cisco bugs to try and find something that better reflected what happened (in my post 2 above that bug wasn’t exactly our problem, my post above has the closest cisco bug) I did see the scp bug you mentioned, however didn’t think much of it as we are not using scp, just straight out tftp.
Thanks for letting me know though
August 30th, 2009 at 9:04 pm
Thanks for writing this great blog I really enjoyed.
October 7th, 2009 at 11:04 am
question: if the path is scp://help.me:hopeless/running.config
Is there anyway to set encryption level so the
password will not be in the clear?
thank you