-> How to: backup and restore SMS/MMS database from one Android smartphone to another Android smartphone or Android ROM/version

You don't want to do that unless you know CLI. You need to have Linux and adb installed. Your phone must be either rooted or rebooted into TWRP (recovery).

1) extract the old mmssms.db to mmssms-old.db:

Android up to version 6.0: $ adb pull /data/ $ adb pull /data/ Android 7.0 and higher: $ adb pull /data/user_de/0/ $ adb pull /data/user_de/0/

2) dump it via $ sqlite3 mmssms-old.db .dump > mmssms-old.sql

3) dump it as INSERT statements, remove everything except sms, threads, canonical_addresses and save as mmssms-old-inserts.sql

#! /bin/bash SQLITE=sqlite3 if [ -z "$1" ] ; then echo usage: $0 sqlite3.db exit fi DB="$1" TABLES=`"$SQLITE" "$DB" .tables` echo "-- $TABLES" echo 'BEGIN TRANSACTION;' for TABLE in $TABLES ; do echo echo "-- $TABLE:"; COLS=`"$SQLITE" "$DB" "pragma table_info($TABLE)" | cut -d'|' -f2 ` COLS_CS=`echo $COLS | sed 's/ /,/g'` echo -e ".mode insert\nselect $COLS_CS from $TABLE;\n" | "$SQLITE" "$DB" | sed "s/^INSERT INTO table/INSERT INTO $TABLE ($COLS_CS)/" done echo 'COMMIT;';

4) extract a new default mmssms.db to mmssms-default.db (as in 1 above)

5) dump it via $ sqlite3 mmssms-default.db .dump > mmssms-default.sql, remove all INSERT statements if there are any

6) replace CREATE TABLE definitions for the `threads` and `sms`es tables in mmssms-default.sql from mmssms-old.sql

7) cat mmssms-default.sql mmssms-old-inserts.sql | sqlite3 > mmssms-new.db

8) Use and edit mmssms-new.db so that the definitions of the SMS and THREADS tables matched the new format from 5

9) $ file mmssms-default.db -> remember the user format version

10) Run:

$ sqlite3 mmssms-new.db pragma user_version=XXX; .q

11) Upload mmssms-new.db to your new phone. Run adb shell, then

cd /data/ cat mmssms-new.db > mmssms.db rm mmssms-new.db mmssms.db-journal reboot

© 2017 Artem S. Tashkinov. This material cannot be reproduced on any other website, you are only allowed to link to this webpage.

If you want to thank the author or if you want this how-to to be finally brought up to date, please, consider the ad at the top of the page. Thank you!

blog comments powered by Disqus free counters