Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable backup of documents folder and all its sub folders on icloud?

I have an already running enterprise application which stores a lot of documents inside the documents folders. I wish to disable the iCloud backup of all these documents and folders inside the Documents folder. The problem is that the contents inside the folder keep on changing dynamically and the idea of adding kCFURLIsExcludedFromBackupKey for every files sounds a bit difficult, as there are multiple classes in my code which can write to the documents directory.

Is there any way I can disable the upload of the entire documents folder and its subfolder.

like image 434
Ankit Srivastava Avatar asked Nov 21 '14 07:11

Ankit Srivastava


People also ask

What does it mean if you turn off iCloud Drive all documents stored in iCloud will be removed from this Mac?

By turning off iCloud Drive on the Mac, you will have no access to iCloud Drive or any files in iCloud Drive from that computer (unless you turn it on again, which we'll also walk through below).

What happens if I delete iCloud Drive documents and data?

You can delete files you no longer want to store in iCloud Drive. Important: When you delete a file from iCloud Drive on iCloud.com, it's also deleted from all your devices that have iCloud Drive turned on.


2 Answers

Perhaps the files are changing dynamically because they are being regularly updated from a server or similar? If so, then the answer is to move your file storage from the <Application_Home>/Documents directory to the <Application_Home>/Library/Caches directory. These documents will not be backed up. This is of course only suitable if the data can be re-downloaded or recreated in the future, if required.

See this Apple documentation for an overview: https://developer.apple.com/icloud/documentation/data-storage/index.html

like image 76
Duncan Babbage Avatar answered Oct 22 '22 05:10

Duncan Babbage


In appDelegate of your application in the following method

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

Add this code

    NSArray *urlArray = [[NSFileManager defaultManager] URLsForDirectory: NSDocumentDirectory inDomains: NSUserDomainMask];
    NSURL *documentsUrl = [urlArray firstObject];

    NSError *error = nil;
    BOOL success = [documentsUrl setResourceValue: [NSNumber numberWithBool: YES]
                                  forKey: NSURLIsExcludedFromBackupKey error: &error];
    if(!success){
        NSLog(@"Error in disabling %@ from backup %@", [documentsUrl lastPathComponent], error);
    }
like image 36
Dinesh Kaushik Avatar answered Oct 22 '22 04:10

Dinesh Kaushik