4

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 → Storage & 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

enter image description here enter image description here

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

beeshyams
  • 40,739
  • 30
  • 119
  • 269

2 Answers2

3

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 . I know that 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:


¹ 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 ;)

beeshyams
  • 40,739
  • 30
  • 119
  • 269
Izzy
  • 91,166
  • 73
  • 343
  • 943
  • Thank you, the solution worked fine for me. A couple of points that may help the readers : 1. I tried with all Busybox versions, which are well rated and none of them have rsync available the pro version of this ( I mailed developer requesting him to add it), so that leaves with no choice but other means ( incidentally couldn't find the app on reputed sites mentioned ) 2. Automating the execution of command on demand / schedule successful. Instructions here – beeshyams Dec 17 '16 at 16:10
  • TWRP could see the backup on USB , so presumably it should execute fine 4. Same with TiBu , though this requires a bit of workaround (Backup folder location > Storage Provider, click on that and choose options per your OS Version) 5. Though you are not a windows user, for the sake of completeness, you may consider adding extension of rsync on windows as well, as you did for Linux- I did see references. Will add more later if it can help readers
  • – beeshyams Dec 17 '16 at 16:26
  • @beeshyams http://ptspts.blogspot.com/2015/03/how-to-use-rsync-over-adb-on-android.html has instructions on where you can find and manually install rsync for Android. You'll have to be a little creative since you don't want to use a PC. I'd recommend trying to use webget and Root Explorer to download, rename, set +x, and move the binary. – Chris Olin Dec 18 '16 at 04:41
  • @ChrisOlin: Thanks and I had seen that earlier, but not being familiar with Linux, did it the awkward way of downloading the app and extracting rsync and shared it with Izzy and he included that in his answer., In foot notes. Doing it can be learnt, but at a later time, when time permits. – beeshyams Dec 18 '16 at 05:52
  • Update : Verified TWRP and it restores fine from OTG. TiBu runs into problems. It sees the copied folder on USB but unable to select for restore. However, if I create a new Backup folder on USB , it restores. In case of extSD being replaced, I suppose copying the backed up folder should work since all attributes and permissions are intact – beeshyams Dec 18 '16 at 06:18
  • @beeshyams Are you using DocumentProvider storage? If you are and it's still not working, SELinux might be preventing Titanium Backup from reading media from the flash drive. – Chris Olin Dec 19 '16 at 08:44
  • @ChrisOlin: unfortunately, that isn't the case. Just rechecked it is Permissive . Seeing mixed reports on net, works for some, didn't for others. Not sure why – beeshyams Dec 19 '16 at 09:14
  • @ChrisOlin: Besides, as mentioned I can create and backup from a new Backup folder , so read/ write access is not the problem – beeshyams Dec 19 '16 at 09:44
  • SELinux contexts are configured a bit differently than traditional Unix file permissions. I've encountered that exact issue with SELinux preventing Titanium Backup from accessing backup data and causing exactly the same issue you're describing. – Chris Olin Dec 20 '16 at 05:41