[GUIDE] Extract and Restore Contacts, SMS, Call logs from nandroid backups(TWRP)

Search This thread

Mirhawk

Senior Member
Jan 31, 2014
1,453
640
So yesterday My phone, Sony Xperia S, decided to go into bootloop and not boot at all, no matter what I did. Tried flashing stock PRF, stock firmware, some stock based firmware, but it would get stuck in bootloop. The reason for this being I was not formatting the data partition, which I needed to preserve since it had all My sms, contacts, call logs and other app data. Luckily, I had a working recovery(TWRP) and was able to take a backup. Then using that I was able to recover My contacts, sms, call logs and app data. After a lot of Google searches, I was finally able to work it out. The process is as follows:



Needed software:
Code:
yaffs-mmssmsdb-calls-extractor.zip from [URL="http://forum.xda-developers.com/showthread.php?t=1585957"]here[/URL].
Firefox Browser
Firefox addon of SQLite manager : [URL="https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager"]link[/URL].
Excel macro to convert .db contacts to .csv : [URL="http://thydzik.com/downloads/convert-contacts2.db-data-to-vcard-vcf.xlsm"]link[/URL].
Software for csv to vcard conversion (Windows) : [URL="http://www.csvtovcard.com/"]link[/URL].
CSV to vcard conversion (online) : [URL="http://labs.brotherli.ch/vcfconvert/"]link[/URL].
SMS Backup & Restore android app : [URL="https://play.google.com/store/apps/details?id=com.riteshsahu.SMSBackupRestore"]link[/URL].
Call Log Backup and Restore app : [URL="https://play.google.com/store/apps/details?id=com.riteshsahu.CallLogBackupRestore"]link[/URL].

The procedure is a lot crude as of yet, I would update as more universal and convenient options are found.
I know there is Titanium backup app which can restore contact, sms etc from nandroid backups, but You need a paid version of the app.



First we need to extract the data partition of nandroid
  1. Rename the data.ext4.win to data.ext4.tar.gz . If Your files are like data.ext4.win000, data.ext4.win001, then rename each of them to data.ext4.tar.gz in separate folders.
  2. On windows, now You can directly extract them using WinRaR or 7zip application, although You don’t need to extract it entirely.
  3. On linux, You can do so using the following command. It is recommended to store the file in a separate folder as the file gets extracted directly.
    Code:
    tar –xf data.ext4.tar.gz
  4. Now we need to find two files contacts2.db and mmssms.db . The contacts2.db files is for contacts as well as the call logs and the mmssms.db is for messages. The contacts2.db is constant across most ROM’s and OEM firmware apps. The mmssms.db file may vary as per app and ROM’s. So what You need to do is look for a .db file inside the SMS app You have been using with the firmware/ROM.



We will restore the SMS and Call logs first.
Currently it is limited to Windows OS only.

  1. Extract the contents of yaffs-mmssmsdb-calls-extractor.zip to a folder.
  2. Copy the mmssms.db file and contacts2.db file to the above folder.
  3. Now open a command prompt at location of the above folder. This can be done by opening the folder, right clicking using shift key pressed in blank space. You get the “Open command window here” option.
  4. In it type:
    Code:
    extract -s mmssms.db
  5. It will ask You to enter a name for the output .xml file, You can press enter to let it give a default name. This will convert Your sms to a .xml file .
  6. Then type:
    Code:
    extract –c contacts2.db
  7. It will also ask You to enter a name for the output .xml file, You can press enter to let it give a default name. This will convert Your call logs to a .xml file .
  8. Copy both of these files to Your newly formatted phone and then use the two before mentioned apps (Call Log backup& Restore and SMS Backup & Restore) to restore Your SMS and call logs.



