How to get a Backup of Your Android App’s Database in Windows

Getting a backup of your Android application’s database can be as easy as issuing a command for a virtual device:

adb pull /data/data/your.package.name/databases/database_name.db

On a physical device it gets a bit harder. First you need to enable USB debugging for it. Starting with Android 4.2 you actually have to enable the developer options first by tapping the build number 7 times. Then those options will allow you to enable USB debugging.

For security reasons adb pull doesn’t work on non-rooted devices. Dumping the database with SQLite3 doesn’t work for the same reasons. And SQLite3.exe won’t be installed on your device anyway as it’s only the command line client and applications don’t need it to access SQLite databases.

Another option is to copy the database to the device’s SD card and access it from there:

adb -d shell
run-as your.package.name
cat /data/data/your.package.name/databases/database_name.db > /sdcard/database_name.db

This requires the application to be built as debuggable and obviously your device must support SD cards. If your device’s mastermind says “Everybody likes the idea of having an SD card, but in reality it’s just confusing for users” your last hope is having at least Android 4.0. This version introduced the adb backup command:

adb backup -f /data.ab -noapk your.package.name
Now unlock your device and confirm the backup operation.

Your device will show an appropriate confirmation dialog with an option to encrypt your backup if you enter a password. To keep it simple don’t do that and press “Back up my data”. This will create the file “c:\users\account_name\data.ab”.

A Linux system could extract the file’s content with a single command line command. On Windows systems you have to download “Android Backup Extractor”. From it’s .zip file copy “abe.jar” to “c:\users\account_name\”. Then run this from the command line and ignore the warning about “You are not allowed to use strong AES encryption”:

java -jar abe.jar unpack data.ab data.tar

You can open the resulting file “c:\users\account_name\data.tar” for example with 7zip and extract “\apps\your.package.name\db\database_name.db”.

Finally you can access your database backup:

"C:\Program Files (x86)\Android\android-sdk\tools\sqlite3.exe" database_name.db

Update 2013-05-01

Some additional info from doing this again after a few months:

  • You’ll find adb.exe (Android Debug Bridge) in “C:\Program Files (x86)\Android\android-sdk\platform-tools”. So the backup command becomes "C:\Program Files (x86)\Android\android-sdk\platform-tools\adb" backup -f /data.ab -noapk your.package.name
  • If you mistype your.package.name you’ll still see the success message but nothing will actually happen.
  • The command line program (cmd.exe) in Windows shows the current directory in it’s prompt. That is usually “C:\Users\account_name>” and will be the directory your data.ab file gets copied to.
  • Hmm… data.ab landed in “C:\Users\account_name\AppData\Local\VirtualStore” this time. Probably because I didn’t run cmd.exe as an administrator now. But doing so leads to a command prompt of “C:\Windows\system32>” so I’m unsure how data.ab ended up in “C:\Users\account_name>” in the previous round.
  • Some recent Android update added an additional confirmation screen before starting the backup asking whether you want to allow access from the specified computer.
  • You prefer a GUI for manipulating your database once you got the backup? Use SQLite Manager, an add-on for FireFox. Install it, restart FireFox and find it’s menu item in “FireFox” > “Web developers”.

Update 2016-08-04

Adding some code to copy the database file may be an easier solution and it works without an SD card. I added a link to a recent post and one to a standalone browser for SQLite databases.

Additional References

Advertisements
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

5 Responses to How to get a Backup of Your Android App’s Database in Windows

  1. Doug says:

    Hi,

    Maybe you can help me. From a command prompt in the directory where adb.exe resides, I typed the following: adb backup -apk -shared -all -f C:\Users\doug\backup.ab
    I then went to my USB connected phone to confirm the backup. The correct screen displayed, I didn’t enter a password. But, no matter how many times I pressed ‘back up my data’, it wouldn’t execute. However, the moment I pressed ‘do not back up’, that line highlighted itself in ‘holo blue’ and adb stopped.
    Can you think of some setting I have set incorrectly to allow the Full Backup?

    Motorola Droid Maxx with JellyBean

    Thanks!
    -doug

  2. Doug says:

    I forgot to mention that the phone isn’t rooted. I do have a PIN lock screen. I’ve tried with it locked first or unlocked. No difference. ‘back up my data’ presses just don’t do anything. However, adb places a zero byte file in the path I specified.

    -doug

  3. Thanks for the post! This worked. That was definitely an adventure.

  4. Jason says:

    Hey, great post – I’m at a dead end however. I’m trying to extract my notes from my phone that I lockd myself out of months ago. Last ditch effort to recover data before wiping the phone.

    /data/data/com.akproduction.notepad/databases/aknotepad.db

    Unfortunately AK Notepad does not appear to be debuggable so I’ve resorted to the backup option you outlined. The catch is I cannot use the device to confirm the backup and follow suit. What are my options from here?

  5. santosh says:

    thanks for the post, i could take a backup and read the db

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s