Backup your datas automatically on a NAS (synology)

Here I explain how I have configured my workstation to backup my data automatically each night.

The principle of the automatic backup

Use rsync through a bash script and a crontab to make a backup (mirror) of specific directories on a Network Attached Storage (NAS).

Requirement for the backup

  • Debian / Linux on your workstation
  • rsync
  • A NAS (I have a Synology Ds411 slim)
  • A network configuration that works (not detailed here)!


Configuration of the NAS

First, you must allow SSH connection in the setup of your NAS as described here.
Create a user on the NAS (Config Panel > User > Create) and give him write access to his directory.
Tips: since DSM 4.1, check that the user have write access to ‘homes’ directory or you will have a read-only error.

Create the script

Connected as root, create a directory backup/ in the root directory and create an empty bash script file.

# cd /root
# mkdir backup/
# touch

Copy and adapt the script (see bellow).

Exclude some subdirectories from backup

create a file excludeHome.lst in /root/backup/ and fill it with the directories you DO NOT want to be backuped.


Automatize the backup

To automatize your backup each night, just use a crontab task on your workstation (under root)

# crontab -e
Ex to execute the backup each night at 3:35 am, use this crontab
# 35 3 * * * /root/backup/

Check logfile

Logs are written in /root/backup/snapshot-date-of-backup.log

Backup Script (

# Backup the LOCALDIR
# on a distant server through SSH
# Execute the script as Root
# change with your local dir
# change with your distant dir
# change with your user ssh
# change with your server nameserver

NOW="$(date +"%Y-%m-%d")"

rsync -av \
--stats \
--del \
--backup \
--backup-dir=$SERVERDIR/$SERVERPATH/deleted/ \
--progress \
--log-file=$LOGFILE \
--exclude-from $EXCLUDE \
GD Star Rating
Backup your datas automatically on a NAS (synology), 4.5 out of 5 based on 8 ratings