Backup remote linux machines to Synology

The Purpose

I use a number of Virtual Private Servers (VPS) and wanted to make a backup of the data and applications running on them.

The first step is to make a local copy of your data to a folder on the remote machine, then you can pull these files to the Synology NAS via a scheduled task. For my applications I simply used tar to backup all the directories I can about to a single file and a mysql dump to dump all the databases in the mysql server to a single file.

Setup Authentication

generate your keys


  • do not configure with a password

Verify sshd is configured to use key files

vi /etc/ssh/sshd_config

AuthorizedKeysFile      %h/.ssh/authorized_keys

Add the public key to ssh authorized_keys

cat >> ~/.ssh/authorized_keys

Copy the private key to the Synology

Use any method you like for this. I personally simply copied the contents of the private key, then pasted it into a file on my local machine and moved it to an existing share on the NAS.

Connect to source machine from Synology and trust the source machine

chmod 400 $AbsolutePathToPrivateKey
ssh -p 22 -i $PRIVATEKEY

The scheduled task

Create the scheduled task

save the script below local to the Synology and make it executable


  1. You may need to enable SSH terminal access on your NAS.
  2. If you edit the script locally on a windows machine with Notepad ++ make sure you change the EOL (End of Line) to Unix

/usr/bin/rsync -avz --progress -e "ssh -p $PORT -i $SSHID" $USER@$SERVER:$SOURCE $TARGET >> $LOG 2>&1

Run the script and verify your data is copied


Leave a Reply