sqlite的DB的Andr​​oid备份/恢复 [英] Sqlite DB Android Backup/Restore

查看:124
本文介绍了sqlite的DB的Andr​​oid备份/恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道的最佳做法是什么,备份和恢复的android一个SQLite数据库。目前,我通过采取备份的数据库,并使用文件输入/输出流,将它复制到SD卡处理这一问题。然后,我用的是相反的过程,如果我要恢复老备份。

I wanted to know what the best practices are for backing up and restoring a SQLite DB on android. Currently I approach the issue by taking the DB to be backed up and using File Input/Output Streams to copy it to the sd card. Then I use the reverse process if I want to restore and old backup.

这个方法似乎工作,还没有损坏我的数据。我想知道,如果这是最好的办法,或是否有这样做的更安全的方式?

This method seems to work and has not yet corrupted my data. I am wondering if this is the best approach or if there is a safer way of doing this?

感谢

推荐答案

这似乎将是最好的办法。您可能需要考虑采取的SQLite文件的校验和复制,并将其与额外的保障目标文件进行比较了。只要确保没有打开的连接,当你复制数据库,否则你可能会结束与DB意外状态它恢复时。

This seems like it would be the best approach. You may want to consider taking a checksum of the SQLite file before copying and comparing it with the destination file for extra assurance. Just ensure there are no open connections to the database when you take the copy, otherwise you may end up with the DB in an unexpected state when it's restored.

我可以看到这样做的唯一的另一种方法,是将读取数据块的实际内容,并生成含有它可以从恢复SQL文件,这显然是一个更为复杂和不提供任何优势证明了这种复杂性。

The only other way I could see to do it, would be to read the actual contents of the DB and generate a file containing the SQL which which it can be restored from, this is obviously a more complex and doesn't offer any advantages to justify this complexity.

这篇关于sqlite的DB的Andr​​oid备份/恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