Community discussions

MikroTik App
 
dadoremix
Member Candidate
Member Candidate
Topic Author
Posts: 133
Joined: Sat May 14, 2011 11:31 am

Mikrotik backup + upload to FTP /problem/

Sun Feb 25, 2018 9:52 am

Hello
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
/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
 
User avatar
sebastia
Forum Guru
Forum Guru
Posts: 1782
Joined: Tue Oct 12, 2010 3:23 am
Location: Antwerp, BE

Re: Mikrotik backup + upload to FTP /problem/

Sun Feb 25, 2018 1:03 pm

Hi

Have you tried running script manually on the failing nodes? It should work in "one-of" mode, before you schedule it.

On the other hand, do you schedule 89 uploads on exactly the same time to one server? Can it handle all at once? You should probably spread the load over time.
 
dadoremix
Member Candidate
Member Candidate
Topic Author
Posts: 133
Joined: Sat May 14, 2011 11:31 am

Re: Mikrotik backup + upload to FTP /problem/

Sun Feb 25, 2018 1:48 pm

upload is not at the same time
cca 10-15 sec gap
how i open new mtik and put via terminal script and schedule
so, is not at the same time..
but now i go test wih 10 of them .. maybe is ftp server NAS .. problem
 
User avatar
tomaskir
Trainer
Trainer
Posts: 1162
Joined: Sat Sep 24, 2011 2:32 pm
Location: Slovakia

Re: Mikrotik backup + upload to FTP /problem/

Tue Feb 27, 2018 5:55 pm

I would suggest getting a proper config management solution.
(that will do config backup, show changes in config ,etc.)

You have multiple choices:
Unimus - https://unimus.net/
Oxidized - https://github.com/ytti/oxidized
Rancid - http://www.shrubbery.net/rancid/
etc.

It will be easier to use, much more stable, and less error-prone than scripting around everything...
 
2frogs
Forum Veteran
Forum Veteran
Posts: 713
Joined: Fri Dec 03, 2010 1:38 am

Re: Mikrotik backup + upload to FTP /problem/

Tue Feb 27, 2018 9:13 pm

Be sure to have a delay after the backup creation long enough for the file to finish writing before it tries to ftp. Devices with smaller cpu’s or devices under load will take longer to write.
 
dadoremix
Member Candidate
Member Candidate
Topic Author
Posts: 133
Joined: Sat May 14, 2011 11:31 am

Re: Mikrotik backup + upload to FTP /problem/

Tue Feb 27, 2018 10:06 pm

maybe someday .. mikrotik make some app for all that
Great hardware offer, but poor support around maintenance
Its easy when you have 1-10 mikrotik routers .. but 100+?
 
User avatar
tomaskir
Trainer
Trainer
Posts: 1162
Joined: Sat Sep 24, 2011 2:32 pm
Location: Slovakia

Re: Mikrotik backup + upload to FTP /problem/

Wed Feb 28, 2018 3:19 pm

maybe someday .. mikrotik make some app for all that
Great hardware offer, but poor support around maintenance
Its easy when you have 1-10 mikrotik routers .. but 100+?
As I mentioned in my previous post, you already have multiple solutions that exist that do this.

Why should MikroTik write an application for something that already exists?
That would be just a waste of developer time, that could be much better spent elsewhere.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10195
Joined: Mon Jun 08, 2015 12:09 pm

Re: Mikrotik backup + upload to FTP /problem/

Wed Feb 28, 2018 4:01 pm

It will be easier to use, much more stable, and less error-prone than scripting around everything...
Those solutions are "scripting around everything" just as well as an own solution!
The only difference is that the scripting is done by someone else, which saves work and may avoid
some common traps that those others have already encountered.
On the other hand, when you have some unique requirement it is often more difficult to incorporate
because you do not have deep understanding of the code and it often includes complexity that was
only added for other people's requirements.

Don't get me wrong, it is usually worthwhile to investigate such existing solutions and use them
when convenient. But I have been doing this (get config and store in a revision control system
using some custom script) for a long time before those solutions were published. That was
even under SCCS and later RCS... :)
 
dadoremix
Member Candidate
Member Candidate
Topic Author
Posts: 133
Joined: Sat May 14, 2011 11:31 am

Re: Mikrotik backup + upload to FTP /problem/

Wed Feb 28, 2018 9:17 pm

maybe someday .. mikrotik make some app for all that
Great hardware offer, but poor support around maintenance
Its easy when you have 1-10 mikrotik routers .. but 100+?
As I mentioned in my previous post, you already have multiple solutions that exist that do this.

Why should MikroTik write an application for something that already exists?
That would be just a waste of developer time, that could be much better spent elsewhere.

why?
because, then i have all from mikrotik
Who know, what
Unimus - https://unimus.net/
works with my config, also need to pay other work like unimus
other 2, works only at linux .. i want windows os :) etc etc
yes we have dude .. but .. what he can do? Nothing, again chemistry and programming. I use dude only for watch if is all devices online, and upgrade
People want click clik and forget, like winbox
If there is no winbox, I doubt it would be a mikrotik so popular as it is now.
So, why not make managment app, save, monitor, operate devices .. all from mikrotik family

Who is online

Users browsing this forum: No registered users and 29 guests