Skip to content

Instantly share code, notes, and snippets.

@jk2K
Forked from medyo/extract_realm_database_android.sh
Last active February 22, 2023 15:04
Show Gist options
  • Save jk2K/a66ed67b252b880824b32dd4952d1b39 to your computer and use it in GitHub Desktop.
Save jk2K/a66ed67b252b880824b32dd4952d1b39 to your computer and use it in GitHub Desktop.
how to export realm database, work on Android 5.0+
#!/bin/bash
ADB_PATH="/Users/lee/Library/Android/sdk/platform-tools"
PACKAGE_NAME="com.yourcompany.app"
DB_NAME="default.realm"
DESTINATION_PATH="/Users/lee/Downloads/${DB_NAME}"
NOT_PRESENT="List of devices attached"
ADB_FOUND=`${ADB_PATH}/adb devices | tail -2 | head -1 | cut -f 1 | sed 's/ *$//g'`
if [[ ${ADB_FOUND} == ${NOT_PRESENT} ]]; then
echo "Make sure a device is connected"
else
${ADB_PATH}/adb exec-out run-as ${PACKAGE_NAME} cat files/${DB_NAME} > ${DESTINATION_PATH}
echo "Database exported to ${DESTINATION_PATH}"
fi
@danielbas
Copy link

This is very helpful, thank you!

@locpv-ibl
Copy link

Nice query but this is only for debuggable package. Best android practices do say that "Your minifest file should have set debug to false". That will probably prevent from this query!

@ronaldondantas
Copy link

Awesome! Thanks.

@wagnerpaz
Copy link

Many thanks! It works like a charm!

@Jeaan2
Copy link

Jeaan2 commented Aug 17, 2020

Thank you, man! It helped a lot!

@tejassonar
Copy link

Thanks a lot!!!

@sirmong
Copy link

sirmong commented Dec 16, 2020

Awesome! Thank you!

@LewisFieldMargin
Copy link

Very useful, thanks!

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