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 😉
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.
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
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”
Ok.. we are done with ssh thingy. Let’s write some script.
Next, we will do some scripting as below.
#!/bin/ash #This is the private key PRIVKEY="/volume/ServerBackup/scripts/snology" #This is the folder you would like to backup from HOSTFOLDER=/backup/* #This is the folder you would like to backup to Synology DESTFOLDER="/volume/ServerBackup/database/server-godzilla/" #We will be using rsync in synology, this will do the rync! /usr/syno/bin/rsync -avz -e "ssh -p7777 -i $PRIVKEY" firstname.lastname@example.org:$HOSTFOLDER $DESTFOLDER
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
ssh -p2222 root@your_synology_ip mydisk> cd /volume/ServerBackup/scripts mydisk> ./database.backup.sh The authenticity of host '[godzilla.takizo.com]:2222 ([123.456.123.111]:2222)' can't be established. ECDSA key fingerprint is f7:9b:d6:92:7b:33. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[godzilla.takizo.com]:2222,[123.456.123.111]:2222' (ECDSA) to the list of known hosts. receiving incremental file list 20150721122502.dbbackup.tar.gz sent 42 bytes received 18901016 bytes 1021678.81 bytes/sec total size is 18997573 speedup is 1.01
The important part for this action is this line
Warning: Permanently added '[godzilla.takizo.com]:2222,[123.456.123.111]:2222' (ECDSA) to the list of known hosts.
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 😉