Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

melchior

macrumors 65816
Nov 17, 2002
1,241
120
I have been looking for clues. My iOS data is about 50MB with several GB of attachments. It dates back to 2008.

If I ignore the attachments, I can see my text messages. But if I change attachment locations, it borks. What does that mean? Does it bork because there are so many? Does it bork because some do not resolve? I have 40 or so that point to /var/tmp and more that point to ~/Library/parts/

Not all of my attachments follow the same folder structure, so I have to change some like /var/mobile/Library/SMS/Attachments/ to ~/Library/Messages/Attachments. I have ignored those pointing to /var/tmp/ and ~/Library/Parts/

It looks normal and I use SQL execute like this and it all looks good. It this in two steps:

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

then

Code:
UPDATE attachment
SET filename = replace(filename, '/var/mobile/', '~/')
WHERE
  filename LIKE '%/var/mobile/%';

I was looking at differences between my iOS schema and the macOS schema.

There are 29 indices instead of 28. This is the extra one is:

Code:
message_attachment_join_idx_message_id
CREATE INDEX message_attachment_join_idx_message_id ON message_attachment_join(message_id)

there are 11 triggers instead of 10. The extra one is:

Code:
delete_associated_messages_after_delete_on_message
CREATE TRIGGER delete_associated_messages_after_delete_on_message AFTER DELETE ON message BEGIN DELETE FROM message WHERE (OLD.associated_message_guid IS NULL AND associated_message_guid IS NOT NULL AND guid = OLD.associated_message_guid); END

There are also small differences like leading spaces after some brackets in the schema that don't appear in my 9006 version.

There are 10 tables, of identical names in both.

Please help.
 
Last edited:

DenBeke

macrumors regular
Aug 11, 2011
192
8
Antwerp
Creating an extra index shouldn't alter the data in your database.
Your first query seems, wrong, because you don't replace the SMS with Messages.

But I don't really have an idea what might be causing the disappearing messages...
 

melchior

macrumors 65816
Nov 17, 2002
1,241
120
Thanks for the reply.

to clarify, I copied your SQL query, but attachments linked to /var/mobile/Library/SMS/Attachments/ would not be found at /var/mobile/Library/Messages/Attachments/ on my Mac. So I run a second query, to fix up those ones, only change the /var/mobile/ to ~/

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

melchior

macrumors 65816
Nov 17, 2002
1,241
120
For anyone playing along at home, I got this to work by making the import into a 10.11.6 El Capitan install. It took a few tries and it wasn't very clean in the El Capitan, but once I brought it into Sierra it is smooth as butter.

I changed the version from 9006 to 9005 to match the chat.db that I had in El Capitan. Then when I copied it across to Sierra it updated it to 10013.

In the end, I only changed SMS to Messages and I ignored all the /var/mobile/ as they didn't point to existing files anymore.
 

Converseallstar95

macrumors member
Original poster
Sep 24, 2008
31
13
@melchior It seems like you've got it all figured out? I've never experienced any attachments in /var and I've been using OS X since Mavericks. I have over 12GB of attachments and a 300MB .db so I don't think size matters much (as long as your computer specs can handle it).

@DenBeke Regarding the stickers, I didn't copy the stickers folder, I copied the stickers as files. More testing needs to be done, I don't know if anyone is interested but a complete transfer is a complete transfer in my head.
 

rbelusko

macrumors newbie
Apr 14, 2017
8
2
Hi,

First timer here....
Thanks to all the previous posts as I was able to follow the steps and get this to work. However I am having an issue with some of the older messages. It appear that these did not port over properly.


  • Messages from 2013 forward appear to be okay.
  • Messages from 2011-2012 show as seen in the picture below (broken).
  • Messages from 2010-2011 are completely missing, but these messages are on my iPhone (where the backup was extracted from).

Luckily I backed out so I can start all over again from the beginning if needed.

Here is a picture of how the older messages look.
611332-c1f7713a615312ebe28b19ebf5a377e8.jpg

I'm sure this is some kind of a formatting thing that requires additional SQL commands to execute, I just have no idea as to what those are. Any ideas?

Thanks
Bob
 

Attachments

  • IMG_0896.JPG
    IMG_0896.JPG
    341.1 KB · Views: 489
Last edited:
  • Like
Reactions: Mcmeowmers

Mcmeowmers

macrumors 6502
Jun 1, 2015
427
268
Note: this is more those that have iMessage histories from different iOS versions/devices and would like to merge them together or import them to Messages on macOS. You might be able to modify some of the steps to restore Messages to Messages. Note the absent "i".... these steps are for iMessage to Message.

Here is a much easier way using iExplorer and iBackupBot 5.4.4.

Information:
iExplorer can read iOS 10.x back ups but it's not able to modify the files, iBackupBot cannot read encrypted iOS 10.x but it can read and modify unencrypted, so there is a gap in out abilities...

