Copy files from the MikroTik router via SMB

There are many instructions on how to move automatic backups of the router via FTP to an external storage.

I would now like backups created by the router to be stored on an external storage device via SMB.

So far I have only found instructions on how to create an SMB share on the Mikrotik router, but I would like to copy/move local files from a Mikrotik router to an SMB share (Windows), is that possible?

Greetings
Andreas

Good Evening Andreas,

If i am not mistake, RouterOS doesn`t support SMB export out-of-the-box
Nevertheless, if you have a device with a arm, arm64, x86 or tile architecture,
you can install the ROSE-Package (https://help.mikrotik.com/docs/spaces/ROS/pages/259031065/ROSE-storage)
that support SMB-Share.

I just tested it with a RB4011, works great.

Add ROSE-storage package and reboot then create SMB disk:

/disk add type=smb ...

You don’t need rose package.

Agrees; my bad.

Currently, there are no any commands to do that. But as far as I know, they are working on improving file management and hope this functionality will appear in the final 7.18 release or some beta.

Hi,

Try this:

https://help.mikrotik.com/docs/spaces/ROS/pages/259031065/ROSE-storage#ROSEstorage-Configurationexample.4


disk add smb-address=10.155.145.11 smb-share=share1 smb-user=user smb-password=password type=smb

Work only from cli.

Looks like no one is even reading what he asked about…

1 Like

Yes, there is no copy/move file commands for CLI, only move over GUI can be done. For now only solution (without fetch command copy hack) is that backup script creates files directly on mounted disk path without need for copy/move.

To copy file locally over SSH using fetch command:

/tool/fetch url=sftp://127.0.0.1 user=<ROS_USER> upload=yes src-path=<copy_from_file_path> dst-path=<copy_to_file_path>

If you have password allowed SSH login password=<ROS_USER_PASSWORD> can be added to fetch command argument, but is not recommended, better to use key auth.

SSH local access setup
For key auth to work, private/public key pair needs to be exported into files:

/ip/ssh/export-host-key key-file-prefix=ssh_key

and imported for SSH ROS user which will be used in fetch command:

/user/ssh-keys/import public-key-file=ssh_key_<ssh_alg>_pub.pem user=<ROS_USER> key-owner=local
/user/ssh-keys/private/import private-key-file=ssh_key_<ssh_alg>.pem user=<ROS_USER> key-owner=local

Depending on firewall rules, in my case I needed to accept loopback interface in input chain to be able to connect to local SSH:

/ip/firewall/filter add action=accept chain=input in-interface=lo

Also additional note: if there is IP restriction in /ip/service for ssh, then bridge address can be used instead 127.0.0.1 in sftp fetch url because localhost address cannot be added there.

In this case if file moving is needed, then file can be just deleted by /file/remove <copy_from_file_path> after is successfully uploaded by fetch command.

My goal has been the same, automated backups on the device being copied elsewhere, but I’ve been treating the MikroTik as an SMB host with a Windows box as the client that executes the copy. I was struggling with this in 7.17, finding that while I could access the share the contents couldn’t be copied out, and after upgrading to 7.18.2 today, this seems to have been solved. Not 100% sure it will apply the same for this scenario, where the MikroTik executes the copy to a remote host.

I would also note that from a security standpoint, I believe it’s better to have your backups retrieved from a device, rather than pushed from the device. That way the backup system doesn’t need to grant any ingress access to remote devices.

So, based on the SMB function and what I’ve been taught is best practice, my method is:

  • Configure SMB on the Mikrotik, with appropriate directory share & permissions
  • Mount that share in a Win11 box
  • Use Task Scheduler to execute a batch that mirrors the contents of the mount to another location (I use FreeFileSync)

Relevant bits from the release notes:

7.18
*) smb - fixed connection issues with clients using older SMB versions (introduced in v7.17);
*) smb - fixes for SMB server;
*) smb - improved system stability;

7.18.1
*) winbox - fixed missing SMB client on non-ROSE devices;

There is a file move command: /file set name=
I don’t know since which RoS version, in Ros 7.16.2 is there, in 6.32.3 is not.

It can also move files to/from/between smb shares added with /disk add type=smb …

I don’t know if this was intended this way, I mean to include move in a rename operation. In the background I guess is a copy + delete.
I couldn’t find any file copy solution other than fetch.

I’m looking forward to the improved file management.

Is there any progress on implementing “copy” command, MikroTik?

the only working solution i know is this:

  1. mount smb share locally on mikrotik
  2. add rsync job to copy files from your source to mounted share
  3. wait until rsync is ‘in sync’
  4. clean up and your’e done

it would be great if mikrotik extended fetch command to support smb with subdirectories and some additional features. but until then, that’s it.

For automated backup files suggest to use SCP and pull new created backup files from any host as you need.
Solution without user/password typing, need to add user’s keys first.
Check firewall rules allowing ssh connections and voile.