Stephen Ostermiller's Blog

Synology NAS Backup Script

I use external drives to backup everything on my Synology NAS. My data easily fits on a single large drive so:

  • I put two large drives in my NAS and use raid0 (mirrored disks)
  • The entire backup (or even multiple backups) can fit on an external drive.

I worry about threats to my data:

  • Hard drive failures
  • Physical damage (like dropping my NAS and backup drives)
  • Accidentally deleting important files and not noticing until the deletions have propogated to the backups

Raid0 and mutiple external drives really helps with drive failures. I'd say I get a drive failure every year or two. When it is in the NAS, I just replace the drive and let the NAS re-sync. When it is on a backup drive, I just stop using that drive.

Because of the risk of physical damage (even the risk of my house burning down!), I take a backup drive off-site every month. There is always one backup in the safety deposit box in my bank. I never have all the backups in the same physical location.

To combat accidental deletion of files:

  • I use multilple backup drives
  • I use drives big enough to hold multiple backups each
  • Every night I overwrite at most a single backup
  • I have enough backups so that I should always have a copy of my data at least a couple weeks old

To help with this, I wrote a script that does my backups. Here is the way it works:

  1. Does sanity checks
    1. External drive is mounted
    2. The NAS has at least the expected number of files on it
    3. No other backup job is currently running
    4. There is enough space to make a backup
  2. Examines all external drives that are attached
  3. Chooses an external drive on which to make a backup
    1. The first drive with available space
    2. Or overwrite a backup that did not complete last time
    3. Or overwrite a backup where there are several from the same day
    4. Or overwrite the oldest backup
  4. Creates a directory for the backup named by today's date
  5. Uses rsync to create the backup
  6. Creates a log file
  7. Prints a summary from the log file

For example, here is the listing of backups when three different external drives are attached to my NAS. Each drive has space for two backups, so I have 6 different backups available just on the drives that are connected:

Available backups:
  2020-01-27: complete files=458557:820GB trans=260:7GB runtime=34m:3KB/s disk=BAK2T04 mount=/volumeUSB1/usbshare dev=/dev/sdq1
  2020-01-28: complete files=458590:820GB trans=1075:8GB runtime=14m:9KB/s disk=BAK2T04 mount=/volumeUSB1/usbshare dev=/dev/sdq1
  2020-01-29: complete files=458614:820GB trans=427787:820GB runtime=17h:13KB/s disk=BAK2T05 mount=/volumeUSB3/usbshare dev=/dev/sdr1
  2020-01-30: complete files=458621:820GB trans=251996:304GB runtime=3h:28KB/s disk=BAK2T05 mount=/volumeUSB3/usbshare dev=/dev/sdr1
  2020-01-31: complete files=458550:820GB trans=427723:820GB runtime=19h:12KB/s disk=BAK2T06 mount=/volumeSATA/satashare dev=/dev/sdc1
  2020-02-01: complete files=458555:820GB trans=427727:820GB runtime=20h:11KB/s disk=BAK2T06 mount=/volumeSATA/satashare dev=/dev/sdc1

You can download my script and use it yourself:

nas-backup-1.0.0.tar.gz

Use ssh/scp to put it on your NAS and add it to a cron job.

The hardware

Here is the full hardware list that I recommend. Click any item to buy it on Amazon.

Synology NAS

read my review

2 NAS drives of the same size

Size (TB): 1, 2, 3, 4, 6, 8, 10, 12, 14


Size (TB:): 1, 2, 3, 4, 6, 8, 10, 12, 14, 16

External USB Drive Bay

read my review

Drives for External Backup


Size (TB): 1, 2, 4, 6, 8, 10, 12, 14

Leave a comment

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