Restore OS X iMessages History from chat.db

nodebase picture nodebase · Nov 26, 2014 · Viewed 18.7k times · Source

I saved a copy of everything inside ~/Library/Messages/ which included a folder named Attachments that is filled with a bunch of subdirectories containing all my files ever attached to a message (images, documents, movies, etc), and three (3) files named:

  1. chat.db (about 20 MB file size),
  2. chat.db-shm (33 KB), and
  3. chat.db-wal (565 KB).

I opened the large chat.db file and it contains all my messages in an SQLite database. I know this file contains all the information needed to rebuild my iMessage history, I'm just not sure how to convince the iMessages.app to do so.

I've been at this for about 60 minutes now, trying several different things (I'm not going to list out every one of them).

There's gotta be a way to restore my messages from these files that I saved.

Answer

favoretti picture favoretti · May 18, 2017

After banging my head on it for 3 days - I've found out the following:

All those 3 files keep an index of what you have in Archives. So removing corrupted files and/or just restoring backup of these 3 files should have done it. But it didn't. I've tried restarting Messages app a thousand times after replacing those files, to no avail. Until I've decided to run lsof to see what is actually using chat.db. To my surprise it was not Messages app:

[none-none][18:42:24] vlazarenko@alluminium (~/Library/Messages)$ lsof -n | grep chat.db
IMDPersis 1655 vlazarenko  txt       REG                1,3      32768 107632436 /Users/vlazarenko/Library/Messages/chat.db-shm
IMDPersis 1655 vlazarenko    4u      REG                1,3     309032 107632435 /Users/vlazarenko/Library/Messages/chat.db-wal
IMDPersis 1655 vlazarenko    5u      REG                1,3       4096 107632432 /Users/vlazarenko/Library/Messages/chat.db
IMDPersis 1655 vlazarenko    6u      REG                1,3      32768 107632436 /Users/vlazarenko/Library/Messages/chat.db-shm

As you can see, it's a process called IMDPersissomething.. Looking for that one:

[none-none][18:57:10] vlazarenko@alluminium (~/Library/Messages)$ ps -ef | grep IMDPersis
  501  1655     1   0  6:48PM ??         0:00.11 /System/Library/PrivateFrameworks/IMDPersistence.framework/XPCServices/IMDPersistenceAgent.xpc/Contents/MacOS/IMDPersistenceAgent

An a-ha! moment. Quitting Messages, replacing the files, doing kill on the PID of IMDPersistenceAgent and then starting Messages got me my history back in no time.

Thought I'd share, albeit this is an old thread.