自动备份SQLite数据库 [英] Automatically backing up SQLite database

查看:577
本文介绍了自动备份SQLite数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序使用了一个我希望备份的小型SQLite数据库.我假设如果没有使用fullBackupContent对其进行编码,这将不会自动发生,如下所示.如何修改backupscheme.xml的内容以正确设置包含路径?我更喜欢在运行时设置数据库位置.

My app uses a small SQLite database that I'd like to have backed up. I'm assuming this won't happen automatically, without my coding for it using fullBackupContent, shown below. How do I modify the content of my backupscheme.xml to set the include path correctly? I prefer to set the db location at runtime.

我的backupscheme.xml看起来像

My backupscheme.xml looks like

<?xml version="1.0" encoding="utf-8"?>
<full-backup-content >
    <include domain="database" path="device_info.db"/>
</full-backup-content

我的清单包含:

    <application
    android:allowBackup="true"
    android:icon="@drawable/time_machine_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" 
    android:name="mypackage.myapp"
    android:fullBackupContent="@xml/backupscheme" 
    > 

推荐答案

<include domain="database" path="device_info.db"/>

此处,域表示在其中解释path的根目录. database映射到默认情况下SQLite数据库的存储位置,如果您使用的话:

Here, the domain indicates the root directory in which the path is interpreted. database maps to where SQLite databases are stored by default, if you use:

    >上的
  • getDatabasePath()
  • SQLiteOpenHelper仅具有纯文件名
  • openOrCreateDatabase()仅具有纯文件名
  • getDatabasePath() on Context
  • SQLiteOpenHelper with just a plain filename
  • openOrCreateDatabase() with just a plain filename

在这种情况下,文件名应为您的path值.

In that case, the filename should be your path value.

如果由于某种原因数据库存储在其他位置,则<include>指令将需要进行一些调整.

If your database is stored somewhere else for some reason, the <include> directive would need some adjustment.

这篇关于自动备份SQLite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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