2

I would like to extract my Android database so I can examine it, but I cannot figure out how. I am aware of the two common methods (e.g., adb pull and copying to the SD card). I have successfully used the "copying to the SD card" method before, but neither one of those methods is working for me now.

I say "now" because I switched to a pre-populated database with this version of my application using this method.

When I use adb shell and cd to /data/data/com.myapp/databases/, this is what I see when I run ls -l:

drwxrwx--x    u0_a106    u0_a106    2017-07-19 11:03    cache
drwxrwx--x    u0_a106    u0_a106    2017-07-19 11:03    databases
lrwxrwxrwx    install    install    2017-07-19 11:03    lib -> /data/app-lib/com.myapp
drwxrwx--x    u0_a106    u0_a106    2017-07-19 11:03    shared_prefs

Notice that even though I am in the proper "databases" sub-directory, there is still another "databases" directory underneath that.

Now, when I execute this command:

run-as com.myapp ls -l databases

I see this:

-rw-rw----    u0_a106    u0_a106    21504    2017-07-19 15:53    MYDB
-rw-------    u0_a106    u0_a106     8720    2017-07-19 15:53    MYDB-journal

There is my database, in that (one level deeper) "databases" directory. I have tried using the adb pull command, but Android tells me /data/data/com.myapplicaiton/databases/MYDB does not exist.

So, I tried the next level, and still I get /data/data/com.myapplicaiton/databases/databases/MYDB does not exist.

Then I tried using the "copying to the SD card" method. I get a database, but it is 0 bytes in size.

Weird, because I can obviously see the database exists and it has a size larger than 0 bytes.

So ... what is going on, and how can I get my database?

Thanks.


EDIT:

Per a request, I'm adding the code I use to extract the database:

adb shell run-as com.myapplication cat /data/data/com.myapplication/databases/MYDB > /mnt/ext_sdcard/MYDB.db

I also tried:

adb shell run-as com.myapplication cat /data/data/com.myapplication/databases/databases/MYDB > /mnt/ext_sdcard/MYDB.db

Then I use adb pull /mnt/ext_sdcard/MYDB.db to retrieve it from the tablet.

Brian
  • 1,726
  • 2
  • 24
  • 62

1 Answers1

0

You can get any file that resides in the /data/data/package_name folder of a debuggable app using the command

adb exec-out run-as package_name cat remote_file > local_file

In your case it will look like this

adb exec-out run-as com.myapp cat databases/MYDB > target_file

kws
  • 926
  • 7
  • 11
  • I tried that, it doesn't work. All I get is a db file that has 0 bytes. – Brian Jul 21 '17 at 20:48
  • It gives you 0 bytes because it can't find the file. Check the path again. Methods [`getPath()`](https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#getPath()) and [`getDatabasePath()`](https://developer.android.com/reference/android/content/Context.html#getDatabasePath(java.lang.String)) will help you find it. – kws Jul 21 '17 at 22:32