Here is a guide on how to setup rsync daemon on mycloud gen2 device.
-
To run rsync daemon you will need a configuration file and a secret file (for password storage). By default they should be created as /etc/rsyncd.conf and /etc/rsyncd.secrets. However /etc/ is cleaned on every reboot, so to avoid this let’s create this files in some of your shared folder.
-
Your shared folders are in /dev/sda2 mounted at “/mnt/HD/HD_a2/”, you can use ls command with tab completion over ssh to find it out. For rest of this guide I will use “/mnt/HD/HD_a2/BackUP” folder.
-
Use vi or nano to create secrets file
vi /mnt/HD/HD_a2/BackUP/rsyncd.secrets
add your “username:password”, one per line, you can keep password blank. In my case it like this
#cat /mnt/HD/HD_a2/BackUP/rsyncd.secrets
root:
sharad:
- Now create rsync configuration file, in my case this is
#cat /mnt/HD/HD_a2/BackUP/rsyncd.conf
#rsync --config=/mnt/HD/HD_a2/BackUP/rsyncd.conf --daemon
log file=/var/log/rsync.log
[shares]
path=/mnt/HD/HD_a2/
uid=0
gid=0
auth users=root:rw,sharad:rw
read only=no
list=yes
secrets file=/mnt/HD/HD_a2/BackUP/rsyncd.secrets
hosts allow=pathy
Here [shares] is the name of module, you use with rsync daemon, you may have multiple modules.
only users under ‘auth users=’ can connect with the daemon, rw is for read and write access, ro for readonly.
Put your path to secret file in ‘secrets file=’
in ‘hosts allow=’ you can use either host name of host ip address like ‘192.168.1.101:255.255.255.0’, multiple hosts can be used (comma separated)
- Now run rsync like this
rsync --config=/mnt/HD/HD_a2/<yoursharefolder>/rsyncd.secrets --daemon
-
You will need to restart rsync every reboot, or if you have installed WDCrack you can add the rsync line to “/mnt/HD/HD_a2/Nas_Prog/init.sh”
-
Doing the BACKUP
You will need to run rsync from your host computer to connect with rsync deamon on mycloud and transfer it’s data. For this you will need ipaddress of mycloud , name of the module (we uses shares), allowed users and their password.
rsync --<options> </path/to/backup/folder> rsync://<user>@<mycloudip>:<portofrsync>/<module>/<sharefolder>
Once you run this if rysnc will ask for your password on command line, give the password as per your rsyncd.secrets and transfer will begin.
If you get any errors, check the /var/log/rsync.log on mycloud, to find out error.
Below is the command I use to backup my entire home folder excluding some folders.
rsync -a --progress --links --safe-links --delete --exclude={".cache/*","Music/*","Downloads/*","Videos/*","Pictures/*","qemu/*","mount/*"} /home/sharad/ rsync://root@192.168.0.101:873/shares/BackUP/home
- Scripting and running backup automatically
To use rsync in script you will need to specify your password as environmental variable before running above code. Here is the example I use (in my linux machine running archlinux). Here I am using blank password. I am running this script as root user otherwise some of the file will be unreadable on my host, suite your needs.
#!/bin/bash
# use with "su"
[ $(id -u) != 0 ] && echo "must run as root user" && exit
##########################################
#### RSYNC OVER SSH WITH RSYNC DAEMON ####
##########################################
# avoid password prompt #
export RSYNC_PASSWORD=""
# backup home # --links is required for --safe-links to have any effect
rsync -a --progress --links --safe-links --delete --exclude={".cache/*","Music/*","Downloads/*","Videos/*","Pictures/*","qemu/*","mount/*"} /home/sharad/ rsync://root@192.168.0.101:873/shares/BackUP/home
# backup /etc configs
rsync -a --progress --links --safe-links --delete /etc/ rsync://root@192.168.0.101:873/shares/BackUP/etc```
To run this automatically you can use cronjob on your host machine.