We have cca 89 mikrotik devices 6.39 version stable chain
All in same network 10.40.x.x
Often someone change some setting, or device die after some time, and we dont have config
So i find script to backup and make rsc file + upload to local ftp server
All if fine, working when i run via terminal or winbox >> run script
here is script and scheduler
when schedular run script .. only 20 of 89 mtik devices send backup, other stuck in upload to ftp
to i have full memory of old backup files, because ofter upload, script must delete that backup
And so every 7 days
Code: Select all
/system scheduler
add interval=1w name=backup_ftp on-event="/system script run backup" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
start-date=jan/19/2018 start-time=20:50:57
/system script
add name=backup owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
source="# ftp server\r\
\n :local ftphost \"10.40.3.162\"\r\
\n :local ftpuser \"mw\"\r\
\n :local ftppassword \"x\"\r\
\n :local ftppath \"/MW/\"\r\
\n\r\
\n # months array\r\
\n :local months (\"jan\",\"feb\",\"mar\",\"apr\",\"may\",\"jun\",\"jul\",\"aug\",\"sep\",\"oct\",\"nov\
\",\"dec\");\r\
\n\r\
\n # get time\r\
\n :local ts [/system clock get time]\r\
\n :set ts ([:pick \$ts 0 2].[:pick \$ts 3 5].[:pick \$ts 6 8])\r\
\n\r\
\n # get Date\r\
\n :local ds [/system clock get date]\r\
\n\r\
\n # convert name of month to number\r\
\n :local month [ :pick \$ds 0 3 ];\r\
\n :local mm ([ :find \$months \$month -1 ] + 1);\r\
\n :if (\$mm < 10) do={ :set mm (\"0\" . \$mm); }\r\
\n\r\
\n # set \$ds to format YYYY-MM-DD\r\
\n :set ds ([:pick \$ds 7 11] . \$mm . [:pick \$ds 4 6])\r\
\n\r\
\n # file name for system backup - file name will be BCKP-servername-date-time.backup\r\
\n :local fname1 (\"/BCKP-\".[/system identity get name].\"-\".\$ds.\"-\".\$ts.\".backup\")\r\
\n\r\
\n # file name for config export - file name will be BCKP-servername-date-time.rsc\r\
\n :local fname2 (\"/BCKP-\".[/system identity get name].\"-\".\$ds.\"-\".\$ts.\".rsc\")\r\
\n\r\
\n # backup the configuration\r\
\n /system backup save name=\$fname1\r\
\n :log info message=\"System backup finished (1/2).\";\r\
\n /export compact file=\$fname2\r\
\n :log info message=\"Config export finished (2/2).\"\r\
\n\r\
\n # upload the system backup\r\
\n :log info message=\"Uploading system backup (1/2).\"\r\
\n /tool fetch address=\"\$ftphost\" src-path=\$fname1 user=\"\$ftpuser\" mode=ftp password=\"\$ftppass\
word\" dst-path=\"\$ftppath/\$fname1\" upload=yes\r\
\n\r\
\n # upload the configuration export\r\
\n :log info message=\"Uploading configuration export (2/2).\"\r\
\n /tool fetch address=\"\$ftphost\" src-path=\$fname2 user=\"\$ftpuser\" mode=ftp password=\"\$ftppass\
word\" dst-path=\"\$ftppath/\$fname2\" upload=yes\r\
\n\r\
\n # delay time to finish the upload - increase it if your backup file is big\r\
\n :delay 12s;\r\
\n\r\
\n # find file name start with BCKP- then remove\r\
\n :foreach i in=[/file find] do={ :if ([:typeof [:find [/file get \$i name] \"BCKP-\"]]!=\"nil\") do={\
/file remove \$i}; }\r\
\n :log info message=\"Configuration backup finished.\";"
run backup
can someone help, to reslovle, od test personal at your device ?
Or some other solution?
I have also dude on 1 mikortik , but i dont know how that produce, if dude can that ?
Or, how to make bach of script on windows, and i run on windows
ssh to device via telenet or ssh and run sript ? one click in windows ?
or in mikrotik, and again scheduler