Starting Monday of this week, I’ve been dealing with cellphone issues caused by a defective LCD screen. Now that I have my replacement phone set up and configured the way I want it, it’s time to transfer all of the data on the internal storage of the old phone to the internal storage of the new phone. There’s a couple ways to do this, but my preference is using rsync over a non-wireless medium. It’s a lot more verbose and reliable than adb push/pull and if set up correctly, I don’t have to stage the files on my computer’s hard drive first. It’s also much quicker and less invasive than setting up a SSH server on one of the phones. The only other way I can think of that will let me transfer data between the two devices without having to stage the data on my computer hard drive is via MTP, which is ungodly slow.

Months ago, I came across https://ptspts.blogspot.com/2015/03/how-to-use-rsync-over-adb-on-android.html, which explains how to, with ADB, configure and start rsync on an Android phone and then set up a port forward using the adb forward command. Since I have two cellphones connected to the same computer and you can’t transfer files between two remote hosts with rsync, the only way to accomplish this is to start the transfer from one of the phones. My solution was use the busted phone to start the transfer. Here’s how I did it.

  1. Using the instructions at https://ptspts.blogspot.com/2015/03/how-to-use-rsync-over-adb-on-android.html, configure, start, and set up the rsync port forward on the receiving device.
  2. Assuming you used the same remote and local ports listed in the link from the previous step, use the adb reverse command to set up a reverse tunnel on the sending device:
    adb -s abcd1234 reverse tcp:6011 tcp:6010

    This will bind port 6011 on the sending device (e.g. the device with the serial number of abcd1234) to port 6010 on your computer, which is the port that is forwarding to port 1873 (the port rsync is listening to) on the receiving device.

  3. adb shell to the sending device (e.g. adb -s abcd1234 shell)
  4. Run rsync. In my case, I used the following command:
    rsync -avP -O /storage/emulated/0/ rsync://localhost:6011/root/storage/emulated/0/

For those that are unfamiliar with working with multiple Android devices over ADB at the same time, the -s flag is used to specify the serial number of the device you want to connect to. The adb devices command will print out the recognized devices and their serial numbers.