ÈÐ Wïgê† Ðð† ñåmê

ïñ£ð§ê¢, ïñ£ðrmå†ïðñ §ê¢µr, Ðïgï†ål £ðrêñ§ï¢§, hå¢kïñg, §¥§†êm åÐmïñ阮rå†ïðñ, lïñµx ßlðg

Western Digital PR4100 Built-in rsnapshot backup from remote server

, , , ,

So I recently bought a Western Digital PR4100 NAS drive to backup my Linux Desktop and Laptop after losing 2 external usb drives in about 2 years.  I had always used rsnapshot to back them up.  While poking around the WD NAS via ssh, I realized it has a binary for rsnapshot installed on it that is relatively recent.  I couldn’t find any of the config files though and I came up with this solution.

The first thing you need to do is set up the sshd user on the WD NAS so you have shell access.

The second thing you need to do is to configure rsync via ssh from your computer to copy the rsnapshot config files into place.  This will need done daily because the WD NAS drive reboots at 3am EST every day.  That reboot only lasts a few minutes so what I did was created a cron job that passes the sshd users password via sshpass to create a non-interactive shell in order to rsync the files.  You will also need to copy the entire /home/root/.ssh folder and all its files to your local server and also install them using rsync because the mycloud device also deletes those files on reboot.  It looks something like this:

Create file sync-mycloud-confs.sh containing:

[codesyntax lang=”bash”]

rsync --rsh='sshpass -p PASSWORD ssh -l sshd' /path/to/rsnapshot/*.conf MyCloud_hostname_or_IP_Address:/home/root/
rsync --rsh='sshpass -p PASSWORD ssh -l sshd' /path/to/rsnapshot/.ssh/ MyCloud_hostname_or_IP_Address:/home/root/.ssh/

[/codesyntax]

In the above you will need to replace PASSWORD with your sshd users password, replace /path/to/rsnapshot/*.conf with your path to them and MyCloud_hostname_or_IP_Address with whatever method you use to ssh into your mycloud device, I use ip address btw.  I may try to find a better place to store these files so they don’t get deleted on device reboots but for tonight, it works there so thats what I am going with before I forget.

The next thing you need to do is set up your cron jobs on the mycloud device.  Believe it or not, logging in as the sshd user allows you to modify the  existing cronttab by simply running:

[codesyntax lang=”bash”]

crontab -e

[/codesyntax]

I split my device into a few different mountpoints for ease of management and backups, but I will just go over the main desktop config.  This is the crontab entries for it:

[codesyntax lang=”bash”]

30 3 * * * /usr/sbin/rsnapshot -c /home/root/Desktop.conf daily > /dev/null 2>&1
0 3 * * 1 /usr/sbin/rsnapshot -c /home/root/Desktop.conf weekly > /dev/null 2>&1 &
30 2 1 * * /usr/sbin/rsnapshot -c /home/root/Desktop.conf monthly > /dev/null 2>&1

[/codesyntax]

And finally the rsnapshot config file for my desktop is named Desktop.conf and it contains:

[codesyntax lang=”bash”]

config_version	1.2

snapshot_root	/mnt/HD/HD_a2/LinuxDesktopBU

no_create_root	1

cmd_cp		/bin/cp
cmd_rm		/bin/rm
cmd_rsync	/usr/sbin/rsync
cmd_ssh	/usr/bin/ssh
cmd_du		/usr/bin/du

retain	daily	7
retain	weekly	4
retain	monthly	3

verbose		3
loglevel	1
logfile	/var/log/rsnapshot.log
lockfile	/var/run/rsnapshot.pid

rsync_long_args	--rsync-path="sudo rsync" --delete --numeric-ids --relative --delete-excluded

link_dest	1
use_lazy_deletes	0

backup	user@ip_address:/boot/	Desktop/
backup	user@ip_address:/etc/	Desktop/	exclude=mtab,exclude=core
backup	user@ip_address:/home/	Desktop/	exclude=Dropbox,exclude=.dropbox-dist,exclude=.dropbox
backup	user@ip_address:/opt/	Desktop/
backup	user@ip_address:/root/	Desktop/
backup	user@ip_address:/usr/	Desktop/
backup	user@ip_address:/var/	Desktop/

[/codesyntax]

One last piece of the puzzle, your mycloud device will need to be able to login to the remote server using a password-less key.  So login to the mycloud device as the sshd user and run ssh-keygen also.  Then you will need to install that public ssh key on your remote server with a user that has sufficient privileges to access all the files and directories you wish to backup, which often means root user which is also why I have rsnapshot performing the backup over ssh.  I will try to find another location but for now, its what I have.


Leave a Reply