How to Rsync from Remote Server to Synology

I hava a synology at home, mainly use to store important files, and realize beside have a backup of my server files on dropbox, may be it can have another copy in Synology as well. I explored the possibility of rsync the backup either on dropbox or server into synology, and… it works!

Here is what you need to prepare before proceed with the backup.

1. Create a directory for backup. i.e folder name of ServerBackup. Go to “Control Panel” -> “Shared Folder”.

2. Enable SSH on Synology. Go to “Control Panel” -> “Terminal & SNMP” -> “Enable SSH Service”. If you option to change the SSH port or not 😉

synology-backup-enablessh

3. Try to ssh into Synology with username “root”. The root password is the same with “admin”.

If are you done, let’s do it.

Generate SSH Key

You wouldn’t want to key in password whenever want to access to the server to grab the file. Generate a “custom” ssh key which will be used for synology. Remember, please do not set the password. Give you ssh file a “special name”, DO NOT use the default. I.e we used synobackup, there are 2 files will be generate

1. synobackup – This is the private key files
2. synobackup.pub – This is the public key which will be placed on the remote server.

synology-backup-sshkey

Next, we will copy this 2 files into Synology folder ServerBackup. We create a folder name “scripts”, and the file will be placed in synology

1. /Volume/ServerBackup/scripts/synobackup
2. /Volume/ServerBackup/scripts/synobackup.pub

We will copy the key on synobackup.pub into remote server’s ssh directory “.ssh/authorized_keys” for the user’s home directory where you will login with the username later. i.e “/home/takizo/.ssh/authorized_keys”

synology-backup-homeauthorizedkey

Ok.. we are done with ssh thingy. Let’s write some script.

Simple Scripting

Next, we will do some scripting as below.

Save the script above into your Synology backup folder which created earlier “/volume/ServerBackup/scripts/database.backup.sh”

Please take note that the remote folder is define by yourself. We are done with the script, it’s time to Execute it!

Configure the Backup Script

Due to it’s the first time access to the remote server, you need to manually run the script in shell to accept the SSH session. We are almost there.

SSH to Synology server

The important part for this action is this line

This will add the host into /root/.ssh/known_hosts, when the script is run next time, it will not prompt the message again.

Setup the Task on Synology

Since the script is working perfectly fine. The last step is add it into Synology’s Task Schedule.

1. Go to “Control Panel” -> “Task Schedule”
2. Create “User defined-script”
3. Give a meaningful name for your “Task”
4. User choose “root” or any user you prefer
5. User-defined script: The script you created earlier inside Synology folder, “/volume/ServerBackup/scripts/database.backup.sh”
6. Put up a schedule for this, how often it should run and at what time.

After the schedule has been created, try run it again and check is the files transfer into your Synology folder (if you don’t have new copy of file in the server, delete the files earlier being rsync into synology).

Yep, basically you have another copy of backup on synology! Enjoy backup more stuff from remote server 😉