Ubuntu – Rsync to mtp mounted android does not work

androidmtprsync

I tried to sync ogg-audio-files to my android device like this:

rsync -av piano /run/user/1000/gvfs/mtp\:host\=%5Busb%3A002%2C005%5D/SanDisk/Music/

===> rsync -av piano/ /run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C007%5D/SanDisk/Music/
sending incremental file list
rsync: failed to set times on "/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C007%5D/SanDisk/Music/.": Operation not supported (95)
...
foo-bar/one.ogg
...
rsync: mkstemp "/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C007%5D/SanDisk/Music/foo-bar/one.ogg.0gzy9t" failed: Operation not supported (95)

But only the directory got created. No file was transfered:

===> find /run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C007%5D/SanDisk/Music/piano

/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C007%5D/SanDisk/Music/piano/foo-bar

How to rsync between my android device and my Ubuntu PC?

I found a work-around: I unplugged the micro-SC card from the android device and inserted it into the sd-card reader of my laptop. But a solution where I don't need to do this would be nice.

Best Answer

Not sure if you need a rooted device for this (I only run rooted LineageOS and am not familiar with other flavours). In LineageOS, /system/xbin/rsync exists by default, else, connect your phone to your PC and start a terminal and execute all of the commands below in the PC's terminal:

sudo apt install wget adb
wget -O rsync.bin http://github.com/pts/rsyncbin/raw/master/rsync.rsync4android
adb push rsync.bin /data/local/tmp/rsync
adb shell chmod 755 /data/local/tmp/rsync
adb shell cp /data/local/tmp/rsync /sdcard/rsync.bin
adb shell /data/local/tmp/rsync --version
  • create a configuration file
adb shell 'exec >/sdcard/rsyncd.conf && echo gid = 0 && echo uid = 0 && echo address = 127.0.0.1 && echo port = 1873 && echo "[root]" && echo path = / && echo use chroot = false && echo read only = false'
  • start the rsync daemon on the device
# on regular Android
adb shell /data/local/tmp/rsync --daemon --no-detach --config=/sdcard/rsyncd.conf --log-file=/proc/self/fd/2
# on LineageOS
adb shell rsync --daemon --no-detach --config=/sdcard/rsyncd.conf --log-file=/proc/self/fd/2
  • on a different shell window, start port forwarding
adb forward tcp:6010 tcp:1873
  • happy copying
rsync -av --progress --stats --partial rsync://localhost:6010/root/sdcard/DCIM .