Backing up between two My Passport Wireless devices

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

1 Like

This is quite interesting. I was not aware the WD Passport Wireless could be customized this way even though it theory it’s possible since it’s a small NAS.

Regards,

Yes, what makes this possible is the very nice and full-featured Linux system that Western Digital put on the MyPW device.

In fact, you can use the basic script I provided to do automated backups of multiple servers onto your MyPW device, as long as you set up the .ssh/authorized_keys file on the servers that you want to back up so that you can ssh into that server from your MyPW device.

Best regards,

—Kayvan

In fact, I suspect that you could even do something like this with your MyPassport Wireless if you wanted to…

https://gist.github.com/sled/7745097 (Guid to cross compile transmission 2.82 for Western Digital MyCloud).

Which would turn your MyPW into a torrent/download box.

Of course, doing such things voids your warranty, but it’s easy to undo any/all modifications by performing a system reset of the device.

—Kayvan

A quick followup.

I changed the interval for the cron job to be once every half hour. I’ve had a couple of weeks now of using this and it’s worked flawlessly.

All the details are now here:

https://github.com/ksylvan/MyPassportWirelessHacks

Once you’ve set up rsa key ssh, you can simply run a one line rsync command to do that.

rsync -e ssh -rlptvogD source-device:/path/to/backup/ target-device:/path/to/store/backup/

You can add exclude-files on the CLI or in a txt file, and even put that right in crontab. Rsync is a powerful tool.  I’ve used it in production environments to publish content, backup db files and even just as a way to restore a user directory to a default at every logout.  It handles all the heavy lifting, if a part of a file changes, it sends the change, if nothing changed, nothing happens.  Add a new directory on source, it will create it on the target.

Yes Phil. It’s a great tool. The automated setup works beautifully.

PhilLesh69

you write, that even rsync over ssh can be done.

When I use a remote site as a source it worked for me.

When I use to copy from the Passport Wireless to a remote site over ssh, I get “rsync error: some files/attrs were not transferred (see previous errors) (code 23) at sender.c(219) [sender=3.1.0]”

The same command works under Ubuntu or Mac OS X as an initiator. 

Here the command: rsync -rcltDve ssh /DataVolume/test.txt username@rsync.hidrive.strato.com:/users/username/b
ackup

I have the same problem with other rsync servers.

Any idea? Somebody successfuly done it?

yjogol

This error bugged me now for hours. There seams to be a bug in rsync 3.1.0 10372 – rsync 3.10 error in protocol data stream while rsync 3.0.9 runs through

Just grab the latest ARMel binary (3.1.2-X) from the deb archive file Debian -- Package Download Selection -- rsync_3.2.7-1_armel.deb and copy it to somewhere under /DataVolume/XXX (to no overwrite the original one)

Rsync local to remote location (e.g. Synology NAS) through SSH works now! :slight_smile: