Core Data shoebox with iCloud: best practice for backup and restore?

Does anyone know of great sample code or a Git repository that implements a best practice for backup and restore of a shoebox Core Data store with iCloud support? The closest implementation am aware of is from the official documentation, under "Changing a Store’s Type and Location", but that causes the current data store context to become invalid, which is not what I want, because it's a shoebox implementation.

I basically need a function for "back this whole thing up, but keep the original open when I'm done" and another function for "restore all entries from this backup, de-duping". I have an implementation for restoring and de-duping from a legacy storage location, so I can reuse that to restore from a backup location. All I'm really missing is a clean way to make a full backup to backup location. I'm willing to figure out the local Documents and iCloud Documents / other-cloud-storage details, the part I'm struggling with is the Core Data part itself. Another ways is, if it could create a duplicate of the storage, as with a file copy command, that would be ok.


If I can't find an effective solution using Core Data directly, I might resort to raw sqlite or plist for backup, but that's a whole lot of code, which defeats the purpose of leveraging Core Data.