如何备份用核心数据存储的数据——iPhone应用?

时间:2022-03-03 23:02:13

I'm using sqlite for the persistent store, so could I just upload the .sqlite file to, for example, Amazon S3 as a way of providing users with the ability to backup their app data? Then for restoring just download it back and replace the existing .sqlite file in the app's folder.

我正在使用sqlite进行持久存储,所以我是否可以将.sqlite文件上传到Amazon S3,作为向用户提供备份应用数据能力的一种方式?然后,为了恢复,只需下载回来,并替换应用程序文件夹中现有的.sqlite文件。

Does anybody see any issues with that? Has anyone done it? Any other suggestions on how to implement data backup feature?

有人发现这有什么问题吗?有人做过吗?关于如何实现数据备份功能还有什么建议吗?

1 个解决方案

#1


3  

Yes, uploading the SQLite file is possible; it is just a file and can be backed up as you would for any file.

是的,上传SQLite文件是可能的;它只是一个文件,可以像任何文件一样备份。

Generally though, this approach might be a little inflexible: it's an all or nothing approach to handling the data inside the .sqlite file.

不过,通常这种方法可能有点不灵活:它是处理.sqlite文件中的数据的一种全有或全无的方法。

If you wanted to provide finer grained backups, you might want to consider a solution for syncing the records in the database on the phone with records stored elsewhere. i.e. read all the objects you want to back up, convert them to JSON/XML/whatever and upload them to a server which then adds them to its own database.

如果您想要提供更细粒度的备份,您可能需要考虑一种解决方案,将数据库中的记录与存储在其他地方的记录同步。例如,读取所有要备份的对象,将它们转换为JSON/XML/随便什么,然后将它们上传到服务器,然后将它们添加到自己的数据库中。

The reason why you would export, send to a server and have the server import into its own database, is that this would allow you to perform more finegrained edits -- i.e. just sync the entries that have changed since last sync. However it is a lot more work since you will need to control the software running on the server and also have code to serialize your CoreData objects to the transfer format.

您将导出、发送到服务器并将服务器导入到自己的数据库的原因是,这将允许您执行更细粒度的编辑——也就是说,只需同步自上次同步以来更改的条目。但是,由于您需要控制在服务器上运行的软件,并且还需要代码将CoreData对象序列化为传输格式,因此需要做很多工作。

#1


3  

Yes, uploading the SQLite file is possible; it is just a file and can be backed up as you would for any file.

是的,上传SQLite文件是可能的;它只是一个文件,可以像任何文件一样备份。

Generally though, this approach might be a little inflexible: it's an all or nothing approach to handling the data inside the .sqlite file.

不过,通常这种方法可能有点不灵活:它是处理.sqlite文件中的数据的一种全有或全无的方法。

If you wanted to provide finer grained backups, you might want to consider a solution for syncing the records in the database on the phone with records stored elsewhere. i.e. read all the objects you want to back up, convert them to JSON/XML/whatever and upload them to a server which then adds them to its own database.

如果您想要提供更细粒度的备份,您可能需要考虑一种解决方案,将数据库中的记录与存储在其他地方的记录同步。例如,读取所有要备份的对象,将它们转换为JSON/XML/随便什么,然后将它们上传到服务器,然后将它们添加到自己的数据库中。

The reason why you would export, send to a server and have the server import into its own database, is that this would allow you to perform more finegrained edits -- i.e. just sync the entries that have changed since last sync. However it is a lot more work since you will need to control the software running on the server and also have code to serialize your CoreData objects to the transfer format.

您将导出、发送到服务器并将服务器导入到自己的数据库的原因是,这将允许您执行更细粒度的编辑——也就是说,只需同步自上次同步以来更改的条目。但是,由于您需要控制在服务器上运行的软件,并且还需要代码将CoreData对象序列化为传输格式,因此需要做很多工作。