Automate mounting of external USB storage for Synology Hyper Backup

I have the habit of having additional copies of back ups (partial and not full) from the Synology NAS to an external USB storage device like the Seagate Expansion Desktop. However, I want the external USB storage to be visible (i.e. mounted) to the Synology NAS only when the Hyper Backup task is running and not visible (i.e. unmounted) at other times with the hope of mitigating ill effects of ransomware attacks. I managed to achieve it using Task Scheduler and careful planning of backup windows for Hyper Backup tasks. I have put together this guide to show you how it is done.

The general idea

The approach is pretty straightforward:

  1. Have the external USB storage device physically connected to the Synology NAS at all times.
  2. Instruct the Synology NAS to mount the external USB storage device a couple of minutes before the scheduled Hyper Backup task starts.
  3. Configure the Hyper Backup task to remove the external USB storage device when the Hyper Backup task succeeds.

What’s left is just scheduling the automated mounting of USB storage device and Hyper Backup tasks. Easy isn’t it? Trust me, it really is.

Executing the plan

Connecting the hardware up

We need to connect the external USB storage physically to the Synology NAS. In my case, I connected my Seagate Expansion Desktop to one of the unused USB 3.0 ports on the Synology DS1821+. If everything is connected up properly, the Seagate Expansion Desktop would show up on the DiskStation Manager (DSM). A clear sign is that you see a “eject” symbol on the DSM’s taskbar.

Figuring out which USB port is it connected to

The next step is figuring out how does the DSM sees and locates the connected external USB storage device. Before we proceed, you will need to enable SSH service on the Synology NAS and SSH to it.

Once you are connected to the SSH service, you can issue the command “lsusb” to figure out which port it is connected to. I have issued “lsusb | grep Seagate” as I knew that I was trying to locate my Seagate Expansion Desktop drive.

Using lsusb to figure out which USB port is the USB storage connected to.
Using lsusb to figure out which USB port is the USB storage connected to.

In my setup, the Seagate Expansion Desktop is connected to “2-2”. Do take note of this information as it is required later on.

Configuring your scheduled Hyper Backup task

Since your USB storage is connected and visible to the system, we might as well configure a Hyper Backup task to backup stuffs to the external USB storage.

Go through the guided steps of selecting data and applications to be backed up to the external USB storage. Other than having it as a scheduled task (e.g. monthly backup on the 12th at 3am), check (or enable) the option of removing the destination device when the backup succeeds. This will unmount (or eject) the external USB storage device from the Synology NAS.

Just a tip: You can create a lightweight Hyper Backup task to test if it ejects (or unmount) the external USB storage device.

Removing destination device when the backup task successfully finished.
Removing destination device when the backup task successfully finished.

Scheduling and automating mounting of external USB storage

For this section, we will leverage DSM’s Task Scheduler feature. This can be found in DSM’s Control Panel. We will create a scheduled task for User-defined script that runs as root with the following content.

Replace the “2-2” with the information you got from the previous section. You should schedule it to run a couple of minutes before your Hyper Backup task. For example, if the Hyper Backup task runs on the 12th at 3am, I would schedule this to run on the 12th at 2.58am.

If your external USB storage is mounted at this juncture, unmount (or eject) it from the DSM’s taskbar. Once it has been ejected, test the scheduled task by manually running it from the Task Scheduler. If everything is done up correctly, the external USB storage should be mounted within 10 seconds. If it doesn’t, do check if the USB port information is correctly entered.

Conclusion

Do take note of the amount of time that your Hyper Backup task takes (aka the backup window) and make sure that you do not have overlapping backup windows. Another thing to note is you will need to update the “2-2” if you change the external USB storage to another USB port.

If everything is timed and configured properly, the Hyper Backup and Scheduled tasks will run like clockwork.

Hyper Backup and Scheduled tasks running like Clockwork.
Hyper Backup and Scheduled tasks running like Clockwork.

I hope the above information helps you with your backup strategy!

 

Treat shadowandy!

If these step-by-step guides have been very helpful to you and saved you a lot of time, please consider treating shadowandy to a cup of Starbucks.  

Leave a Reply

Your email address will not be published. Required fields are marked *