Monday, June 10, 2013

Cisco IOS Configuration Archiving

Juniper has always been easier when rolling back configuration in case you messed up or you just wanted to try something and revert back to your good old working configuration, you can literally rollback to your old configuration with one command rollback 1  and you're back to the previous configuration. Cisco has a similar thing, although tedious; but it nearly gets the job done. The archive  command. There's a similar way to do this using the configure replace command.

You can get under the archive configuration hierarchy with the command arhcive in the global configuration mode


R2(config)#archive
R2(config-archive)#
now let's get to the good stuff. there are several features you can configure to achieve fully automated configuration archive.

First step is to configure the path in which you want the archived configurations to be saved at. personally, i prefer to make a directory to contain only the archived configurations. here's how to do it


R2#mkdir disk0:/archives
Create directory filename [archives]?
Created dir disk0:/archives

After making the directory, you need to point out  from the archive hierarchy to the directory we just created.


R2(config-archive)#path disk0:/archives/backup
Notice that after pointing to the archives directory, i added " /backup ", the reason is that you need to define a base name for the configurations to use is so that the backups name would be like backup-1 , backup-2 etc.. as it will increment till it reaches the highest configurable number which is 14, which can be configured with the maximum command


R2(config-archive)#maximum ?
  <1-14>  maximum number of backup copies
R2(config-archive)#maximum 14

now to make an snapshot of the configuration automatically each time you write your configuration to the memory you'll have enter this command 


R2(config-archive)#write-memory
Basically what it does is that it archives the configuration each time you issue the write command on your router which is good but, keep in mind that if you keep saving every time you enter some command things can get a little bit messy since it will keep archiving and incrementing . There's a way around this but it contradicts a little bit with the whole theory of saving your most recent configurations.

R2(config-archive)#time-period ?
  <1-525600>  Number of minutes to wait between archive creation
R2(config-archive)#time-period 1
time-period  delays the time after an archive creation has been triggered, meaning that if you issued a write  command it doesn't create the archive until the configured time has passed. it's a trade off really, since you can write 20 lines manually or 500 lines pasted from the notepad in that minute and you might need to rollback all of that before the minute is off. no putting this command will just create the archive instantaneously.

let's see how our configuration works so far

 R2#show archive
The maximum archive configurations allowed is 14.
The next archive file will be named disk0:/archives/backup-0
 Archive #  Name
   1      
   2      
   3      
   4      
   5      
   6      
   7      
   8      
   9      
   10
There are currently no configuration saved.
there are no archives saved right now, how about configuring an IP address then saving it. You can actually do this in two ways, either configuring write-memory under the achrive hierarchy or by simply issuing the archive config in the exec mode


 R2#conf tEnter configuration commands, one per line.  End with CNTL/Z.R2(config)#int f0/0R2(config-if)#ip add 10.1.2.1 255.255.255.0R2(config-if)#endR2#writeBuilding configuration...[OK]
R2#show archive
The maximum archive configurations allowed is 14.
There are currently 1 archive configurations saved.
The next archive file will be named disk0:/archives/backup-1
 Archive #  Name
   1        disk0:/archives/backup-0 <- Most Recent
   2      
   3      
   4      
   5      
   6      
   7      
   8      
   9      
   10   
As you can see, the router saved this configuration with the name backup-0 in disk0. lets change the hostname also and make a new archive

R2(config)#hostname cisco-router
cisco-router(config)#end
cisco-router#wr
Building configuration...
*Jun 10 00:52:25.715: %SYS-5-CONFIG_I: Configured from console by console[OK]
cisco-router#show archive
The maximum archive configurations allowed is 14.

There are currently 2 archive configurations saved.

The next archive file will be named disk0:/archives/backup-2

Archive # Name
1 disk0:/archives/backup-0
2 disk0:/archives/backup-1 <- Most Recent
3
4
5
6
7
8
9
10

cisco-router#
excellent eh? now how can you actually see the contents of that configuration, it has been a whilke and you actually can't remember which one you changed the interface IP address in 

you can do that in many way actually, the simplest of them is using the more  command from the exec mode


cisco-router#more disk0:/archives/backup-0
This will show you the whole configuration that is in backup-0 which is very cumbersome to compare with any other config. 


cisco-router#show archive config differences disk0:/archives/backup-0!Contextual Config Diffs:+hostname R2-hostname cisco-router

Notice the (+) and (-) in-front of the hostname lines here, this basically means that the archive your viewing right now contains hostname R2 and  and does not contain hostname cisco-router. it's very neat specially when your comparing your current configuration with an archived one to assess the impact of rolling back.

now we saved the configuration, how do we rollback to this configuration. There are several ways to do this

let's see what our disk contains first

cisco-router#dir disk0:/archivesDirectory of disk0:/archives/
    2  -rw-        1748  Jun 10 2013 00:47:54 +00:00  backup-0
 
    3  -rw-        1758  Jun 10 2013 00:52:26 +00:00  backup-1
66875392 bytes total (66863104 bytes free)
As expected, the configurations saved in the disk0 with base name backup. we can load these configs to the routers with several techniques which are fairly different in behavior


  • making the archive file the startup-config file! you can do as follow reloading the router, when the router comes up, it will use the configuration was that copied to the startup config, which is not very pretty in downtime prospective. 
 copy disk0:/archives/backup-0 startup-config

  • using the configure replace command we talked about earlier, which is better because it replaces the  running configuration with any complete configuration saved on your flash or disk configure 
replace disk0:/archives/backup-0 force

Hopefully i managed to cover the basics of archiving, there's more and as usual old articles are updated with new stuff every now and then. Please feel free to comment regarding any mistakes or new features!










No comments:

Post a Comment