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.
generate your keys
- do not configure with a password
Verify sshd is configured to use key files
Add the public key to ssh authorized_keys
cat key.pub >> ~/.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 email@example.com
The scheduled task
Create the scheduled task
save the script below local to the Synology and make it executable
- You may need to enable SSH terminal access on your NAS.
- 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