我需要备份我的数据库。最初在我的“创建备份”页面中,我显示了我的原始数据库。当我单击添加新备份按钮时,必须在检查是否已进行任何新更改的条件下创建我的数据库的新备份。如果进行了任何更改,则必须创建新的备份。否则,只会显示一条警报消息,表明上次备份文件没有更改。任何人都可以帮忙吗
问问题
64 次
1 回答
1
使用此方法。创建数据库的新副本并使用不同的名称保存。
- (void)copyDatabaseToCache
{
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *documentFolderPath = [searchPaths objectAtIndex: 0];
NSString *dbPath1 = [documentFolderPath stringByAppendingPathComponent:@"newDatabaseName.sqlite"];
NSString *backupDbPath = @"You should give back up db path here";
NSError *error = nil;
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:backupDbPath error:&error];
NSLog(@"Persistent store size: %@ bytes", [fileAttributes objectForKey:NSFileSize]);
if ( ![[NSFileManager defaultManager] fileExistsAtPath:dbPath1]) {
[[NSFileManager defaultManager] copyItemAtPath:backupDbPath toPath:dbPath1 error:nil];
}
}
于 2013-06-11T11:38:34.227 回答