You would need a custom recovery for this solution and it appears that you already have TWRP installed.
Setup adb 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.