Using Synology NAS "USB Copy" to backup multiple shared folders
The idea to use bind mounts comes from this blogpost. Thank-you, "Thunderbyte Computer"!
Scripts are available in this GitLab snippet. Contributions welcome :)
Synology NAS has a "USB Copy" feature which can automatically copy data from the NAS to a USB drive - but it forces the user to select a single shared folder as the source. Here's how to backup everything.
"Bind mounts", in a Unix system, allow you to mount an already-mounted filesystem to another location. This post describes how to use bind mounts to map multiple shared folders into a single shared folder, and then backing up that single shared folder to a USB drive.
Create a shared folder to contain the bind mounts
Start by opening the Control Panel and creating a new Shared Folder:
I named mine
_BackupUSB, made it hidden, and disabled the Recycle Bin.
Create two new Triggered Tasks
In the Task Scheduler section of Control Panel, create a new Triggered Task:
Name the task
mountbind, run as user
root, and set the event to "Boot-up":
Then paste in the contents of this script:
#!/usr/bin/env sh SOURCE_FOLDER=/volume1 DESTINATION_FOLDER_NAME=_BackupUSB DESTINATION_FOLDER=$SOURCE_FOLDER/$DESTINATION_FOLDER_NAME if [[ ! -d $DESTINATION_FOLDER ]] then echo "$DESTINATION_FOLDER_NAME shared folder does not exist." exit 1 fi cd $SOURCE_FOLDER find . -maxdepth 1 -type d -not -name "@*" -not -name "." -not -name "$DESTINATION_FOLDER_NAME" | while read folder do echo "Binding folder $folder" mkdir -p "$DESTINATION_FOLDER/$folder" mount -o bind "$folder" "$DESTINATION_FOLDER/$folder" done
This script will run whenever the Synology boots.
Next, create a second Triggered Task. Name this task
unmoundbind, run as user
root, and set the event to "Shutdown":
Then paste in the contents of this script:
#!/usr/bin/env sh SOURCE_FOLDER=/volume1 DESTINATION_FOLDER_NAME=_BackupUSB DESTINATION_FOLDER=$SOURCE_FOLDER/$DESTINATION_FOLDER_NAME if [[ ! -d $DESTINATION_FOLDER ]] then echo "$DESTINATION_FOLDER_NAME shared folder does not exist." exit 1 fi cd $DESTINATION_FOLDER find . -maxdepth 1 -type d -not -name "@*" -not -name "." | while read folder do echo "Unbinding folder $folder" umount "$DESTINATION_FOLDER/$folder" done
This second script will run whenever the Synology shuts down.
Reboot the NAS
Reboot the NAS. After rebooting, open File Station, and look inside the
_BackupUSB folder. You should see folders inside which match your other Shared Folders, and their contents should also be visible on the right-hand side. (See red highlight)
Prepare a USB drive (or two)
Skip this step if you already have a formatted USB drive.
Plug your USB drive into the front USB socket on the NAS, and open the External Devices section in Control Panel.
From there the disk can be formatted as
Create a USB Copy export task
Now create a USB Copy export task. Open USB Copy from the Main Menu, and press the blue "Create" button (+). Give the task a name (I created two tasks for two external disks and called them
Offsite A and
Offsite B), select
/_BackupUSB as the source and
/usbshare1 as the destination. Choose your copy mode. (I went for "Incremental", because subsequent backups are much faster)
Trigger the copy operation whenever the USB drive is plugged in, and eject the drive when the copy completes:
And complete the setup by selecting all filetypes for backup:
Configure USB Copy notifications
Next, we can use the Control Panel to set up some notifications. Go to the "Notification" section, then select the "Rules" tab. Expand the "USB Copy" section - don't be concerned that it all appears to be disabled. From there, you can enable notifications for when the task completes.
Start the first copy task
Use the eject button, in the right-hand corner of the DSM task bar to unmount the USB disk. Then unplug and re-insert the USB drive to start the first copy task.
My offsite backup strategy
I bought two 5TB USB drives, and set up a separate export task for each drive. I'll do a weekly export to a drive, then take that drive to work and bring the other drive home.
Backup speed with my hardware
Approximately 10 hours per TB, for the initial backup.
- DS220+ NAS
- STGX5000400 5TB USB drive
- front USB 3.0 port
First published 20 October 2022