Now retrieving contacts. It is a bit lengthy, but simple process.
  1. Start firefox browser. In it, after You have installed the addon do following to enable the addon
    • Go to options (3 horizontal lines).
    • Select “Customize” and drag the “SQLite Manager” to the blue bordered box.
  2. Now open options and select SQLite Manager. In it select Database>Connect Database. In the opened dialog box, select All Files(*.*). Then select Your contacts2.db .
  3. From the left side tree structure in the SQLite Manager window, right click on “data” and select “Export Table”.
  4. Now in right side part of the window, You will get CSV tab and SQL tab. Under CSV tab, simply press OK button without changing any other options.
  5. It will ask You to save Your .csv file. Save it.
  6. Now if You try to open this file directly, You will notice that file is not properly arranged.
  7. To arrange it properly, open the convert-contacts2.db-data-to-vcard-vcf.xlsm file. If You don’t know how to enable Macros, then do the following:
    • It will show You a warning “Security Warning Macros have been disabled. Options..”
    • Press the Options button. Select “Enable this content” and press ok.
    • Now Press the office button present at left top corner. In it select “Excel Options”.
    • Select Customize tab from left side. Then from “Choose commands from:” drop down menu, select Macros.
    • Now add convertDatatoContacts and writeContactstovCard to right pane from left pane by selecting them and pressing add. Press OK button.
  8. Now as You can see two white square icons have been added at top right corner next to save undo redo options.
  9. Select the first white square icon. Select “Enable Macros” button. Now select Your .csv file in the opened dialog box.
  10. Now the file must have opened in a separate excel. The format should be 4 rows with they being First Name, Last Name, Phone 1 and Phone 2.
  11. Then select Save As>Excel Workbook>Save Type as CSV(Comma delimited).csv . Press ok and yes on the two warnings generated.
  12. At the left bottom, right click on “contacts” sheet and press delete. Save and close the file.
  13. Run CSV to vCard software and open the above saved .csv file. Here You can save all contacts as single vCard file or separate files.
  14. In the “Properties” section on the window, in front of “Phone 1” and “Phone 2” select “Mobile Phone” from options. Press “Convert” button.
  15. Alternative to above two steps, You can also convert .csv to vcard using the website.
  16. Now a .vcf file will be created where the .csv file was stored.
  17. Now simply copy the .vcf file to phone and import using the phone contacts app!
  18. Done!



Credits and sources:
@abbot2
[TOOL] yaffs extractor, mmssms.db & contacts2.db converter
http://thydzik.com/export-android-contacts-contacts2-db-to-vcard-vcf-on-windows/
 
Last edited:

john_pangolin

Member
May 21, 2015
6
0
Praise to you for saving me !
And if I may, I'd like to state my experience, which brings a few interesting facts into light:
1/ I was unable to open my tar.gz archives with 7-zip v9.20. It kept displaying an error message. Only the v15.14 version could handle them flawlessly.
2/ as a textra user, I discovered that it stores a duplicate sms database, which IS NOT compatible with yaffs-mmssmsdb-calls-extractor (which screams a message about a "missing sms table" or something) (praise to the author as well)
BUT, the system sms database can be found here, and is fully handled by the extractor tool:
data\data\com.android.providers.telephony\databases\mmssms.db

Now my sms are back and I can resume my thread about the best knitting techniques.
Thanks again
 
Last edited:

2PointOBoy

Senior Member
Apr 29, 2013
60
16
Thanks for this. I wanted to comment to help others using Microsoft Office 2016 & now that Firefox Quantum has made old extensions incompatible. Call logs & SMS are easily imported by Nandroid Manager app (god bless the dev). This a short summary of steps to restore contacts, presuming you have the contacts2.db file extracted:

- Install Firefox 39 from here. Might work with FF 57, but did not want to take chances.
- Download the Excel Macro [which will help us later correctly arrange our data via pre-set changes, aka macros, on the Excel spreadsheet][see link above]
- Install & enable the SQLite extension in Firefox (already linked above by OP)
- Follow OP's steps until you obtain the .csv file
- Open the macro file you had downloaded earlier & click enable the content
- In Excel 2016, you need to add Developer Tab to your top menu: Go to File -> Options -> Customize Ribbon -> Check mark Developer option on the right side column. Click OK.
- Now we need to run the macros: Click on Developer Tab at the top -> Macros -> Run the first macro: convertDatatoContacts
- Select the .csv file & proceed
- Now run the second macro: writeContactstovCard
- Vcard (.vcf) is saved to same folder as your original macro file.

In Nougat, Contacts app can open and import .vcf file or you can use third-party app.
 

Xelasarg

Senior Member
Jul 12, 2007
124
74
Great tutorial, thank you very much! This saved 6000 SMS when Titanium Backup had messed up. ??
 

wuith

