cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
10888
Views
20
Helpful
12
Replies

How can i do scheduled automatic backups to an ftp server in ios xr?

davicho182
Level 1
Level 1

Hello guys! As the title says im looking forward to automatically back up my running config on a cisco CRS-1 to an FTP server. I was only able to find this config example:

Configuration commit auto-save filename ftp://A.B.C.D/myconfig.txt

This allows me to save my config to an ftp server everytime i use commit on the device. Now i want to know if there's a way to automatically save my configs everyday at 00:00  and also include the date and time in the name of the file so i don't overwrite the existing files in the ftp server.

I dont want to use any tool i just wanna know if what im asking is possible via CLI commands. I would greatly appreciate your help with this subject.

Regards,

David

12 Replies 12

Alexei Kiritchenko
Cisco Employee
Cisco Employee

Hello David,

There is no simple CLI to do it but the Embedded Event Manager supports cron and with your EEM script running on the CRS you can achieve the desired result.

Regards,

/A

Hello Alexei,

Thanks for replying, would you be so kind to send me a link where i can learn the procedure to implement this method you described in your post? It would be really helpful.

Regards,

David

Hello David,

EEM is basically TCL script extended for IOS support. You can find EEM description and configuration examples on this page

Configuring and Managing Embedded Event Manager Policies

http://www.cisco.com/en/US/docs/routers/crs/software/crs_r4.1/system_monitoring/configuration/guide/b_sysmon_cg41crs_chapter_010.html

Apart from IOS XR specific instructions you can use TCL commands.

Regards,

/A

Could you convert this command in IOS to use for IOS XR

kron occurrence Backupcfg in 1:0:0 recurring

policy-list Backupcfg

kron policy-list Backupcfg

cli show run | redirect tftp://10.5.3.22/10.5.0.1.cfg

Thank you very much.

here you go:

RP/0/RSP0/CPU0:A9K-BNG#sh run | file tftp://3.0.0.1/see_this

regards

xander

How to schedule for show command automatically every day?

Anyone have command share me please.

Leo Laohoo
Hall of Fame
Hall of Fame

Not sure if this script will work on a CRS, but try this:

archive

log config

logging enable

hidekeys

path tftp:///$h-

write-memory

time-period 10080

Explaination: 

There are two ways to save your config to your remote station:

1.  When someone saves the config; and

2.  At an alloted time period, expressed in 10080 (weekly for me). 

jacekFrankowski
Level 1
Level 1

Hi there,

I know this is quite late reply but I have the same issues and I figure out the script that really works:


::cisco::eem::event_register_timer cron cron_entry "0 22 * * *"


namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
if [catch {cli_open} result] {
error $result $errorInfo
} else {
array set cli1 $result
}

array set _sinfo [sys_reqinfo_routername]
set hostname $_sinfo(routername)


if [catch {cli_exec $cli1(fd) "show clock"} cli_output] {
 error $cli_output $errorInfo
} else {
 set current_time $cli_output
}

set year [lindex $current_time 12]
set month [lindex $current_time 3]
set day [lindex $current_time 4]
set temp [lindex $current_time 5]

set hour [string range $temp 0 1]
set minute [string range $temp 3 4]
set second [string range $temp 6 7]
append time $hour "." $minute "." $second
append date $month "-" $day "-" $year "-" $time
append filename $hostname "-" $date
if [catch {cli_exec $cli1(fd) "sh run | file ftp://username:password@192.168.1.1/$filename"} cli_output] {
error $cli_output $errorInfo
}
if [catch {cli_close $cli1(fd) $cli1(tty_id)} result] {
error $result $errorInfo

Hi Jacek,

Could you please explain this script little.

What it does and how to implement?

I am also trying to find solution to save file with time on each commit command, so files are not overwritten.

I used to archive in IOS, with $h/$h and it worked well but in IOS-XR it does not work.

The easiest way to save the file on commit with a unique filename is to have a tcl script looking for the commit syslog message, when it sees that copy running config to a file with the date and time as part of the filename.

Sam

Hi Sam,

Very good idea, this also will work. I'd prefer to play with show clock command here but this is just my approach that is already working in the production without any problems. 

Regarding this part of code:


if [catch {cli_exec $cli1(fd) "show clock"} cli_output] {
 error $cli_output $errorInfo
} else {
 set current_time $cli_output
}

set year [lindex $current_time 12]
set month [lindex $current_time 3]
set day [lindex $current_time 4]
set temp [lindex $current_time 5]

set hour [string range $temp 0 1]
set minute [string range $temp 3 4]
set second [string range $temp 6 7]
append time $hour "." $minute "." $second
append date $month "-" $day "-" $year "-" $time
append filename $hostname "-" $date

This just assures the uniqness of the configuration file name on the FTP server by taking hostname and the date. Date is parsed from the show clock command. Try out show clock on your IOS-XR and lindex is used to point at a specific string in the entire command output. Please note that the "show clock" itself has got an index 0 and 1 as far as I remember.

You can also use the clock function.

Here is an example from another script where if a commit fails we run a list of commands and then output data to a file:

if [catch {cli_exec $cli1(fd) "commit"} result] {
    error $result $errorInfo
} else {
    set output [split $result "\n"]
    foreach val $output {
        if [regexp ".*Failed to commit one or more configuration items.*" $val matched] {
            append cmd_output $result
            break
            foreach val $failurecli {
                if [catch {cli_exec $cli1(fd) $val} result] {
                    error $result $errorInfo
                } else {
                    append cmd_output $result
                }
            }
            set tdate [clock format [clock seconds] -format %Y%m%d%H%M%S]
            set filename [format "/harddisk:/data-%s.txt" $tdate]
            set outfile [open $filename w]
            puts $outfile "$cmd_output"
            close $outfile
            set output_msg "Saved data to file $filename"
            if [catch {cli_close $cli1(fd) $cli1(tty_id)} result] {
                error $result $errorInfo
            }
        }
    }
}
}   

Thanks,

Sam