Recovering Corrupted iWork Documents from iCloud

With Mountain Lion on my Macs—now including the machine I use at work—I’ve started to make more use of iCloud document syncing so that I can access my documents at home, work, on my laptop and on my iPad (and occasionally iPhone). But I’ve now been stung twice by corrupted iWork documents.

The first time was a couple of months back with a Numbers document I use to track some personal finances. I don’t know what the corruption was, or what caused it, but it prevented me opening the corrupted file, or copying or moving it, to try and open it elsewhere. Luckily however, I was able to restore to a recent backup from Time Machine[1].

But today I was struck with the issue again with a Keynote presentation that I had created at work. On this occasion there was no Time Machine backup, as I don’t have Time Machine set up on my work computer[2], and I hadn’t had my home Mac on since creating the file for a Time Machine backup to be created there.

So, after some consideration I experimented with a solution that worked for me on this occasion (your mileage may vary).

As I couldn’t copy, move or export the file from Keynote’s iCloud window, the iWork for iCloud beta, or from the ~/Library/Mobile Documents/com~apple~Keynote/Documents/ folder (where iCloud stores Keynote documents locally), I thought (correctly) that I may be able to copy it from the Terminal.

After firing up the Terminal app and navigating to the ~/Library/Mobile Documents/com~apple~Keynote/Documents/ folder I used the cp command to copy the file contents to a new folder on my desktop (using the -r flag on the cp command, as the Keynote file is really a disguised folder/directory)[3].

With the Keynote file contents now in a folder on my desktop, I used the Finder to rename the folder with a .key extension, turning the folder into a Keynote file, which opened without issue. I was then able to copy that working Keynote file back into iCloud, where it seems to have been working fine since.

I’m disappointed, and a little unsettled, by these corruption issues, but relieved I’ve been able to recover files on both instances. When it works, iCloud is fantastic, and the best way to work across Macs and iOS devices on documents. But I’ll be carrful about using it for anything too critical given the issues I’ve experienced, and maybe stick with DropBox for them instead.

Update: A newer post on fixing this problem can be found here.


  1. If I recall correctly, I had to do this in the Finder, after accessing the ~/Library/Mobile Documents/ folder (where iCloud stores its documents locally), and even then I don’t think I was able to move/copy the file back into iCloud, but had to create a new file, copying the contents from the recovered file saved locally.  ↩

  2. The work machine does used server-based network accounts, that in theory would be backed up, but I was after a quicker solution than contacting IT in the hope they could recover the file from a tape somewhere.  ↩

  3. i.e. cp -r <keynotefilename> ~/Desktop/<foldername>/  ↩