Senior Member
Sep 13, 2011
76
19
Thank you very much! With your guide I could recover my SMS from a phone with a bootloop (TWRP bootable) but I did a different process:
1. TWRP Backup
2. Transfer it to PC
3. Rename the data.ext4.win to data.ext4.tar.gz . If Your files are like data.ext4.win000, data.ext4.win001, then rename each of them to data.ext4.tar.gz in separate folders.
4. Open each file in BandiZip program and search for mmssms.db
In my case it was in: data/user_de/0/com.android.providers.telephony/databases/
5. Copy this file to the same folder in spare phone / same phone after factory reset.
6. SMS appear now!
 
Last edited:

mango9

Member
Mar 13, 2019
15
1
Thanks for valuable infomation.I'd like to share my experience that I have use Android recovery program to extract and recover sms,contacts,call logs from backup files.It has powerful method and the operation is easy.
 

juda iskariotsky

Senior Member
Dec 1, 2013
149
39
Bratislava
Samsung Galaxy S22 Plus
my samsung s9+ deleted all my contacts, slowly like 20 a month lol, no idea why, ****ty sammy soft and auto sync deleted em from sammy cloud too...

i had problems even extracting contacts2.db /Failed to extract calls: no such table: calls/
so i found a better way: just convert your contacts2.db right into vcf here: http://gsmrecovery.ru/db2vc/index.php?lang=en
all my contacts are back :)
 
  • Like
Reactions: m3tamo0ph

