1

Current solution and problem with it: I currently zip my user directory when creating a backup of my CoreData-generated SQLite database. However, this backs up the redundant indexes (which make searching faster) as well. (In my case, a lot of redundancy was introduced by moving to CoreData with several search indexes. The amount of data increased from about 3 MB to more than 10 MB.)

What I want: I would like to backup my CoreData-generated SQLite database in a storage-efficient way, i.e., without the redundant search indexes. When restoring the backup, these search indexes should be recreated. The whole process of backing up and restoring should be as simple as possible, i.e., without manually creating a clone of the data structure without search indexes.

What I've tried: I've read the many posts on Stackoverflow about backing up CoreData and also Apple's documentation. For example: migratePersistentStore. In addition, I've read documentation on SQLite, e.g., SQLite Online Backup API. However, I haven't found any option to create a backup without the search indexes and to restore this backup in a way that the search indexes are rebuilt.

My settings/options:

  • OS: iOS 8.2

  • Device: iPhone 6 Plus

  • Store options: @{ NSMigratePersistentStoresAutomaticallyOption : @YES, NSInferMappingModelAutomaticallyOption : @YES, NSSQLitePragmasOption : @{@"journal_mode" : @"DELETE"} };

  • MOC option: NSMainQueueConcurrencyType

John
  • 8,468
  • 5
  • 36
  • 61
  • 1
    Please post the store options you are using to create your persistent store and the OS versions you are deploying to. – quellish Apr 02 '15 at 18:20

1 Answers1

0

While you still may want to rethink your backup strategy overall, one thing you could look at doing is connecting to the .sqlite files that are the core data backing store directly using the Sqlite API and just exporting the data to a backup .sqlite file on the disk. This is very similar to what the sqlite .dump command can be used for.

Something similar has been proposed before: https://stackoverflow.com/a/27453637

The relevant SQLite APIs to look at can be found here: https://www.sqlite.org/c3ref/backup_finish.html

Community
  • 1
  • 1
Joseph Afework
  • 269
  • 1
  • 4
  • Thank you. This seems to be a way to backup a SQLite database with advantages over just using a system's copy command. From my understanding, the same method would be used for creating the backup and for restoring it. However, I could not find an option to create a backup without the search indexes and to restore this backup in a way that the search indexes are rebuilt. – John Apr 08 '15 at 08:32