Make a new unencrypted iOS 10.x back up with iTunes and continue reading...

Steps:
iBackupBot won't work on encrypted iOS 10.x back ups. Simply make a new backup with iTunes that is not encrypted.

To merge/import/export iMessage/SMS databases:
Open iBackupBot (iBB) and select your unencrypted iOS 10 back up. Click Messages on the main window under "User Information." Click Messages tab, Import. Then pick the appropriate backup to import, it will decrypt the non-iOS 10 backups. You may review threads and specific messages (also includes attachments.) Click OK, might give you an error or three, just keep clicking ok. It will say "X messages merged and y attachments", ok.

Repeat for other backups merging them into your newest.

Now press Export. A registration window pops up which you can conveniently close by pressing Escape or Cancel. The save dialogue appears. Save as sms.db. You can verify and edit the version using DB Browser for SQLite

I suggest importing older db to newer so that the version stays correct.

After merging and importing you should be able to press Restore from the Messages tab in iBackupBot to update your attachments folders on iOS


Open iExplorer and...
Navigate to MediaDomain/Library/SMS/ for attachments, pictures and stickers.
Navigate to HomeDomain/Library/SMS/ for sms.db - make sure this is the database you've merged others into.


After you have the new sms.db and attachment folders follow directions above to get Messages on macOS to open it


Hope it works!
 

rbelusko

macrumors newbie
Apr 14, 2017
8
2
I'll give this a try.
Can iExplorer only read backups from a connected mobile device? (And not from an existing iTunes backup?)
 

Mcmeowmers

macrumors 6502
Jun 1, 2015
427
268
I'll give this a try.
Can iExplorer only read backups from a connected mobile device? (And not from an existing iTunes backup?)
iExplorer can read any iTunes backups and read the current filesystem on an attached iOS device.

It does not have to be jailbroken either. However, jailbroken devices can have their root folder read. Which is not important for iMessage backup.

I will mention that once you turn off encryption and make a backup you should turn encryption back on. Otherwise you risk losing back ups of health activity logs and some other metadata - iTunes will warn you when you turn off encryption but you can turn it back on after and your data will be preserved.
 

rbelusko

macrumors newbie
Apr 14, 2017
8
2
I'll give it another shot, I couldn't figure out how to import an existing backup. Thanks.

And yes... about the encryption being off/on. Actually I brought this up in an Apple forum once and was disappointed to learn that there is no "carbon copy" backup solution for the iPhone... you can only do it through iTunes/iCloud.

And I got your private message - thanks :)
 
  • Like
Reactions: Mcmeowmers

DBird846

macrumors newbie
Aug 19, 2016
1
1
So I did I fresh install of El Capitan and wanted all my messages (SMS/iMessage) from my iPhone, as I lost the message on my computer, so I made a backup through iTunes, then used iExplorer to extract the "sms.db" and the "Attachments" folder from the iPhone backup. I then deleted the "com.apple.iChat" container in my user library, and copied the "sms.db" (renaming it "chat.db") and the "Attachments" folder to the "Messages" folder in my user library. After I opened the Messages app, all the conversations were there (SMS/iMessage), but the attachments in each conversation showed, for example, "IMG_4271" with a question mark. How can I associate all the attachments with the correct conversations (I don't mind doing it manually with a .db file editor or something)? Thanks!

Thank you so much for this thread I am wanting to do exactly this. But iExplorer is $40? Wow. Is there a less expensive application out to do this?
[doublepost=1494191670][/doublepost]
So I did I fresh install of El Capitan and wanted all my messages (SMS/iMessage) from my iPhone, as I lost the message on my computer, so I made a backup through iTunes, then used iExplorer to extract the "sms.db" and the "Attachments" folder from the iPhone backup. I then deleted the "com.apple.iChat" container in my user library, and copied the "sms.db" (renaming it "chat.db") and the "Attachments" folder to the "Messages" folder in my user library. After I opened the Messages app, all the conversations were there (SMS/iMessage), but the attachments in each conversation showed, for example, "IMG_4271" with a question mark. How can I associate all the attachments with the correct conversations (I don't mind doing it manually with a .db file editor or something)? Thanks!

Nevermind my previous comment I got have iExplorer now. I cannot find the sms.db file in my backup. Thanks for your help.

EDIT: Fount it!

Within iOS 10's file structure:

sms.db file is located: Home Domain > Library > SMS

Attachments is located: Media Domain > Library > SMS

Thank you so much. My iMac is running macOS 10.12.4 Sierra. My current iPhone is a 7 Plus which has restore data on it back from my first iPhone 4 in 2011. Following this instruction set and the help of DeneBeke's tip to use DB Browser of SQLite, this solution worked perfectly for me. This is something I have been wanting since SMS Forwarding was first introduced (in Yosemite?). Thank you both again!
 
Last edited:
  • Like
Reactions: Mcmeowmers
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.