Backing up Apple Messages
ArticlesMy Apple Messages / iMessage archive is around 40GB across 2445 threads and goes back to 2012. I love having all of my messages instantly available on all of my Apple devices, but the size of the archive is getting out of control. If I do a search in the Messages app on my Mac, the Messages app freezes for many seconds, showing the spinning rainbow “loading” indicator. And so, I decided it was time to archive all of my old messages and “only” keep the last year’s worth. There are options in iOS to keep Messages “forever”, for 30 days, or 1 year.
Exporting messages is easy using the imessage-exporter command line tool.
imessage-exporter -f html -c compatible -o /Volumes/external/export
This command exports messages from the default Messages database on a Mac to html (web pages) including attachments, and it converts formats like HEIC to jpg so browsers can display images inline.
However, the file names of the exports are phone numbers and email addresses, which makes people hard to find. I wanted file names to be the names of my contacts. To do this, I wrote (or more precisely, I guided ChatGPT into writing) a script that takes a Messages export folder and a vCard export (I exported my entire address book of over 2,200 contacts), and renames files to matching contact names.
For example, if the export yields a filename like “+14155551212, foo@bar.html” and you have Contacts in the .vcf file that match, a rename might output something like “Joe Time, Bill Holman.html”
I did an export and rename tonight for 12 years of Messages and set my account to only keep 1 year’s worth of Messages from now on. I also set a recurring reminder to do a backup every 10 months, which gives me 2 months of buffer each year, just in case.
Here’s the code! Enjoy.