0

What is the right or the best way to backup and restore android app data by terminal emulator in a rooted phone?

su -c cp -r /data/data/the.app.id /sdcard/the/backup/directory can copy the app data, but copying them back will cause some problems. For example, the owner and group of them are not correct, permissions are not right, only root can access them.

I've searched for a while and got some solutions that I don't want. adb backup the.app.id needs a computer. Some apps cannot access sdcard, so switching to it then copying is not possible. Also, to copy it, iterate through the whole directory and chmod with root takes a lot of time and may not work.

If the question needs more explanations, please tell me by comment. Thanks for reading or answering this.

Kirk
  • 121
  • 9
  • adb backup doesn't necessarily need a computer if your device is rooted. Helium Backup uses this approach on-device. But to use it from a terminal, you'd need at least an adb executable. AFAIR that's not there anymore by default since Android 6. Also note that apps can opt-out of ADB's backup (devs can set ALLOW_BACKUP:FALSE in the Manifest). To work around that, there's an Xposed module (not sure about other approaches to it). – Izzy Jan 03 '18 at 10:44
  • I'm using Android 5.1, and I have adb in my system naturally. But adb connect doesn't work. adb connects phone to a computer with a usb cable, but how to use adb in the phone to connect into the same phone? I tried Titanium Backup, it doesn't work on my phone. Just found Helium backup and its adb approach, trying it now. – Kirk Jan 03 '18 at 10:58
  • What about copying out the data with root when backup. When restore, install the app and add the user(u0_aXX) to sdcard_r group then copying back to /data/data? – Kirk Jan 03 '18 at 11:01
  • adb backup the.app.id got adb: unable to connect for backup. Helium works fine! – Kirk Jan 03 '18 at 11:20
  • I've never tried that on-device. But I assume what Helium does is starting the daemon via TCP/IP and connecting to that. Why TiBu should not be working on your device I cannot tell, as "doesn't work" doesn't give a clue on where it fails :) – Izzy Jan 03 '18 at 13:29
  • 1
    Yeah, working on it. Thank you!! https://android.stackexchange.com/questions/142533/run-adb-command-inside-the-terminal-emulator-or-programmatically-without-root – Kirk Jan 03 '18 at 13:50
  • Really sorry for bothering you, after searching a lot, I found you have answered this question before: https://android.stackexchange.com/questions/139948/how-to-back-up-an-apps-data-manually – Kirk Jan 04 '18 at 15:49
  • the tar command can do it, I've marked this question as "duplicated" to close it according to https://meta.stackexchange.com/questions/10841/how-should-duplicate-questions-be-handled – Kirk Jan 04 '18 at 15:51
  • Careful with the restore then. If you try that on a new (or factory-reset) phone, you'll need to adjust ownership of each file and directory to match that of the app it belongs to – as on a new install, the app will get a new userID. – Izzy Jan 04 '18 at 17:29
  • Yes, use chown -R to change the owner – Kirk Jan 06 '18 at 07:22

0 Answers0