Community discussions

MikroTik App
 
Bomber67
Member
Member
Topic Author
Posts: 385
Joined: Wed Nov 08, 2006 10:36 am

How to verify result of fetch upload to FTP server?

Mon Nov 14, 2016 10:31 am

Hi all,

I run a couple of scheduled scripts on my routers.
Script 1 runs at 0200 hrs and makes a backup file and an export file
Script 2 runs every hour throughout the day (0230, 0330 etc).
It checks for backup files and export files and upload them to an FTP server (NAS) using fetch, before deleting them on the router
When everything is up and running this works like a champ, but I would like to add some checking to my script, to be notified if something goes wrong.
I would like to verify that the file is actually uploaded to the FTP server, and - if possible - if it is of the right size.

1) Is it possible to get some sane result back from the fetch command?
I try to read the function result into a string:
  :set resstr [/tool fetch address=$ftphost src-path=$fname user=$ftpuser mode=ftp password=$ftppassword dst-path=($ftppath . $fname) upload=yes keep-result=yes];
  :log info "Result= $resstr"
  :log info ("Length=" .  [len $resstr]);
If everything goes fine, resstr is of length 0.
However, if I change some params to provoke an error in the fetch command, i.e. invalid hostname, path, user, password or something, the script simply halts immediately.
Isn't it supposed to abort the fetch operation and return something useful as a function result?

2) Is it possible to browse the ftp server to check that the uploaded file(s) are present and of the right size?
Or is the only solution to try to pull the file off the ftp, save it to another name and compare the sizes?
 
Bomber67
Member
Member
Topic Author
Posts: 385
Joined: Wed Nov 08, 2006 10:36 am

Re: How to verify result of fetch upload to FTP server?

Tue Nov 15, 2016 1:58 pm

Come on guys, I know some of you are doing fetch upload to ftp!
So how do you perform an integrity check?
 
User avatar
h8r1dx4
just joined
Posts: 5
Joined: Thu Nov 17, 2016 12:17 pm
Location: South Africa
Contact:

Re: How to verify result of fetch upload to FTP server?

Sat Nov 19, 2016 12:01 pm

hi bomber , i have made a backup script that will help you .
It writes a log file that tells you if backup was made and if files where copied properly. It can do multiple devices and next versions will include mailing the logs after backup runs.
only thing is that it needs to be run from a linux system.

Check it out here https://github.com/h8r1dx4/mkbackup

Let me know if you need help or want a feature added.

Regards,
 
User avatar
BlackVS
Member Candidate
Member Candidate
Posts: 174
Joined: Mon Feb 04, 2013 7:00 pm
Contact:

Re: How to verify result of fetch upload to FTP server?

Wed Nov 23, 2016 11:13 am

Hi all,
1) Is it possible to get some sane result back from the fetch command?
Isn't it supposed to abort the fetch operation and return something useful as a function result?
I found only one way for the same situation - to put fetch command into the
:do {
} on-error={}
block...

Example from my code:
:local ERRNO 0
:local ERRFILENOTFOUND 1
:local ERRFTPFAILED 2
:local error $ERRNO
:do {
   :tool fetch mode=ftp upload=yes user=$ftpuser password=$ftppassword src-path=$bfile address=$ftphost dst-path="$ftppath/$bfile"
   $log2file file=$logfile console=yes  log=info text=($logprefix."SUCCESS sending $bfile via ftp")
} on-error={
   $log2file file=$logfile console=yes  log=error text=($logprefix."FAILED sending $bfile via ftp. Run //system script run backups_send2ftp from terminal windows to see error description")
   :set error ($error|$ERRFTPFAILED )
}
...
if ($error!=0) do={
 process errors
}

2) Is it possible to browse the ftp server to check that the uploaded file(s) are present and of the right size?
Or is the only solution to try to pull the file off the ftp, save it to another name and compare the sizes?
I'm afraid using RouterOS scripting it is impossible due to RouterOS has very ridiculous FTP support ^).
I.e. right now I know only two ways to do this - using external calls (like proposed above by h8r1dx4 ) or copy back and compare...
 
User avatar
BlackVS
Member Candidate
Member Candidate
Posts: 174
Joined: Mon Feb 04, 2013 7:00 pm
Contact:

Re: How to verify result of fetch upload to FTP server?

Thu Nov 24, 2016 7:37 am

One more way - run fetch in separate script (using :execute") and catch the output of script.
Fetch if success prints "status: finished". Or prints error mesage which can be parsed.
:local logftp "ftp.log"
:local cmd "/tool fetch mode=ftp upload=yes user=\"$ftpuser\" password=\"$ftppassword\" src-path=\"$bfile\" address=\"$ftphost\" dst-path=\"$ftppath/$bfile\""
:execute file=$logftp script=$cmd
#wait 30s usually enough. Or run loop for some time and check log ftp file for "status" text
:delay 30s
:local logres [/file get [find name="$logftp.txt"] contents]
:if ($logres~"finished") do={
 .... success upload ....
}

Who is online

Users browsing this forum: SerhiiH and 32 guests