How to Backup Contacts and SMS Messages using command line in Android

The messages are available via the Telephony and contacts via the Contacts provider. The data is stored in SQLite databases in the following locations:

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/
./adb pull /data/data/
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/
./adb shell rm /data/data/
./adb push mmssms.db /data/data/
./adb push ~/Desktop/phone/contacts2.db /data/data/
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.

For more details please refer