Top Liked Posts

  • There are no posts matching your filters.
  • 25
    So yesterday My phone, Sony Xperia S, decided to go into bootloop and not boot at all, no matter what I did. Tried flashing stock PRF, stock firmware, some stock based firmware, but it would get stuck in bootloop. The reason for this being I was not formatting the data partition, which I needed to preserve since it had all My sms, contacts, call logs and other app data. Luckily, I had a working recovery(TWRP) and was able to take a backup. Then using that I was able to recover My contacts, sms, call logs and app data. After a lot of Google searches, I was finally able to work it out. The process is as follows:



    Needed software:
    Code:
    yaffs-mmssmsdb-calls-extractor.zip from [URL="http://forum.xda-developers.com/showthread.php?t=1585957"]here[/URL].
    Firefox Browser
    Firefox addon of SQLite manager : [URL="https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager"]link[/URL].
    Excel macro to convert .db contacts to .csv : [URL="http://thydzik.com/downloads/convert-contacts2.db-data-to-vcard-vcf.xlsm"]link[/URL].
    Software for csv to vcard conversion (Windows) : [URL="http://www.csvtovcard.com/"]link[/URL].
    CSV to vcard conversion (online) : [URL="http://labs.brotherli.ch/vcfconvert/"]link[/URL].
    SMS Backup & Restore android app : [URL="https://play.google.com/store/apps/details?id=com.riteshsahu.SMSBackupRestore"]link[/URL].
    Call Log Backup and Restore app : [URL="https://play.google.com/store/apps/details?id=com.riteshsahu.CallLogBackupRestore"]link[/URL].

    The procedure is a lot crude as of yet, I would update as more universal and convenient options are found.
    I know there is Titanium backup app which can restore contact, sms etc from nandroid backups, but You need a paid version of the app.



    First we need to extract the data partition of nandroid
    1. Rename the data.ext4.win to data.ext4.tar.gz . If Your files are like data.ext4.win000, data.ext4.win001, then rename each of them to data.ext4.tar.gz in separate folders.
    2. On windows, now You can directly extract them using WinRaR or 7zip application, although You don’t need to extract it entirely.
    3. On linux, You can do so using the following command. It is recommended to store the file in a separate folder as the file gets extracted directly.
      Code:
      tar –xf data.ext4.tar.gz
    4. Now we need to find two files contacts2.db and mmssms.db . The contacts2.db files is for contacts as well as the call logs and the mmssms.db is for messages. The contacts2.db is constant across most ROM’s and OEM firmware apps. The mmssms.db file may vary as per app and ROM’s. So what You need to do is look for a .db file inside the SMS app You have been using with the firmware/ROM.



    We will restore the SMS and Call logs first.
    Currently it is limited to Windows OS only.

    1. Extract the contents of yaffs-mmssmsdb-calls-extractor.zip to a folder.
    2. Copy the mmssms.db file and contacts2.db file to the above folder.
    3. Now open a command prompt at location of the above folder. This can be done by opening the folder, right clicking using shift key pressed in blank space. You get the “Open command window here” option.
    4. In it type:
      Code:
      extract -s mmssms.db
    5. It will ask You to enter a name for the output .xml file, You can press enter to let it give a default name. This will convert Your sms to a .xml file .
    6. Then type:
      Code:
      extract –c contacts2.db
    7. It will also ask You to enter a name for the output .xml file, You can press enter to let it give a default name. This will convert Your call logs to a .xml file .
    8. Copy both of these files to Your newly formatted phone and then use the two before mentioned apps (Call Log backup& Restore and SMS Backup & Restore) to restore Your SMS and call logs.



    Now retrieving contacts. It is a bit lengthy, but simple process.
    1. Start firefox browser. In it, after You have installed the addon do following to enable the addon
      • Go to options (3 horizontal lines).
      • Select “Customize” and drag the “SQLite Manager” to the blue bordered box.
    2. Now open options and select SQLite Manager. In it select Database>Connect Database. In the opened dialog box, select All Files(*.*). Then select Your contacts2.db .
    3. From the left side tree structure in the SQLite Manager window, right click on “data” and select “Export Table”.
    4. Now in right side part of the window, You will get CSV tab and SQL tab. Under CSV tab, simply press OK button without changing any other options.
    5. It will ask You to save Your .csv file. Save it.
    6. Now if You try to open this file directly, You will notice that file is not properly arranged.
    7. To arrange it properly, open the convert-contacts2.db-data-to-vcard-vcf.xlsm file. If You don’t know how to enable Macros, then do the following:
      • It will show You a warning “Security Warning Macros have been disabled. Options..”
      • Press the Options button. Select “Enable this content” and press ok.
      • Now Press the office button present at left top corner. In it select “Excel Options”.
      • Select Customize tab from left side. Then from “Choose commands from:” drop down menu, select Macros.
      • Now add convertDatatoContacts and writeContactstovCard to right pane from left pane by selecting them and pressing add. Press OK button.
    8. Now as You can see two white square icons have been added at top right corner next to save undo redo options.
    9. Select the first white square icon. Select “Enable Macros” button. Now select Your .csv file in the opened dialog box.
    10. Now the file must have opened in a separate excel. The format should be 4 rows with they being First Name, Last Name, Phone 1 and Phone 2.
    11. Then select Save As>Excel Workbook>Save Type as CSV(Comma delimited).csv . Press ok and yes on the two warnings generated.
    12. At the left bottom, right click on “contacts” sheet and press delete. Save and close the file.
    13. Run CSV to vCard software and open the above saved .csv file. Here You can save all contacts as single vCard file or separate files.
    14. In the “Properties” section on the window, in front of “Phone 1” and “Phone 2” select “Mobile Phone” from options. Press “Convert” button.
    15. Alternative to above two steps, You can also convert .csv to vcard using the website.
    16. Now a .vcf file will be created where the .csv file was stored.
    17. Now simply copy the .vcf file to phone and import using the phone contacts app!
    18. Done!



    Credits and sources:
    @abbot2
    [TOOL] yaffs extractor, mmssms.db & contacts2.db converter
    http://thydzik.com/export-android-contacts-contacts2-db-to-vcard-vcf-on-windows/
    4
    Thank you very much! With your guide I could recover my SMS from a phone with a bootloop (TWRP bootable) but I did a different process:
    1. TWRP Backup
    2. Transfer it to PC
    3. Rename the data.ext4.win to data.ext4.tar.gz . If Your files are like data.ext4.win000, data.ext4.win001, then rename each of them to data.ext4.tar.gz in separate folders.
    4. Open each file in BandiZip program and search for mmssms.db
    In my case it was in: data/user_de/0/com.android.providers.telephony/databases/
    5. Copy this file to the same folder in spare phone / same phone after factory reset.
    6. SMS appear now!
    1
    owzm tutorial

    tks for A DETIALED TUTORIAL:):eek:
    try this forum for retrive contacts ,given a easy method by "StefanPutureanu"

    https://forums.androidcentral.com/ask-question/459773-how-do-i-retrieve-my-contacts-twrp-backup.html
    1
    my samsung s9+ deleted all my contacts, slowly like 20 a month lol, no idea why, ****ty sammy soft and auto sync deleted em from sammy cloud too...

    i had problems even extracting contacts2.db /Failed to extract calls: no such table: calls/
    so i found a better way: just convert your contacts2.db right into vcf here: http://gsmrecovery.ru/db2vc/index.php?lang=en
    all my contacts are back :)