Reputation: 5936
I have searched everywhere on SO Google etc and I can't seem to find a solution or tutorial that fits for manually backing up, and restoring my Core Data Sqlite files. The aim is for the user to manually restore the Core Data SQlite files from the documents directory.
This seems promising but is just to complex for my needs or to extrapulate the relevant sections to my issue. I just want to replicate want iCloud does by backing up the documents directory without the user having to restore the device to a back up every time they may need their data back. I was hoping cloudkit in iOS 8 would make this simpler but nothing has clicked so far.
To summarise: How do I get the contents of the documents directory up to iCloud, then retrieve it again. Im not after syncing, just remote storage and retrieval of the documents directory. Ive read some people have had success with Dropbox for this, open to that to
UPDATE
NSString *filePath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"app.sqlite"];
NSString *filePath2 = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"app.sqlite-shm"];
NSString *filePath3 = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"iCertifi.sqlite-wal"];
//Path to documents directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *archivePath = [documentsDirectory stringByAppendingString:@"/files.zip"];
//Zip up documents directory
ZipArchive *archiver = [[ZipArchive alloc] init];
[archiver CreateZipFile2:archivePath];
[archiver addFileToZip:filePath newname:@"backUp.sqlite"];
[archiver addFileToZip:filePath2 newname:@"backUp.sqlite-shm"];
[archiver addFileToZip:filePath3 newname:@"backUp.sqlite-wal"];
Upvotes: 1
Views: 1276
Reputation: 2522
I've done iCloud documents, CloudKit and Dropbox.
Dropbox is the easiest to start with.
I zip up my database:
ZipArchive *archiver = [[ZipArchive alloc] init];
[archiver CreateZipFile2:archivePath];
[archiver addFileToZip:withPath newname:filename]; //@"x.sqlite"
[archiver addFileToZip:withPath newname:filename]; //@"x.sqlite-shm"
[archiver addFileToZip:withPath newname:filename]; //@"x.sqlite-wal"
Then send it up to dropbox
NSString *dropBoxPath = [NSString stringWithFormat:@"/%@/%@",kBackupFolder,fileToUpload];
DBPath *path = [[DBPath alloc] initWithString:dropBoxPath];
NSString *sourcePath = xxxxx;
if (!info) {
DBFile *backupFile = [[DBFilesystem sharedFilesystem] createFile:path error:&createFileError];
DBError *writeFileError;
[showFile writeContentsOfFile:sourcePath shouldSteal:NO error:&writeFileError];
You can wait for it to upload:
while (showFile.status.state == DBFileStateUploading || showFile.status.error) {
[NSThread sleepForTimeInterval:1.0f];
fileprogress = showFile.status.progress;
Links:
https://github.com/mattconnolly/ZipArchive
https://www.dropbox.com/developers/sync
Upvotes: 2