Skip to content

Instantly share code, notes, and snippets.

@romulof
Created May 16, 2015 05:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save romulof/6af8a8919660f395f975 to your computer and use it in GitHub Desktop.
Save romulof/6af8a8919660f395f975 to your computer and use it in GitHub Desktop.
Simple shell script to download Android SQLite database to your computer using a few `adb` commands. Based on: https://stackoverflow.com/a/12914297/314055
#!/bin/bash
REQUIRED_ARGS=2
PULL_DIR="./"
if [ $# -ne $REQUIRED_ARGS ]
then
echo "Usage: $0 [package_name] [db_name]"
echo ""
exit 1
fi;
eval "adb -d shell 'run-as $1 cp /data/data/$1/databases/$2 /data/data/$1/databases/$2-copy'"
if [ $? -ne 0 ]
then
echo "Error cloning database"
echo ""
exit 1
fi;
eval "adb -d shell 'run-as $1 chmod 666 /data/data/$1/databases/$2-copy'"
if [ $? -ne 0 ]
then
echo "Error changing clone permission"
echo ""
exit 1
fi;
eval "adb -d shell 'cp /data/data/$1/databases/$2-copy /sdcard/$2'"
if [ $? -ne 0 ]
then
echo "Error coping to /sdcard"
echo ""
exit 1
fi;
eval "adb -d shell 'run-as $1 rm /data/data/$1/databases/$2-copy'"
if [ $? -ne 0 ]
then
echo "Error removing clone"
echo ""
exit 1
fi;
eval "adb -d pull /sdcard/$2 $PULL_DIR"
if [ $? -ne 0 ]
then
echo "Error downloading"
echo ""
exit 1
fi;
eval "adb -d shell 'rm /sdcard/$2'"
if [ $? -ne 0 ]
then
echo "Error removing /sdcard copy"
echo ""
exit 1
fi;
exit 0
@romulof
Copy link
Author

romulof commented May 16, 2015

Works on Nexus 5 running Lollipop 5.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment