1

I'm trying to download my sqlite database so that I can review it's contents (our app does online offline sync, and I'm trying to ensure it's only pulling down what it's supposed to from the API).

I'm trying to use adb pull /data/data/com.mycompany.myapp/files/db.sqlite3 but I keep getting permission denied.

I've tried logging in via shell and copying it to the SD card, but I get permission denied there as well (and I don't want to add SDCard access in my Manifest).

$ adb shell
$ run-as com.mycompany.myapp
$ cd files
$ cp db.sqlite3 /mnt/sdcard/db.sqlite3
$ PERMISSION DENIED

Without ROOT permission, how do I download my sqlite file from my android device to a location that will allow me access?

Chase Florell
  • 46,378
  • 57
  • 186
  • 376

1 Answers1

3

Downloading is (as you see) quite tricky, but not impossible.

Here's the steps to grab the file and move it to your local machine.
note: I'm on Windows, but this can be done on other devices as long as you know your local paths.

$ adb shell                         // enter into shell
$ run-as [com.mycompany.myapp]      // log in as your app
$ cd [files]                        // navigate to the path of the file you need access to.
$ chmod 0644 [db.sqlite3]           // DANGEROUS: change the permissions of said file allow you access via adb pull
$ {ctrc} + {c}                      // Exit Shell
$ adb pull [/data/data/com.mycompany.myapp/files/db.sqlite3] [c:\db.sqlite3] // pull the file to your local machine.

From there, you can navigate to your output directory and access the file.

note: anything in [square braces] is a variable that you will fill with your own variables.
note: {ctrl} + {c} is in PowerShell on Windows, other platforms can be different.

I've also created a simple Powershell script that does this automatically.

$appName = 'com.mycompany.myapp'
$dbName  = 'db'

adb shell "run-as $appName chmod 644 /data/data/$appName/files/$dbName"
adb pull "/data/data/$appName/files/$dbName" "./$dbName.sqlite3"
Invoke-Item ".\$dbName.sqlite3"
Chase Florell
  • 46,378
  • 57
  • 186
  • 376