cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
647
Views
1
Helpful
8
Replies

Please assist on a daily SFTP backup using EEM on Cisco router

I want to configure a daily backup to be copied to an SFTP server using EEM script on cisco router. Please assist on the configuration. 

1 Accepted Solution

Accepted Solutions

Example to run EEM to backup running config manually or with cronjob at 1am.

event manager applet configBackup
 event tag t1 none
 event tag t2 timer cron cron-entry "0 1 * * *"
 trigger
  correlate event t1 or event t2
 action 010 cli command "enable"
 action 020 cli command "show clock"
 action 030 regexp "([A-Za-z]+) ([0-9]+) ([0-9]+)" "$_cli_result" match month day year
 action 040 info type routername
 action 045 cli command "config term"
 action 046 cli command "file prompt quiet"
 action 047 cli command "exit"
 action 050 append date "$day"
 action 051 append date "$month"
 action 052 append date "$year"
 action 053 append date "_"
 action 054 append date "$_info_routername"
 action 055 puts "filename = $date"
 action 060 cli command "copy running-config sftp://username:password@192.168.0.26/$date"
 action 070 puts "$_cli_result"

 

INTERNET#event manager run configBackup
filename = 20Jun2024_INTERNET

SFTP send: Writing to /home/dafrey/20Jun2024_INTERNET size 24486
!
24486 bytes copied in 0.439 secs (55777 bytes/sec)
INTERNET#

View solution in original post

8 Replies 8

Torbjørn
Spotlight
Spotlight

Hi,

Is there a reason why you can't use the configuration archive functionality to achieve this? It does support SFTP as a target location.

You can read more about this here: https://www.cisco.com/c/en/us/td/docs/routers/ios/config/17-x/syst-mgmt/b-system-management/m_cm-config-versioning.html

Happy to help! Please mark as helpful/solution if applicable.
Get in touch: https://torbjorn.dev

 

Hi,

Thanks for the reply. I think archive is not interactive. Since SFTP connections request username and password.

Example to run EEM to backup running config manually or with cronjob at 1am.

event manager applet configBackup
 event tag t1 none
 event tag t2 timer cron cron-entry "0 1 * * *"
 trigger
  correlate event t1 or event t2
 action 010 cli command "enable"
 action 020 cli command "show clock"
 action 030 regexp "([A-Za-z]+) ([0-9]+) ([0-9]+)" "$_cli_result" match month day year
 action 040 info type routername
 action 045 cli command "config term"
 action 046 cli command "file prompt quiet"
 action 047 cli command "exit"
 action 050 append date "$day"
 action 051 append date "$month"
 action 052 append date "$year"
 action 053 append date "_"
 action 054 append date "$_info_routername"
 action 055 puts "filename = $date"
 action 060 cli command "copy running-config sftp://username:password@192.168.0.26/$date"
 action 070 puts "$_cli_result"

 

INTERNET#event manager run configBackup
filename = 20Jun2024_INTERNET

SFTP send: Writing to /home/dafrey/20Jun2024_INTERNET size 24486
!
24486 bytes copied in 0.439 secs (55777 bytes/sec)
INTERNET#

 

Thanks Dan,

I will try it and will notify you the result.

 

Thank you very much Mr. Dan!

it works perfectly. But can I use it also for Nexus switches?

 

I also found that it needs this command additionally to work if you are using AAA

event manager session cli username nnnnn

You should be able to use the config archive feature by specifying the path like so:

archive
 path sftp://username:password@ipaddress
 time-period 1440

Alternatively you can specify default sftp credentials and omitting the username and password from the path:

ip sftp username { username }
ip sftp password { password }

 This should also work for Nexus switches.

Happy to help! Please mark as helpful/solution if applicable.
Get in touch: https://torbjorn.dev

archive doesn't support sftp:

Any for nexus 9k is appreciated.