01-06-2013 12:10 PM
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
01-06-2013 01:26 PM
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
01-06-2013 02:11 PM
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
01-09-2013 12:10 AM
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
Apart from IOS XR specific instructions you can use TCL commands.
Regards,
/A
08-13-2013 08:21 PM
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.
08-15-2013 11:33 AM
02-26-2015 03:17 AM
How to schedule for show command automatically every day?
Anyone have command share me please.
08-15-2013 03:59 PM
Not sure if this script will work on a CRS, but try this:
archive
log config
logging enable
hidekeys
path tftp://
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).
04-15-2016 04:37 AM
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
05-23-2016 05:05 AM
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.
05-23-2016 05:45 AM
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
05-23-2016 09:14 AM
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.
05-23-2016 09:22 AM
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
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide