Hi everyone,
I read this post earlier: WD-My-Cloud/Success-3-rsync-backup-between-My-Cloud-devices and I tried to do it with my two MP Wireless devices.
The way this poster did it, they mounted the other drive using cifs (smb protocol) but no matter what I tried, I couldn’t get the “mount -t cifs” to work, even though I can do it from a Fedora linux box like this:
sudo mount -t cifs -o username=guest,password= //192.168.1.101/public /mnt/mp2
But doing the same from my other device I see this:
root@Home2 (~)# mount -t cifs -o username=guest,password= //192.168.1.101/public
/mnt
mount: mounting //192.168.1.101/public on /mnt failed: No such device
root@Home2 (~)#
I’ve tried all sorts of permutations for the syntax, but have not gotten that piece to work. So if anyone has any ideas, I’d love to hear them.
In any case, my next approach: I thought I could get a pure ssh/rsync solution to work.
When you ssh into the MyPW device, you notice that there’s a pretty full featured Debian/Linux system in there (THANK YOU Western Digital — so awesome!) but a few things need to be adjusted.
First thing: ssh requires strict permissions on the home directory for key based (non-interactive) logins to work.
So, I had to do this:
# chmod 755 /home/root
I did this for both the sending and receiving MyPW devices.
Next, generate the keys and set up the authorized_keys file on the receiving side:
cd /home/root
ssh-keygen
ssh-keygen -t dsa
ssh-keygen -t ecdsa
cat .ssh/id_rsa.pub | ssh 192.168.1.101 'mkdir .ssh; cat >> .ssh/authorized_keys'
Now, you should be able to just ssh to the other box (the one you want to backup) without needing a password.
Having set this up, I put the following in /DataVolume/Backup/backup:
#!/bin/sh
#
# Author: Kayvan Sylvan
#
# Automated rsync+ssh backup from WD My Passport Wireless device
#
cd $(dirname $0)
my_script=$(pwd)/$(basename $0)
usage() { echo "Usage: $0 [setup | doit]"; exit 0; }
if [$# -ne 1]
then
usage
exit 0
fi
# Change these for your setup
#
src=192.168.1.101:/DataVolume/
DESTDIR=/DataVolume/Backup/mwp_backup
LOG=/DataVolume/Backup/rsync.log
WHEN="0 2 * * *" # cron specification (2AM every day)
CRON_INIT=$(ls /etc/init.d/*cron*)
MY_CRON_FILENAME="backup_my_data"RSYNC_OPTS="-avz -h --progress"
if [! -d $DESTDIR]; then mkdir $DESTDIR; fi
case "$1" in
setup)
echo "$WHEN root $my_script doit" > /etc/cron.d/$MY_CRON_FILENAME
$CRON_INIT restart
;;
doit)
START=$(date)
echo "About to rsync $SRC to $DESTDIR" > $LOG
rsync $RSYNC_OPTS root@$SRC $DESTDIR >> $LOG 2>&1
echo "STARTED at $START - ENDED at $(date)" >> $LOG
;;
*)
usage;;
esac
Now, edit the script (set up the IP addresses and locations, and choose the time for backups) then run the “setup” part to set up your cron job, like this:
# chmod +x ./Backup/backup# ./Backup/backup setup
Shutting down crond services: done
Starting crond services: done
After this, your backups should happen at the specified times.
Putting the backup script on the DataVolume is important, because it won’t be lost when you do firmware upgrades.
Test it by running the script by hand once (after which the rsync will happen much faster).
Best regards,
—Kayvan