Skip to content

Instantly share code, notes, and snippets.

@Kirill89
Last active May 2, 2020 10:40
Show Gist options
  • Save Kirill89/852a921169db91f965dcaa2ac71689d9 to your computer and use it in GitHub Desktop.
Save Kirill89/852a921169db91f965dcaa2ac71689d9 to your computer and use it in GitHub Desktop.
This is a script to easily download realm database file from device and open it in realm browser app.
#!/bin/sh
PACKAGE_NAME="com.trax.retailexecution"
DB_NAME="$1"
OUT_DIR="$HOME/RealmDatabases"
# Check args
if [ -z "$DB_NAME" ]
then
echo "usage ./realm.sh database_name"
exit 1
fi
# Create folder for databases if not exists
mkdir -p "${OUT_DIR}"
# List available files on device
echo "\n\nAVAILABLE FILES:\n\n"
adb shell "run-as ${PACKAGE_NAME} ls files/"
echo "\n\n=================\n\n"
# Copy db file to sdcard
adb shell "
run-as ${PACKAGE_NAME} chmod 666 files/${DB_NAME} &&
mkdir -p /sdcard/${PACKAGE_NAME} &&
rm -f /sdcard/${PACKAGE_NAME}/${DB_NAME} &&
cp /data/data/${PACKAGE_NAME}/files/${DB_NAME} /sdcard/${PACKAGE_NAME}/${DB_NAME} &&
run-as ${PACKAGE_NAME} chmod 600 files/${DB_NAME}
"
# Remove local copy of db
rm -f "${OUT_DIR}/${DB_NAME}.realm"
# Get db from device to local
adb pull "/sdcard/${PACKAGE_NAME}/${DB_NAME}" "${OUT_DIR}/${DB_NAME}.realm"
# Check realm browser installed
if [ ! -d "/Applications/Realm Browser.app/Contents/MacOS" ]; then
echo "\n\nPlease install Realm Browser https://itunes.apple.com/il/app/realm-browser/id1007457278"
exit 1
fi
# Run realm browser
/Applications/Realm\ Browser.app/Contents/MacOS/Realm\ Browser "${OUT_DIR}/${DB_NAME}.realm"
@Kirill89
Copy link
Author

Don't forget to add export PATH=~/Library/Android/sdk/platform-tools:$PATH to your profile.

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