How to backup data stored with Core Data - iPhone app?
I'm using sqlite for the persistent store, so could I just upload the .sqlite file to, for example, Amazon S3 as a way of providing users with the ability to backup their app data? Then for restoring just download it back and replace the existing .sqlite file in the app's folder.
Does anybody see any is开发者_运维知识库sues with that? Has anyone done it? Any other suggestions on how to implement data backup feature?
Yes, uploading the SQLite file is possible; it is just a file and can be backed up as you would for any file.
Generally though, this approach might be a little inflexible: it's an all or nothing approach to handling the data inside the .sqlite file.
If you wanted to provide finer grained backups, you might want to consider a solution for syncing the records in the database on the phone with records stored elsewhere. i.e. read all the objects you want to back up, convert them to JSON/XML/whatever and upload them to a server which then adds them to its own database.
The reason why you would export, send to a server and have the server import into its own database, is that this would allow you to perform more finegrained edits -- i.e. just sync the entries that have changed since last sync. However it is a lot more work since you will need to control the software running on the server and also have code to serialize your CoreData objects to the transfer format.
精彩评论