2

My rooted Moto G is stuck in a bootloop. I want to backup a specific app.

is enabled. I have access to and recovery. I have tried wiping cache and dalvik cache and even flashing the ROM again. Now I need to wipe the internal storage to make my phone work.

The device does not have an SD card slot. I need to backup an app before wiping all of my data. Other data like pictures, documents, etc., is already backed up by using cable and pen drive.

I tried using ADB to backup but I cannot confirm the backup on my phone as no such screen is shown in recovery mode. Can I just copy and then paste some files to restore the app?

2

You would need a custom recovery for this solution and it appears that you already have TWRP installed.

Setup in PC, if not already. Boot into recovery mode. Mount data partition. Find the package name of your app, if don't know already and execute these commands:

adb shell 
busybox tar -C / -cvzhf /sdcard/PACKAGE_NAME.tgz data/app/PACKAGE_NAME* data/data/PACKAGE_NAME  # replace PACKAGE_NAME with package name of the app

The last command will create a tarball with extension .tgz under /sdcard with name as package name of the app. The tarball would contain the app's APK (among other things) and app's private data. Files' ownership and attributes would be preserved automatically. Extended attributes (such as SELinux context) won't be preserved in this command.1

Your app may be having publicly accessible data under /sdcard/Android. You can simply use adb pull or MTP to copy those files into PC and restore them using adb push or MTP, when needed.

To restore the backup, do:

adb shell
busybox tar -C / -xvzhf BACKUP_PATH   # replace BACKUP_PATH with the file path of your backup, such as /sdcard/PACKAGE_NAME.tgz
restorecon -FRv /data/data/PACKAGE_NAME  # this will set default SELinux context on the data files of your app

Unmount data partition, reboot and you should be able to find your app in restored state.

Note: I've tested this solution on an unofficial CM13 build.


1 I noticed that bionic build of busybox (found in TWRP v2.8.6.0) among other arguments has -p for tar which is used to store SELinux contexts. If the file was created using that argument, then during extraction those contexts would be restored automatically, hence, no need to run restorecon explicitly.

  • 1
    Execute busybox tar to know what those commands are doing. – Firelord Feb 14 '16 at 14:45
  • 1
    I wiped my phone but I will try this method next time my phone blows up. Thanks a lot! – Utkarsh Barsaiyan Feb 15 '16 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.