├── .gitignore ├── LICENSE ├── README.md ├── adb-db-pull.sh └── changelog.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .*.md.html 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | (The MIT License) 2 | 3 | Copyright (c) 2014 Leonard Wu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android SQLite DB Pull (adb-db-pull) 2 | 3 | Shell script to pull SQLite DBs on an Android (virtual) device directly to a connected computer, via ADB. 4 | 5 | The pulled DB file may then be opened and examined using any of the SQLite tools running on the computer. 6 | 7 | 8 | Features: 9 | * List all packages on Android device that have a SQLite database 10 | * List all SQLite databases on Android device under a given package name 11 | * Copy a specified SQLite DB file from Android device to current local directory on computer 12 | 13 | 14 | Prerequisites: 15 | 16 | * A computer runing *nix (Linux, Mac OSX, etc) 17 | * ADB (part of Android SDK) must be installed on computer 18 | * Connected Android device may be a virtual device (ADT Virtual Device, Genymotion, etc) or a _rooted_ physical device. 19 | * Only one Android device may be connected; multiple connected devices may fail with unkown errors 20 | 21 | 22 | ## Installation 23 | 24 | Copy the shell script into a directory on your PATH, e.g., `/usr/local/bin` 25 | 26 | ```sh 27 | $ git clone https://github.com/leonardw/adb-db-pull.git 28 | $ cd adb-db-pull 29 | $ cp ./adb-db-pull.sh /usr/local/bin/ 30 | $ chmod +x /usr/local/bin/adb-db-pull.sh 31 | ``` 32 | 33 | ## Usage 34 | 35 | ```sh 36 | $ adb-db-pull.sh [PACKAGE.NAME [DB_FILE]] 37 | ``` 38 | 39 | 40 | ## Example 41 | 42 | List all packages that have a SQLite database, on a running Android device connected via ADB 43 | ```sh 44 | $ adb-db-pull.sh 45 | Packages with SQLite DBs found on device: 46 | com.android.deskclock 47 | com.android.email 48 | com.android.inputmethod.latin 49 | com.android.keychain 50 | com.android.launcher 51 | com.android.providers.calendar 52 | com.android.providers.contacts 53 | com.android.providers.downloads 54 | com.android.providers.media 55 | com.android.providers.settings 56 | com.android.providers.telephony 57 | com.android.providers.userdictionary 58 | com.mydomain.myapp 59 | ``` 60 | 61 | 62 | List all SQLite databases under a specified package, on a running Android device connected via ADB 63 | ```sh 64 | $ adb-db-pull.sh com.mydomain.myapp 65 | SQLite DBs found under com.mydomain.myapp on device: 66 | names.db 67 | names.db-journal 68 | profile.db 69 | profile.db-journal 70 | ``` 71 | 72 | 73 | Copy a specified SQLite DB file to current local directory, from a running Android device connected via ADB 74 | ```sh 75 | $ adb-db-pull.sh com.mydomain.myapp names.db 76 | Done: snapshot 77 | 7219 KB/s (45056 bytes in 0.006s) 78 | Done: ADB pull 79 | 80 | $ ls -al 81 | total 112 82 | drwxr-xr-x 7 me staff 238 22 Jun 10:00 . 83 | drwxr-xr-x 3 me staff 102 22 Jun 10:00 .. 84 | -rw-r--r-- 1 me staff 45056 22 Jun 10:00 names.db 85 | ``` 86 | 87 | 88 | ##License 89 | 90 | (The MIT License) 91 | 92 | Copyright (c) 2014 Leonard Wu 93 | 94 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 95 | 96 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 97 | 98 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 99 | -------------------------------------------------------------------------------- /adb-db-pull.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2014 Leonard Wu 4 | # MIT License 5 | # Android SQLite DB Pull (adb-db-pull, v1.2) 6 | # https://github.com/leonardw/adb-db-pull.git 7 | 8 | ADB=`which adb` 9 | ADB_SHELL="$ADB shell" 10 | SELF=`basename $0` 11 | DEST_DIR="./" 12 | 13 | if [ $? -ne 0 ] 14 | then 15 | echo "adb runtime not found. Please install Android SDK and add into PATH" 16 | exit 1 17 | fi; 18 | # Show usage info if incorrect num of args 19 | if [ $# -ne 2 ] 20 | then 21 | echo "Usage: $SELF [PACKAGE.NAME [DB_FILE]]" 22 | echo "eg. $SELF com.mydomain.myapp names.db" 23 | fi; 24 | # Quit if more than max num of args 25 | if [ $# -gt 2 ] 26 | then 27 | exit 1 28 | fi; 29 | 30 | # No args, try list all package names 31 | if [ $# -eq 0 ] 32 | then 33 | cmd_list_pkg="$ADB_SHELL 'ls -d /data/data/*/databases | cut -d \"/\" -f 4' " 34 | echo "" 35 | echo "Packages with SQLite DBs found on device:" 36 | eval $cmd_list_pkg 37 | exit 0 38 | fi; 39 | 40 | # One arg, try list all DBs under given package 41 | if [ $# -eq 1 ] 42 | then 43 | cmd_list_db="$ADB_SHELL 'ls /data/data/$1/databases/' " 44 | echo "" 45 | echo "SQLite DBs found under $1 on device:" 46 | eval $cmd_list_db 47 | exit 0 48 | fi; 49 | 50 | # Two args, pull specified DB to local 51 | if [ $# -eq 2 ] 52 | then 53 | cmd_snapshot="$ADB_SHELL 'run-as $1 cat /data/data/$1/databases/$2 > /sdcard/$2' " 54 | # echo $cmd_snapshot 55 | eval $cmd_snapshot 56 | err=$? 57 | if [ $err -eq 0 ] 58 | then 59 | echo "Done: snapshot" 60 | else 61 | echo "Failed: snapshot" 62 | exit err 63 | fi; 64 | cmd_pull="$ADB pull /sdcard/$2 $DEST_DIR" 65 | # echo $cmd_pull 66 | eval $cmd_pull 67 | err=$? 68 | if [ $err -eq 0 ] 69 | then 70 | echo "Done: ADB pull" 71 | else 72 | echo "Failed: ADB pull" 73 | exit err 74 | fi; 75 | fi; 76 | exit 0 77 | -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | # Change Log - adb-db-pull 2 | 3 | ### 1.2, 2014-06-23 4 | * Modified adb shell command for wider compatibility 5 | 6 | ### 1.1, 2014-06-23 7 | * List DBs even if specified package is not debuggable 8 | 9 | ### 1.0, 2014-06-22 10 | First release 11 | --------------------------------------------------------------------------------