With the following command you can backup data from a Linux server to a Synology NAS:
1 |
/usr/bin/rsync -avh --delete --relative --password-file=/root/rsync_pass {/etc,/root,/var/cache/bind,/var/lib/automysqlbackup/latest,/usr/local,/var/www} <backup user>@<synology host>::<synology file share> |
The parameters have the following meaning:
<backup user>: User on NAS with permissions to use rsync to the target share
<synology host>: Hostname / IP of your Synology NAS device (if it is located remote you need to make sure that it is reachable via port 873/TCP
<synology file share>: The name of the target file share on your Synology host where you want to backup the data
In the file “/root/rsync_pass” you store the rsync password of the user <backup user>. Make sure to restrict permissions of that file (“chmod 600 /root/rsync_pass”)
This commands synchronizes the directories included in the “{}” brackets including the complete filename. Deleted files in the source will be deleted in the target as well, so that you do have an exact copy of your source.
To restore files you can use the following command (Example: Restore “/etc/” with all subfolders into the target directory “/restore“:
1 |
/usr/bin/rsync -avh --relative --password-file=/root/rsync_pass <backup user>@<synology host>::<synology file share>/etc/ /restore |
Unfortunately this will preserve the file and directory permissions but not the original owner of the directory/file. This will work if you use another Linux server as your backup device but I have not found a solution for a Synology NAS device.