Last active
August 29, 2015 14:14
-
-
Save pflammertsma/57c45e7ed6c586d02469 to your computer and use it in GitHub Desktop.
Database dump script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ##### | |
| # Note about extracting databases using cat: | |
| # On some devices (e.g. Moto X 2014) the database file contains some misplaced 0x0D characters. At first look these | |
| # occur preceding a "CREATE TABLE" instruction. | |
| ##### | |
| function notice { | |
| echo -e "\033[1m$1\033[0m" | |
| } | |
| function success { | |
| echo -e "\e[1;32m$1\e[0m" | |
| } | |
| function error { | |
| echo -e "\e[1;31m$1\e[0m" | |
| } | |
| notice "dbdump v1.0.2" | |
| echo "" | |
| all_filenames=( | |
| "ally.db" | |
| ) | |
| all_app_names=( | |
| "ally" | |
| ) | |
| all_pkgs=( | |
| "com.vebego.ally" | |
| ) | |
| function dump_db { | |
| echo "" | |
| pkg=${all_pkgs[$1]} | |
| filename=${all_filenames[$1]} | |
| notice "$app-$filename..." | |
| adb shell run-as $pkg chmod 777 /data/data/$pkg/databases/$filename 1>/dev/null | |
| adb shell run-as $pkg ls /data/data/$pkg/databases/$filename | grep "No such file" 2>/dev/null | |
| if [ $? != 0 ]; then | |
| adb pull /data/data/$pkg/databases/$filename dbdumps/$app-$filename 2>/dev/null | |
| if [ $? == 0 ]; then | |
| success "Success!" | |
| else | |
| adb shell run-as $pkg cat /data/data/$pkg/databases/$filename > dbdumps/$app-$filename | |
| #adb pull /sdcard/.allytemp.sqlite dbdumps/$app-$filename 2>/dev/null | |
| #adb shell run-as $pkg rm /sdcard/.allytemp.sqlite | |
| if [ $? == 0 ]; then | |
| success "Success!" | |
| notice "(Used alternative output mode; may have resulted in bad file" | |
| else | |
| error "Failed; found database, but could not pull it" | |
| fi | |
| fi | |
| else | |
| error "Failed; not installed?" | |
| echo "Listing of /data/data/$pkg/databases/:" | |
| adb shell run-as $pkg chmod 777 /data/data/$pkg/databases/ | |
| adb shell run-as $pkg ls /data/data/$pkg/databases/ | |
| fi | |
| } | |
| # Stop on any errors | |
| #set -e | |
| sel_apps=() | |
| while test $# -gt 0; do | |
| case "$1" in | |
| --help|-h|-\?) | |
| echo "Usage:" | |
| echo "dbdump.sh [--app <appname>] [--app ...]" | |
| echo "" | |
| exit | |
| ;; | |
| --app|-a) | |
| shift | |
| sel_apps+=("$1") | |
| ;; | |
| esac | |
| shift | |
| done | |
| mkdir dbdumps | |
| echo "Dumping DB:" | |
| for i in "${!all_app_names[@]}"; do | |
| app=${all_app_names[$i]} | |
| if [ ${#sel_apps[@]} -ne 0 ]; then | |
| for sel in ${sel_apps[@]}; do | |
| if [ "$app" == "$sel" ]; then | |
| dump_db $i | |
| fi | |
| done | |
| else | |
| dump_db $i | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment