Saturday, January 25, 2014

Transfer files off your Android phone: use Droid NAS as an SMB server with a Mac or Linux

If you are getting a getting rid of an Android phone  or device, it's best to make a full backup before you factory reset it.   While, there are many ways to transfer files off of your Android device, I wanted to get everything by viewing my Android files from another "client" computer (which is where I'll copy the Android data).  The steps are:
  1. Export the Android files via the SMB/ CIFS protocol (which is how Windows shares files across computers)
  2. Mount the exported Android  "shares" (the root folders/directories) on a client computer, which can be either Mac or Linux, so you can see the Android files.  (It has been reported that windows will not work as Droid NAS exports via a non standard port; I have not verified if there is a workaround.)  Note: to use Linux you need to be able to run programs as root via sudo.
  3. Copy the files on the client from the Android device to your client computer, using rsync.
(1) Export or expose your Android data to another computer.
There are many Android programs that run as an SMB server.  The one I used is Droid NAS.   After starting the server in Droid NAS, it shows the IP of the Android device and a port, for example 7777, which is the value I will use in the following examples.  There are three profiles "Home", "Work", and "Cafe".  I chose "Home".  I also went to Settings (the gear icon on the bottom left) and specified the wi-fi network on which to export, and I added a user and password, which I'll assume are "uuu" and "pppp" in the examples.  To get these new settings applied, I stopped the server and restarted it.

(2) To see the Android files do either of the following:
On a Mac, in the finder, you should see the Android device in the Shared Section.
Since we added a user and password, you'll have to connect as user uuu with your password pppp.  The finder should show several "shares" that you can "connect" or "mount" on your Mac.

On my phone, I had four shares: Camera, Downloads, Photos and SD Card.  You may have more or fewer shares.

On a linux machine: Verify your linux kernel supports cifs.  You should see a line with cifs when you run
  % grep cifs /proc/filesystems
If you don't see anything, try using smbfs instead of cifs.  If you still don't see anything, you need a newer kernel.  Stop now.

(Optionally, though I never got this to work) verify you can see the Droid NAS as an SMB server:
 % smbclient -L Android-IP-address -p port -U uuu

Mount a share on the linux client.  First make a directory on the Linux cilent where the Android files will be mounted, say /mnt/Android/Camera.
  % sudo mkdir -p /mnt/Android/Camera

 Mount the Android share via the following command.
  % sudo mount -o ro,port=7777 -t cifs -o username=uuu,password=ppp //Android-IP-address/Camera /mnt/Android/Camera

(3)  Copy the files to your client computer.
On the mac:
  (a)  drag the Android shares where you want to copy them.  If this does not work, perhaps because you have too many files and the finder seems to time out getting all the files to copy
  (b) Open a terminal on your Mac and type
   % df
  See where the Android shares are mounted (look in the last column), e.g. /Volumes/Camera
  Copy each share them with rsync via
  % rsync -axv /Volumes/Camera /folder/holding/the/backup

On the linux machine, run rsync
  % rsync -axv /mnt/Android/Camera /folder/holding/the/backup

No comments: