If you are a proud owner of a Synology NAS you should think about an efficient and convenient backup strategy. The built-in module „Hyper Backup“ is a good starting point. You can setup up one or several backup sets for your valuable data and can rely on repetitive backups. But where to store the backups? The easiest way is to connect an external hard disk on one of the USB ports to store the backups there. But in case of a big disaster (e.g. a fire or a burglary) your backup may be lost as well. So, it’s a good idea to use two (or more) backup drives and cycle them on a regular basis. The unused drive(s) may be stored on a safe place (e.g. in a different building).
For example, if you have two backup USB drives you can set up two identical backup sets, one for each drive. The sets may specify a backup on a daily basis (e.g. in the night) and the one with the currently connected drive will succeed while the other will fail temporarily. Then, you can switch the backup drives on a weekly basis. On the above mentioned disaster you will loose at most one week of changes.
The problem with different backup sets for several USB drives is that you have to unmount the already connected drive safely via the DSM admin console before you unplug it and replace it with the next drive in the cycle. If you don’t do that you will get a warning on the console (and possibly via mail) because you may risk a data loss.
There is an option in Hyper Backup’s settings for the backup set to eject the backup volume after a successful backup. With that option in place you could unplug the backup drive safely without login to the admin console because the backup drive is probably not mounted (after the successful backup in the previous night). But if you do not cycle the backup drive right now the backup in the next night will not take place because no backup volume is mounted then.
So, the task is to mount a possibly connected backup drive just before the regular backup should take place. Unfortunately, there no such option in Synology’s Hyper Backup to do that automatically. But there is a built-in scheduler in Synology’s DSM and with that we can execute self-defined scripts on a regular basis. We find that in the module Control Panel as „Task Scheduler“. There we can see the tasks already set up by Hyper Backup for the backups and the possibly enabled integrity checks. We have to make sure that our mount script always runs just before the scheduled Hyper Backup tasks.
Here is my proposal for that script. It’s based on suggestions found here and here.
1 2 3 4 |
/usr/syno/bin/synousbdisk -umount sdq echo "2-2" > /sys/bus/usb/drivers/usb/unbind sleep 10 echo "2-2" > /sys/bus/usb/drivers/usb/bind |
First of all we have to unmount (and unbind) the possibly mounted volume on the USB port. This is necessary because the following bind command would result in a warning if the backup volume is already mounted (e.g. if we have connected the next backup drive in the cycle just before). To get the device name for the unmount command we can issue the command cat /tmp/usbtab
in the terminal while the device is mounted. For me it is „sdq“.
Then we unbind and bind the device on the desired USB port. Again, we obtain the name of the correct USB port via the terminal logged in to the NAS: lsusb
. For me it is „2-2“.
Now, we can create a new Scheduled Task with our User-defined script. It should run daily just before the backup or the integrity check takes place. And in the Task Settings we put in our script.
That’s it. Now we can unplug the currently connected backup volume and re-plug the next drive in the backup cycle without login to the DSM admin console.
Have fun.