Sync ext SD to USB OTG **without** using a PC Device Details


Moto X Play - Android 6.0.1, Rooted (Systemless root)
Samsung 64 GB ext SD
San Disk 128 GB USB - came shipped with FAT 32 reformatted to exFAT since I have folders > 4 GB on external SD 


Use Case

Sync entire contents of ext SD to USB (one way sync without deletion of SD card contents ) on weekly schedule / on demand , as incremental backup without using a PC ( I do have one but reasons for not wanting to use it are not relevant)

Other Details


USB drive recognised by device correctly connected by standard OTG (Settings &rarr; Storage &amp; USB )
Busybox installed . It came bundled with ROM Toolbox Pro. I haven't used it directly. If another busy box is to be installed, it's fine as long it doesn't clash
Mount points as below





Things tried


Unsuccessful app search- I wasn't able to find an app that can do this (Folder Sync claims to but it can't see USB)
Googling for alternatives
MacroDroid automation fails, since app can't see USB (raised this in app forum)


Question: How can I do this ? I am open to any means 

Please note that I intend placing a bounty of 100 , any answer meeting needs before I post bounty will be awarded similarly (I may delay posting the bounty to ensure I get a solution)

Please avoid solutions that


are not tested - it should have been tested on your device and USB configuration to give it credibility
Involve PC , uploading to cloud, transferring to remote server etc
References to claims from doubtful sources which can't be verified
Involving use of File Managers ( I had mixed results with these but then that is for another question)


Aim of the above is not to deter solutions but to discourage frivolous attempts. If clarity is needed, please ask

I discussed this need on chat and some potential candidates for solution included BusyBox, rsync and Tasker. I know nothing of these means so Please do provide complete details. Being a bounty question (almost), I expect that I should be able to straightaway implement successfully without seeking clarifications.

( Being a rooted device with systemless root, solutions using root are fine. However, if OS is to be modified on any way, please highlight as systemless doesn't permit it, though there is a work around )

I am strapped for time and need to get this working ASAP
As we figured out the solution you now use in chat, this answer should comply with "being tested", "not involving a PC or file manager" and "relying on verified sources". Though in the meantime there was another rsync answer posted, you've asked me to present our solution as well – so here we go:

The rsync command can be used to accomplish that. Taken all your requirements into account (including those mentioned later in chat), the command line would look like this:

rsync -a --delete /mnt/sdcard /mnt/usb


Explanations on the command:


rsync obviously is the executable/command
-a stands for "archive", i.e. keep all attributes. This includes to recursively copying contents (directories, subdirectories, files), keeping filestamps and ownership (the latter usually requires root), preserve permissions, etc. For details, please refer to What is archive mode in rsync? on our sister-site.
--delete takes care to remove files on the target (here: /mnt/usb) which are not/no-longer available at the source (here: /mnt/sdcard)
remaining parameters specify the source to copy from (/mnt/sdcard) and the target to copy to (/mnt/usb). Note that we specified both as directories, so all content, also hidden files, should be included as well (the latter wouldn't if we had used a mask like /mnt/sdcard/*).
Note: make sure to specify the real mount points or at least real directories here (e.g. not the /mnt/sdcard symlink as in the example), or it might just copy the symlink over and think that's all you wanted :)


You might wish to try the above on a small source first to see how it works.



Now that the "how" is covered, question remains: Where is rsync? It usually doesn't come pre-installed on the device, and most Busyboxes seem to not include it either. There once was an app on Playstore called rsync backup for Android, but it's no longer there. As this wiki points out, you can directly download the rsync binary from here¹, then push it to your Android device, and install it. Assuming you've pushed the binary to /mnt/sdcard:

su
mount -o remount,rw /system
cd /system/xbin
cp /mnt/sdcard/rsync .
chmod 755 /system/xbin/rsync
chown root.shell /system/xbin/rsync
mount -o remount,ro /system


The above should be done either in a terminal app or via adb shell.

That done, and successfully tested from a shell prompt, remains the question of automation. I know that tasker can execute shell commands as root (in the past this was done by simply prefix them with an exclamation mark, today there might even be a checkbox for it – I didn't check that for a while), but your Macrodroid might provide that as well. Alternatively, you can do it the Unix/Linux way and utilize Cron, which is provided by Busybox; for details please see: How to use crontab in Android?



Also see:


How to use rsync over USB on Android with adb
the rsync man page for further details on available parameters and possibilities
How to rsync to android (in case you want to advance this to include your Linux machine ;)
RSync is also available on other operating systems, see e.g. this list on Wikipedia
there's another RSync app on Playstore: Acrosync – but it wasn't updated since 2013 and neither is it well rated (2.7 stars at 82 votes)
Backup your Android phone with Rsync describes a similar approach as above, involving different resources
How to automate command line when specific application is launched? (for on-demand syncing; note that e.g. tasker also allows to create widgets for tasks, which then can be "tapped on demand" to execute it)




¹ Of course you can also try to find the original app on sites like APKMirror or ApkPure, or download the app from here – but then you had to first install that app, and afterwards grab the binary from it's data directory /data/data/eu.kowalczuk.rsync4android/files/rsync – which I find a bit inconvenient ;)