The following is primarily a note for myself, but perhaps it can be useful for others as well.
Recently my girlfriend arranged for a new phone subscription and she also picked a new Android phone for me. I am grateful, because while I am keen on computers, I have never liked smartphones a lot, nor do I know much about them. For one, most of them do not have comfortable keyboards (fortunately, there is web-based WhatsApp), their screens are too fiddly and there is no easy way to access the command-line.
The last statement is actually not really true. While I would not know how to run a terminal on my phone itself – and I wouldn’t care to do so, because of the aforementioned fiddliness – it turns out to be rather straightforward to obtain command-line access to an Android phone, also when it is not “rooted”. Namely, one can use ADB – the Android Debug Bridge, a client-server tool that is part of the Android SDK Platform-Tools package.
To download only the SDK’s command line tools, scroll to the bottom of the Android SDK page, obtain and unpack the archive in a directory of your choice. Next, make sure you have your Java runtime environment set up and use
$ <android-sdk-directory>/tools/bin/sdkmanager platform-tools
to install the package. ADB can then be accessed via
using the clear instructions on the ADB homepage, that I recommend reading. We can now make backups of varying degrees of comprehensiveness, copy files back and forth and, moreover, we may access the phone’s remote shell. All these operations are scriptable, too.
Finally, a note about backups: Here the process stalls unless I exclude .apk files, .obb files and system apps – perhaps because the phone is in use? This is not really a problem, since a command such as
$ adb backup -f backup.adb -noapk -noobb -shared -all -nosystem
completes successfully and also backs up everything from the phone’s external SD card. In this way, ADB can be very handy for salvaging data from otherwise inaccessible devices.