Here’s what I do for a similar setup:
- Regular 2-way sync:
- Laptop:
e:\folder\foldertosync1
- NAS #1:
/folderA/foldertosync1
A bash script in cron or Synology “Scheduled Task” on NAS #1 then copies files as hardlinks from foldertosync1
to foldertosync2
.
- Regular 2-way sync:
- NAS #1:
/folderA/foldertosync2
- NAS #2:
/folderB/foldertosync2
Unix hardlinks link an additional filename entry to an existing physical file (“inode”), so no extra disk space is used. If either filename is deleted, the link count is reduced by one but the physical file remains on disk until there are no filename entries linked to it. (Hardlinks only work on the same mount point, so the two folders on NAS #1 should ideally be in the same parent folder.)
Files created on Laptop would be synced to NAS #1 in foldertosync1
, then would be hardlinked into foldertosync2
, causing them to be synced to NAS #2.
When files are deleted from Laptop, they will be deleted from NAS #1 foldertosync1
, but remain in foldertosync2
.
The bash script could be something like:
cp -Rlu /folderA/foldertosync1/* /folderA/foldertosync2/
cp -Rlu
recursively copies files and folders [“R”] as hardlinks [“l”] and avoids copying files that already exist unless they are newer [update, “u”].
It could run every 30 minutes or every hour, as appropriate - some interval long enough not to capture Syncthing temp files created for incomplete files (especially if you have large video files that may take some time to transfer).
In that case, you might use a bash script that deletes the temp files – on Linux/POSIX they would be .syncthing.original-file.ext.tmp
(see Understanding Synchronization — Syncthing v1 documentation).
Syncthing will ignore and not sync .syncthing.something.tmp
files, but they would clutter the target folder /folderA/foldertosync2
and will not get deleted without additional intervention.
Something like this ought to do it:
#!/bin/bash
cp -Rlu /folderA/foldertosync1/* /folderA/foldertosync2/
find /folderA/foldertosync2 -iname '.syncthing.*.tmp' -exec rm -f '{}' \;
The '
surrounding '.syncthing.*.tmp'
prevents the shell from prematurely interpreting the wildcard, '{}'
substitutes each filename from find
and \;
adds a trailing ;
to terminate the command – it has to be escaped with \
to prevent it being interpreted by the shell (the ;
may not be strictly necessary, but I don’t think it hurts to have it there).
The two lines could also be separate one-line commands run several minutes apart (i.e., run the first line to copy at the top of every hour and the second line at 2 minutes after the hour, or set both more frequently if needed).
NOTE: I strongly advise that both Syncthing folders on both NAS devices be configured with at least Trashcan versioning to save yourself from $*%# moments. (I prefer Simple or Staggered versioning; and if you have plenty of disk space, set “clean out after” to 300 days or more. See File Versioning — Syncthing v1 documentation for details.) And test with expendable files first!
Someone with more experience than I could probably improve on this.