Skip to content

Instantly share code, notes, and snippets.

@brettp
Last active April 26, 2019 03:28
Show Gist options
  • Save brettp/3671489 to your computer and use it in GitHub Desktop.
Save brettp/3671489 to your computer and use it in GitHub Desktop.
Copying the "SD card" contents between rooted Android devices that don't have a physical SD card using abd

Backup media partition

adb forward tcp:7080 tcp:8080
# from another terminal on same machine (or run adb cmd directly)
adb shell 'tar --exclude=/data/media/0/TWRP -Jcvf - /data/media | nc -p 8080 -l 1>/dev/null'

# original terminal
nc -w15 localhost 7080 > media.tar.gz
adb forward --remove tcp:7080

Old SD rsync method

There is no apparent way to transfer the content of the "SD card" between devices while preserving file times. This is problematic because many apps sort by file creation / modification time. Below is a method that uses rsync on rooted devices to accomplish this. It is possible to do this strictly on the phones, but it is significantly slower because of the wifi connection. Coping files to a host machine, then to a new device over USB is much faster than wifi.

We start an rsync server on the source device, use adb to forward it to a local port, then pull the contents onto our host. Then we switch devices and use the same technique to push back to the target device.

To start:

  • Install ADB on your computer.
  • Install rsyncdroid or SSHelper on both devices.

On the source device:

  • Start rsyncdroid and change the configuration of the [sdcard] module to point to /data/media/ instead of /sdcard. (Required because of permission issues due to emulating a real SD card.)
  • Click the "Start" button at the bottom.
  • Connect to USB.
  • ./adb forward tcp:10500 tcp:873
  • sudo rsync -azv rsync://root@localhost:10500/sdcard/ sdcard/
  • Disconnect when done.

On the target device:

  • Start rsyncdroid and change the configuration of the [sdcard] module to point to /data/media/, and change read_only to no.
  • Connect to USB.
  • ./adb forward tcp:10500 tcp:873
  • sudo rsync -azv sdcard/ rsync://root@localhost:10500/sdcard/
@lianglee
Copy link

hmm, nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment