Home > Development > Android: How to Backup Contacts and SMS Messages

Android: How to Backup Contacts and SMS Messages

In this post I’m presenting a “quick and dirty” way to backup your contacts and SMS messages. “Quick and dirty” not because I’ll show you some illegal or impractical method for doing backups, but because this method doesn’t involve taping any application that you can get from the Android Market to get the job done. Here I will present how to backup your contacts and SMS (and MMS) messages by using standard tools which come with the Android SDK.

If you ever played with the Android SDK you probably know that the contacts and the SMS messages are available to the other applications via Content Providers. The messages are available via the Telephony and contacts via the Contacts provider. The data is stored in SQLite databases in the following locations:

/data/data/com.android.providers.telephony/databases/mmssms.db
/data/data/com.android.providers.contacts/databases/contacts2.db

If you have the Android SDK installed and the phone connected to you computer, to do the backup, you simply need to copy these files from the phone to the computer. You can do this with the “adb pull” command. Here are the commands:

cd <android-sdk-dir>/platform-tools
./adb pull /data/data/com.android.providers.telephony/databases/mmssms.db
./adb pull /data/data/com.android.providers.contacts/databases/contacts2.db

After executing this commands you’ll have the databases in your “<android-sdk-dir>/platform-tools” folder. If you want to examine the databases you can use some SQLite browser. I’m using the SQLite Manager addon for Firefox.

If you want to put the backed up files back on the phone, you’ll have to remount the /system partition in read-write mode, delete the present database files (if there are [present) and push the files back on the phone.

First check to see where the which physical partition is mounted on “/system” to know where you should remount it:

./adb shell mount

Search for the “/dev/block/” part on the line with “/system”. On my phone which is running CyanogenMod 6 it is “/dev/block/mtdblock3”.

After discovering which physical partition is mounted at “/system” you will have to remount that partition as read-write, delete the databases and push the backed up ones.

./adb shell mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
./adb shell rm /data/data/com.android.providers.telephony/databases/mmssms.db
./adb shell rm /data/data/com.android.providers.contacts/databases/contacts2.db
./adb push mmssms.db /data/data/com.android.providers.telephony/databases/
./adb push ~/Desktop/phone/contacts2.db /data/data/com.android.providers.contacts/databases/

After doing the restoration of the databases if it happens that you don’t see either your SMS messages or your contacts you can try copying the databases to your SD card and then by using some file manager with root privileges to place them on the appropriate places. I had this problem with my contacts database and I solved it this way.

  1. No comments yet.
  1. 31/10/2015 at 15:41

Leave a comment