Transferring files from Debian GNU/Linux to Android phone with rsync
Transferring data off of an Android phone with ADB and rsync is straightforward, but rsync
issues appear when transferring files onto the phone. Tl;dr use the --size-only
option with rsync
. Android does not allow the “mtime” or modification time of files to be updated on copy, so when it looks at the files already on the destination, it sees that the mtime does not match and tries to copy again. This defeats the purpose of rsync
and seems to result in errors. Thanks to StackExchange contributor Greg Alexander for this upsight. Full script below:
sudo apt update
sudo apt install -y jmtpfs rsync fuse3
read -p 'ENSURE ANDROID IS CONNECTED WITH USB AND SET TO FILE TRANSFER MODE' ;
mkdir -p /tmp/phone ;
jmtpfs /tmp/phone ;
sleep 5 ;
rsync --recursive --force --size-only --info=progress --verbose ~/Music/ /tmp/phone/Internal\ shared\ storage/Music/ ;
echo 'LOADED MUSIC ONTO PHONE' ;
fusermount -u /tmp/phone ;
echo 'UNMOUNTED PHONE'"