06-20-2024 04:41 AM
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.
Solved! Go to Solution.
06-20-2024 07:31 AM
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#
06-20-2024 04:48 AM
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
06-20-2024 05:18 AM
Hi,
Thanks for the reply. I think archive is not interactive. Since SFTP connections request username and password.
06-20-2024 07:31 AM
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#
06-20-2024 07:36 AM
Thanks Dan,
I will try it and will notify you the result.
06-20-2024 07:40 AM
Thank you very much Mr. Dan!
it works perfectly. But can I use it also for Nexus switches?
06-20-2024 07:45 AM
I also found that it needs this command additionally to work if you are using AAA
event manager session cli username nnnnn
06-20-2024 08:21 AM - edited 06-20-2024 09:51 AM
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.
06-21-2024 05:21 AM
archive doesn't support sftp:
Any for nexus 9k is appreciated.
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