Backing Up and Retrieving Kernel Data SQlite3 Database

I want to back up and get sqlite3 database in master data. This ensures fast saving and recovery of user data saved in the application. The plan is to email the database, then open it up on the receiving device and all of the previous data will be magical and everything will be fine.

I've read a lot of posts and documentation on the subject, but put it all together where I could do with some advice.

What I have done so far:

I was able to email the database sqlite3

using the following

NSString *filePath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"db.sqlite"];
NSError *error = nil;

    NSData *fileData = [[NSData alloc] initWithContentsOfFile:filePath options:0UL error:&error];
    if (error != nil) {
        DebugLog(@"Failed to read the file: %@", [error localizedDescription]);
    } else {
        if (fileData == nil) {
            DebugLog(@"File data is nil");

    MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc] init];
    if (mailView != nil) {
        mailView.mailComposeDelegate = self;
        [mailView setSubject:@"back up database"];
        [mailView addAttachmentData:fileData

        [mailView setMessageBody:@"Database attached"

        [self presentViewController:mailView animated:YES completion: NULL];



Further research leads me to believe that I should attach other log files to this? iOS: How do I back up my main database? And how to export / import this copy?

I have registered these documents as db.sqlite db.sqlite-shm db.sqlite-wal

My question is: 1. Do I send all of these db.sqlite db.sqlite-shm db.sqlite-wal

as attachments in an email? 2. What is the procedure for obtaining these files and copying them into the application.
Simply opening an app does not work as it can only be read by certain apps. Then I made a document type in my info.plist and my app showed up in the action bar as an app to get the document, but the app crashed with an errorincomprehensible archive

So how can I save and restore master data


source to share

1 answer

Archive all 3 sqlite files into one zip file and name it Backup.myappbackup or something similar (it is useful to add the backup date to the filename). You can then register an extension to be recognized by your application, which will allow to recognize this extension and open that backup in your application. You will then unpack the main data files, replace them in their places, and reconfigure the main data stack. You can also allow users to host backups via iTunes Sharing and restore them from the Documents folder.



All Articles