stevex
stevex

Reputation: 5817

How can I prevent a Core Data database with external files from being backed up?

We have an app that uses Core Data to store data. Some of the data comes from a server, and is variable sized, and while it's generally small, can also be quite large (a few megabytes). We're using a Binary Data field with "Allows External Storage" enabled to store this data.

Our app was rejected for a Rule 2.23 violation, because we're storing data that we could re-download from the server and not marking it as to be excluded from backups.

Okay, fair enough, so I want to mark our database to be excluded from backup. Marking the database itself is easy enough:

    BOOL succ = [storeURL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
    if (!succ) {
        NSLog(@"Error setting %@ to be excluded from backups: %@", storeURL, error);
    }

But this only covers the SQLite file itself. When Core Data stores external files, it stores them in a separate directory:

.../Private Documents/MyDatabase.sqlite
.../Private Documents/.MyDatabase_SUPPORT/_EXTERNAL_DATA/(files here)

I need to flag the externally-stored files as not-for-backup. I could set NSURLIsExcludedFromBackupKey on the .MyDatabase_SUPPORT folder, but I don't see any supported way to get the name of this folder.

I could just build it myself, but I don't like depending on this implementation detail. Is there any supported way to find out where Core Data is storing the external files for a database?

Upvotes: 4

Views: 706

Answers (1)

stevex
stevex

Reputation: 5817

Create a subdirectory, create the database within that subdirectory, and then set the NSURLIsExcludedFromBackupKey attribute on the subdirectory. That way anything within the subdirectory, including the hidden SUPPORT directory, will be excluded from backup.

Upvotes: 4

Related Questions