Automate backup with Cisco IOS’ kron

Let’s say you want to automatically back up your router’s running configuration (in RAM) to the startup configuration (in NVRAM) every Monday night at 10 P.M. You might want to make sure that the system is preserving router changes, even if the router losses power and even if someone forgets to save his or her changes.

The new IOS command scheduler makes this a relatively easy task. Here’s how you can use kron to accomplish this.

First, create a kron policy-list. Essentially, this policy list serves as your ‘script’, which lists what you want the router to run at a scheduled time. Here’s an example:

Router(config)#kron policy-list backup
Router(config-kron-policy)#cli write
Router(config-kron-policy)#exit

Next, create a kron occurrence, in which you tell the router when and how often you want to run this policy list (i.e., group of commands). Here’s an example:

Router(config)#kron occurrence backup at 22:00 Mon recurring
Router(config-kron-occurrence)#policy-list backup

This code sets up your backup job to run every Monday night at 10 P.M. (22:00 in military time).

Finally, verify that you’ve entered everything correctly by using the show command.

Router#show kron schedule

Kron Occurrence Schedule
backup inactive, will run again in 2 days 22:03:46 at 22:00 on Mon

Router#show running-configuration
(truncated)
kron occurrence backup at 22:00 Mon recurring policy-list backup
!
kron policy-list backup cli write
(truncated)

Notes:
You might be wondering why I used the write command instead of the copy running-configuration startup-configuration commands. While the copy run start command is interactive, the write command is not. In other words, write doesn’t prompt to verify what you want to do. It’s important to remember that the Cisco IOS Command Scheduler doesn’t allow any interactive commands.

You might be wondering if you could use kron to reboot the router. While it’s a good idea to use the command scheduler if you want to reboot your router on a regularly scheduled basis, you can perform a one-time delayed reboot using reload at with less complexity.

Additional uses for kron include clearing an interface on a daily schedule, clearing the internal log, and showing the routing table at set intervals and sending it to a log.

In some cases, you may want to log the failure or success of your commands. To do so, you can use the debug command. For example, to view all kron debugging, use debug kron all. (You can also use more specific kron debug commands.)

Once you’ve enabled debugging, send logging output to the router’s system buffer or to a syslog server. In that log, you’ll find the command output and whether the commands succeeded or failed.

Backup on FTP config example:
ip ftp source-interface loopback 0
ip ftp username ftp_username
ip ftp password ftp_password
file prompt quiet
!
kron policy-list backup
cli copy running-config ftp://10.20.30.40
!
kron occurrence daily-backup at 0:30 recurring
policy-list backup

~ by Safar Safarov on December 12, 2010.

4 Responses to “Automate backup with Cisco IOS’ kron”

  1. Safar,

    Thanks for the tutorial. I’m curious about this statement however..

    “You might be wondering if you could use kron to reboot the router. While it’s a good idea to use the command scheduler if you want to reboot your router on a regularly scheduled basis, you can perform a one-time delayed reboot using reload at … with less complexity.”

    Does this mean you have done this? Or does it not work as it requires a carriage return to confirm it (interactive)?

    I think I am looking to make a couple changes to the running config, write and reboot, all on a schedule. Is this possible??

    Thanks,

    Chris

  2. Chris,
    to tell the truth, I never tried to use kron to schedule reload. I use a one-time delayed reboot by ‘reload at’ command as I mentioned in the tutorial. If you will find a right way how to do that using kron, you may share it then.
    Thanks,
    Safar.

  3. conf t
    kron occurrence test in 1 recurring
    policy-list test
    kron policy-list test
    cli reload in 1

    Rack2R4#sh kron sched
    Kron Occurrence Schedule
    TESTKRON inactive, will run again in 0 days 00:00:25
    test inactive, will run again in 0 days 00:00:02

    Rack2R4#
    *Mar 1 06:35:35.106: %SYS-5-CONFIG_I: Configured from console by console
    Rack2R4#conf t
    Enter configuration commands, one per line. End with CNTL/Z.
    Rack2R4(config)#no kron occurrence WR in 3 recurring

    ***
    *** — SHUTDOWN in 0:01:00 —

  4. Hi there

    as you can see the kron works fine…..

    however…more control on policy etc can be achieved with Cisco EEM….

    thus I’ll rather use the eem for these type of automation!

    kr
    Josua

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.