I want to upload my Mikrotik router backup file to Linux server using FTP. My linux server is Centos 6.9 and I have configured FTP in server. In mikrotik router I have used this script for taking backup and upload it to server.
:log info "backup beginning now"
:global name=backupfile value=([/system identity get name] . "-" . [/system clock get time])
/system backup save name=$backupfile
:log info "backup pausing for 10s"
:delay 10s
:log info "backup being uploaded"
/tool fetch address=server_ip src-path=$backupfile user=ftpuser mode=ftp password=ftppass dst-path="/home/ftp-docs/$backupfile" upload=yes
:log info "backup finished"
:delay 20s
:log info "Deleting Backup File"
/file remove $backupfile;
:log info "Deleting Backupfile File"
but this script does not working. Please help me for solving this issue.
at first glance it looks ok, log output needed
It's worrying that your FTPing to that kind of address, you should investigate having your server grab the backup with SCP
Here should be 3 more logs but the script didn't run completely. It is paused in the 3rd step only.
I don't have a box on to test the commands but something like this to make sure that your variable is working because a empty value for backupfile
will make the upload fail:
:global name=backupfile value=([/system identity get name] . "-" . [/system clock get time])
/system backup save name=$backupfile
:put $backupfile
if that is correct, then you can now try the /tool fetch
command in the same terminal and hopefully get more information
I have tested this script for sending backup file via mail and it worked successfully. So i think the variable is okay.
Plz can you suggest anything else?
cool, just run these 3 in a terminal on your Mikrotik (in winbox or SSH)
:global name=backupfile value=([/system identity get name] . "-" . [/system clock get time])
/system backup save name=$backupfile
/tool fetch address=server_ip src-path=$backupfile user=ftpuser mode=ftp password=ftppass dst-path="/home/ftp-docs/$backupfile" upload=yes
I think you'll get some error from the fetch
command that will help, without an error I'd just be speculating on a few possibilites.
Now I am able to transfer file from mikrotik to FTP server there was an issue of file permission on server. I have solved it. but now here is another problem. Backup file from mikrotik uploading to server but the file size showing in the server is 0 byte.
I have also tried to do this from mikrotik terminal.
tool fetch address=server_ip src-path=Router_Backup_File.backup user=ftp_user mode=ftp password=ftp_pass dst-path="/home/ftp-docs/$backupfile" upload=yes
I have used this command and it does uploaded my backup file to destination directory in server.
Here "src-path=Router_Backup_File.backup" is the name of the backup file which was created from this script in early section. This command is exactly same as my script lines but the only difference is that here I have used the actual name for "src-path" and in script I have used "src-path=$backupfile" this variable. Do you find anything wrong here?
The 1st file uploaded to FTP server when I used miktorik terminal and the 2nd file created when I have run the backup script. You can see when i used the script, it started uploading the file but could not able to complete (I think there is some errors in the script) but when I used command line (1st file), it did complete to upload the file. And yes you can also see that when I used the script, the file format did not added here.
so close, I'm not sure how to approach the zero byte problem, but this from an old forum post may give more clues:
Also, have you considered binary backups vs exports?
https://wiki.mikrotik.com/wiki/Manual:Configuration_Management
Only add src-path="$backupfile.backup"
:log info “backup beginning now”
:global name=backupfile value=([/system identity get name] . “-” . [/system clock get time])
/system backup save name=$backupfile
:log info “backup pausing for 10s”
:delay 10s
:log info “backup being uploaded”
/tool fetch address=FTPIP src-path="$backupfile.backup" user=USER mode=ftp password=PASS dst-path="/folder/$backupfile.backup" upload=yes
:log info “backup finished”