Exporting messages and attachments from iPhone to Mac

Yesterday I accidentally deleted an important sms conversation from my Mac (for which I didn’t have a Time Machine backup). I thought it would be fairly easy to copy all my messages from my iPhone to my Mac, but it wasn’t that easy…

This guides helps you copy all your messages from iOS to OS X. You could invert the process to copy your messages from OS X to iOS.

Copying the databases

Before continuing, quit Messages app on your Mac.

First you need sms.db and Attachments folder from the iPhone. You can use a backup extractor tool to restore the file structure.
You can also manually find the backup folder in ~/Library/Application Support/MobileSync/Backup. The files in that backup folder are named with the SHA-1 hash of the original file in the iOS filesystem. The file for sms.db is called 3d0d7e5fb2ce288813306e4d4636395e047a3d28. Just rename it to sms.db and you have your SMS database. (I extracted the attachments folder with a third-party app)

Now backup ~/Library/Messages on your Mac and replace all its contents with sms.db and Attachments from your iPhone. Rename sms.db to chat.db.

Remove the ~/Library/Containers/com.apple.iChat folder.

Fixing attachments

On iOS, the messages are stored in ~/Library/SMS/ directory. This is not the case on OS X, where they are stored in ~/Library/Message/. This results in your attachments not showing op in Messages on Mac. In order to solve this, we need to execute a Sqlite query to rename SMS to Messages for each attachment:

UPDATE attachment
SET 
  filename = replace(filename, '/Library/SMS/Attachments/', '/Library/Messages/Attachments/')
WHERE
  filename LIKE '%/Library/SMS/Attachments/%';

I used DB Browser for SQLite to browse and edit the SQL database. You can execute the above SQL query by going to the Execute SQL tab.

Fixing version

It is also possible that you need to update the Sqlite version number. Otherwise Messages.app will mark the database file as incompatible. Again, we do this by executing a query:

UPDATE _SqliteDatabaseProperties
SET
    value = '9007'
WHERE key = '_ClientVersion';

I got the 9007 value from the chat.db database.

Restart

Once all of this is done, restart your Mac and verify that your messages have arrived in Messages app.

Join the Conversation

28 Comments

  1. This worked for me perfectly….almost. Older photos- ones from prior to the summer of 2011 show up as a broken link in OSX Messages now. Curiously, I think they’re all the same photos which I can’t tap and zoom in on in iOS Messages. I don’t know if this was a major OS upgrade or when I switched from a iPhone 3GS to a 4S (what I am using now).

  2. Thank you so much for this. I really appreciate you sharing. This worked for me perfectly using iExplorer and macOS Sierra 10.12.4 with an iPhone 7 Plus that was has restore data on it way back to 2011 with an iPhone 4! Thank you again.

  3. Damn! It actually worked flawlessly! I has tried everything as the usual suggestions go; sign out of icloud, sign back in and so on but now I’ve finally to the sync. Yes its a bit tricky for the typical user but it work and I don’t have to pay some money for a crappy app I’ll end up using one time! Thanks for taking the time to write the guide!

  4. Hi Matthias, thanks for your wisdom on this! I have followed your steps under ‘copying the databases’ successfully, but I don’t know much about IT and don’t know how to use SQL or execute queries so could not complete the ‘fixing version’ process. Can you please provide some more detailed steps on how to update the SQlite version number using a query? Thanks in advance! Ben

    1. You need to download the SQL browser (http://sqlitebrowser.org/) and open the original database file with it.

      Look into the original file on your Mac for the _ClientVersion and copy it.

      Then open the new database you just copied, and save the correct _ClientVersion from the original db on your mac into the new on your Mac.

      I hope this already helps you?

      1. Hi Mathias. Sorry I have no idea what you mean. I have never used SQL or this SQL lite browser application before. When you say open the original database, do you mean the sms.db file? What do you mean by ‘look into the original file on my mac’ – do you mean in the SQL application? I do not understand your last steps at all. Sorry if this is frustrating but as a non IT expert I need step by step, including what to click in the SQL application to execute the query. Thanks in advance!

          1. There is no pattern, the dates are all just completely wrong. For example the text message below says it was sent in 2044. Any idea if there is an option using SQL to change dates somehow? This unfortunately makes using messages almost impossible 🙁 I followed your steps exactly except for the client version which I got from the chat.db file as 10013 rather than 9007 for you.

          2. I did. I tried it again then and hasn’t helped unfortunately. Let me know if you have any other ideas – I’d my messages to be in order so I don’t have to scroll through 100s of messages to find the new one!

          3. I’m running macOS Sierra 10.12.6. It’s weird, it’s almost like messages has forgotten to order the messages according to date

          4. I did but unfortunately it didn’t help. I have noticed that messages that are displaying out of order jump back into their correct order if I send or receive a text in that thread. Ie its like the app only works out that the message was in the wrong order when the thread is used again, then it moves it to the correct place. So gradually over time, as I message more people, the messages are going to fall into order. But it’s a bit frustrating that I can’t do anything to reorder them now. Thank you for your help though!!

          5. @KevinMook:disqus I can’t see your comment in this thread for some reason (did you delete it?) It got emailed to me anyway – I followed your steps and messages are now correctly ordered! Thank you so much for your help! And thank you @DenBeke:disqus as well!

          6. @benspoor:disqus No problem, glad it worked for you too!

            It looks like the system automatically marked my comment as spam; I just marked it as “not spam” so hopefully the comment will be reviewed and restored in case it helps anyone else. And thanks again @DenBeke:disqus!

          7. I also had this problem and noticed the date values seemed to be about 1000000000 times larger than the date_read column. I fixed it by running this: UPDATE message SET date = date / 1000000000 where date > 100000000000000000;

            My messages are now ordered oddly, but the timestamps seem to be correct now at least.

            Thank you, @DenBeke:disqus for your blog post. It’s been a life saver!

  5. Now backup ~/Library/Messages on your Mac and replace all its contents with sms.db and Attachments from your iPhone. Rename sms.db to chat.db.

    Confused here. I’ve already renamed “3d0d7e5fb2ce288813306e4d4636395e047a3d28” to sms.db.
    Now, I’m supposed to rename it to chat.db? Why not just rename it to chat.db instead of renaming it twice? or am I mis-understanding something?

  6. In examining “chat.db” and “SMS.db” files in a SQL browser recently, it appears that the timestamp integer for messages was changed from seconds to nanoseconds in iOS 11 and macOS 10.13 (possibly 10.12). I’ve observed that macOS itself converted the old-format timestamps to new ones by simply adding nine zeroes on the end. If that’s what the OS is doing, then I would suggest you might get better results if you modify the UPDATE statements given above to do the same — i.e., rather than looking for the longer new-format timestamps and dividing them by a billion, you might instead look for the shorter old-format timestamps and *multiply* them by a billion.

Leave a comment

Your email address will not be published. Required fields are marked *