AndroidGood and EVO

Using TWRP’s new ADB interface

TWRP command line interfaceOne of the neat new things with Team Win’s Recovery project version 2.8.0.0 was the introduction of an Android Debug Bridge (ADB) interface and support, but there was not documentation to be found (or I was just unable to see it).

Using openrecoveryscript commands and an ADB shell, you can perform most recovery options from the comfort of your computer and keyboard. This means should you want to create a Windows batch file to reboot your phone into recovery, make TWRP back up your device, and then copy the backups into a rolling set of directories so you always have a week’s worth of full backups, you’re set now.

To access TWRP’s command line, get your phone into recovery. You can either choose to reboot to recovery from the ROM, or you can connect and execute “adb reboot recovery” to get things going.

Once TWRP has loaded, “adb shell” will get you to a shell where you can execute most commands you can in ADB. Your TWRP commands are executed via the “twrp” command. These commands include:

  • wipe cache (eg: “twrp wipe cache”)
  • wipe dalvik
  • wipe data
  • backup (switches, name)
  • restore (source, switches)
  • mount (partition)
  • unmount (partition)
  • set variable = something
  • install <folder/filename>
  • and many more

As most of you will be interested in running backups and installs, below is a quick list of how that’s doable.

Backing up

“adb shell twrp backup SDBOM” does your standard backups. You can add a foldername at the end of the command if you want to place the backup in a non-standard location. The TWRP backup command switches are:

-S = System
-D = Data
-C = Cache
-R = Recovery
-1 = special partition 1
-2 = special partition 2
-3 = special partition 3
-B = Boot
-A = Android secure
-E = SD-Ext
-O = use compression
-M = do not create MD5
-foldername is optional and is just the final folder in the full TWRP path

Restoring

adb shell twrp restore <foldername> <switches>” Foldername is the folder that contains the backup you want to restore, and the switches correspond with the ones in the above section. If you don’t supply a switch, it’s assumed that you’re wanting all data restored.

Misc goodies

Before ADB being in TWRP it was possible to script this by creating a list of commands in the file /cache/recovery/openrecoveryscript but this offers a bit more in the way of flexibility as you can script things line by line on the Windows side if you want to.

If you want to create a batch file to create a backup with one click and the phone being plugged in, it should now be a matter of four lines to go from phone just sitting there to phone backed up and rebooted with one click.

The batch file would look something like this:

adb reboot recovery
adb wait-for-device
adb shell twrp backup SDBOM
adb reboot

You could save that on your computer as a one-click backup, or you could go into scheduled tasks and set it so it runs it every night:

make a nandroid batch schedule

If you wanted to script a bit more, you could turn on MTP (or use ADB pull), move files from a backup directory to your computer, etc.

It’s really a cool little addition that brings the ability to easily script from a computer, notepad, and task scheduler rather than a cron job and a temperamental text editor.

You can find all the openrecoveryscript commands over here, and if I’ve missed something amazing feel free to drop me a line as I’ve been kind of buried under work and a baby lately so it’s been catch up on reviews before pitchforks are raised rather than script out neat things with recovery mode.

Pocketables does not accept targeted advertising, phony guest posts, paid reviews, etc. Help us keep this way with support on Patreon!
Become a patron at Patreon!

Paul E King

Paul King started with GoodAndEVO in 2011, which merged with Pocketables, and as of 2018 he's evidently the owner. He lives in Nashville, works at a film production company, is married with two kids. Facebook | Twitter | Donate | More posts by Paul | Subscribe to Paul's posts

Avatar of Paul E King