Archiving Router Configuration to TFTP Server Automatically

Answered Question
Oct 6th, 2009

Does anyone have a config that they can share on backing up the running config on RouterA daily at 11pm to a TFTP server? I think it involves the "archive" command.

TFTP Address: 10.8.4.201

Path location and File Name: TFTPBoot\RouterA.txt

Time: Daily at 11pm

Thanks in advance.

I have this problem too.
0 votes
Correct Answer by Joe Clarke about 7 years 1 month ago

Yes, you can use the built-in IOS config archive feature to do this. Your config can be as simple as say:

archive

path tftp://10.1.1.1/configs/$h-$t

maximum 14

time-period 60

write-memory

With this config, the device will write a new file to TFTP with the name HOSTNAME-DATE-X where HOSTNAME is the hostname of the device, DATE is the current date/time, and X is a number from 0 to 14. Config archives will be taken periodically every hour, or whenever a write mem is executed.

Note: most TFTP servers won't like this kind of thing. They require that a file exist before it can be written to. You may want to consider a more secure protocol such as SCP.

There is also a really good Embedded Event Manager policy at http://forums.cisco.com/eforum/servlet/EEM?page=eem&fn=script&scriptId=1103 which will archive the config only when it has changed. It works in conjunction with the above Config Archive feature plus the SYS-5-CONFIG_I syslog message.

Correct Answer by Lucien Avramov about 7 years 1 month ago

With kron you can NOT go to config mode.

It's only for EXEC mode, so it wont let you go to config terminal in KRON:

http://www.cisco.com/en/US/docs/ios/netmgmt/command/reference/nm_08.html#wp1058933

You should use EEM to achieve this.

event manager applet SaveConfigToTFTP

event cli pattern "write" sync no skip no

action 1 cli command "enable"

action 2 cli command "configure terminal"

action 3 cli command "file prompt quiet"

action 4 cli command "end"

action 5 cli command "copy running-config tftp://tftp-server/router-confg"

action 6 cli command "configure terminal"

action 7 cli command "no file prompt quiet"

action 8 cli command "end"

(write memory|copy running-config startup-config)"

To set a timer, your applet could configure another, timer applet to run. For example:

action 010 cli command "event manager applet mytimer"

action 011 cli command "event timer countdown time 30"

action 012 cli command "action ..."

  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 5 (3 ratings)
Loading.
pompeychimes Tue, 10/06/2009 - 19:28

I think you'd need to use a kron job to actualy specify a specific time. Else you could do it every so many minutes. Like this...

config t

archive

path tftp:\\backupserver\configs

time-period 180

Correct Answer
Lucien Avramov Tue, 10/06/2009 - 20:13

With kron you can NOT go to config mode.

It's only for EXEC mode, so it wont let you go to config terminal in KRON:

http://www.cisco.com/en/US/docs/ios/netmgmt/command/reference/nm_08.html#wp1058933

You should use EEM to achieve this.

event manager applet SaveConfigToTFTP

event cli pattern "write" sync no skip no

action 1 cli command "enable"

action 2 cli command "configure terminal"

action 3 cli command "file prompt quiet"

action 4 cli command "end"

action 5 cli command "copy running-config tftp://tftp-server/router-confg"

action 6 cli command "configure terminal"

action 7 cli command "no file prompt quiet"

action 8 cli command "end"

(write memory|copy running-config startup-config)"

To set a timer, your applet could configure another, timer applet to run. For example:

action 010 cli command "event manager applet mytimer"

action 011 cli command "event timer countdown time 30"

action 012 cli command "action ..."

davidhuynh5 Tue, 10/13/2009 - 04:35

The archive command works well with L3 Cisco devices. In switches, the archivve command is not available in global config mode. Is there a replacement command?

Correct Answer
Joe Clarke Tue, 10/06/2009 - 20:52

Yes, you can use the built-in IOS config archive feature to do this. Your config can be as simple as say:

archive

path tftp://10.1.1.1/configs/$h-$t

maximum 14

time-period 60

write-memory

With this config, the device will write a new file to TFTP with the name HOSTNAME-DATE-X where HOSTNAME is the hostname of the device, DATE is the current date/time, and X is a number from 0 to 14. Config archives will be taken periodically every hour, or whenever a write mem is executed.

Note: most TFTP servers won't like this kind of thing. They require that a file exist before it can be written to. You may want to consider a more secure protocol such as SCP.

There is also a really good Embedded Event Manager policy at http://forums.cisco.com/eforum/servlet/EEM?page=eem&fn=script&scriptId=1103 which will archive the config only when it has changed. It works in conjunction with the above Config Archive feature plus the SYS-5-CONFIG_I syslog message.

Actions

This Discussion