从设备到网站备份/恢复数据库文件?
我已经完成了一个小型学校项目,使用 SQLite 和 android 2.2 管理一个包含几本书的图书馆。后来,他们要求我创建一个后台系统,但我还没有准备好。所以我试图实现一个连接到互联网的简单备份系统。
我想要指示或提示:
- 从 data/data/package_name/databases/school 获取项目数据库
- 将其发送到在线存储库,可能只是一个 ftp 连接来上传 school_%date% 和latest.db (相同的内容)
和恢复:
- 从服务器下载最新文件,例如 http://www.site.com/school/ latest.db
- 替换 data/data/package_name/databases/school 以及下载的latest.db
我一直在阅读有关 SOA 和 REST 方法的内容,但我无法在我拥有的小型服务器上实现它......还有其他建议吗? /干杯
I've done a small school project to manage a library with several books, using SQLite and android 2.2. Later on, they asked me to create a back office system, which I wasn't ready for. So I'm trying to achieve a simple backup system that connects to the internet.
I would like directions or hints to:
- Get the project database from data/data/package_name/databases/school
- Send it to a online repository, could be just a ftp connection to upload school_%date% and latest.db (same contents)
and to restore:
- Download latest file from server, something like http://www.site.com/school/latest.db
- Replace data/data/package_name/databases/school with the downloaded latest.db
I been reading about SOA and REST approaches but I couldn't implement that on the trivial server I own... any other advices? /cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SOA 或 REST 将是最好的实现方式。最简单的方法就是获取数据库文件并将其发送到您的网络服务器。但我不知道您的应用程序是否有足够的权限在运行时恢复数据库。
您可以使用 sqlite3 命令行工具转储 sql 文件, 请参阅此处并将其发送到您的网络服务器。恢复的过程是一样的,但是您必须先删除表,然后使用检索到的数据恢复数据库。
也许有一些版本依赖性管理会很好,例如通过备份发送您的应用程序版本。通过这种方式,您可以管理数据库文件是否兼容。
SOA or REST would be the most pretty way to do it. The easy way is just to get the database file and send it to you webserver. But I don't know if your app has enough privileges to restore the database while running.
You could use the sqlite3 commandline tool to dump an sql file, see here and send it to your webserver. Restoring would be something the same, but then you have to delete your tables first, then restore the database with the retrieved data.
Maybe it would be nice to have some version dependency management like sending your app version with the backup. This way you can administer whether a database file is compatible or not.