- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将 bike_info.db 恢复到我的应用程序db 文件有一些记录,我想在应用程序中恢复它们
我尝试了下面的代码,显示 toast successful 但数据库没有恢复,我不知道为什么。谁能帮忙?
rest = (Button) findViewById(R.id.cview_restore);
rest.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String currentDBPath = "//data//" + "com.infyco.kp.new_tab"
+ "//databases//" + "bike_info.db";
String backupDBPath = "//data//bike_info.db"; // From SD directory.
File backupDB = new File(data, currentDBPath);
File currentDB = new File(sd, backupDBPath);
FileChannel src = new FileInputStream(backupDB).getChannel();
FileChannel dst = new FileOutputStream(currentDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
Toast.makeText(getApplicationContext(), "Import Successful!",
Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Import Failed!", Toast.LENGTH_SHORT)
.show();
}
}
});
点击 rest 按钮后,这是 android monitor 的输出:
01-17 14:00:40.922 8909-8909/com.infyco.kp.new_tab D/ViewRootImpl: ViewPostImeInputStage processPointer 0
01-17 14:00:40.962 8909-8909/com.infyco.kp.new_tab D/ViewRootImpl: ViewPostImeInputStage processPointer 1
01-17 14:00:41.012 8909-8909/com.infyco.kp.new_tab D/ViewRootImpl: #1 mView = android.widget.LinearLayout{9ba3ae9 V.E...... ......I. 0,0-0,0 #102039d android:id/toast_layout_root}
01-17 14:00:41.072 8909-8909/com.infyco.kp.new_tab D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
01-17 14:00:43.022 8909-8909/com.infyco.kp.new_tab D/ViewRootImpl: #3 mView = null
最佳答案
这是工作恢复的核心恢复代码。一些区别:我在关门前冲水。
我重命名了原始数据库(制作副本并删除原始数据库)因此它不存在(如果恢复失败很容易恢复)。
我也在它自己的线程中执行此操作(此处未显示)。
我从系统获取数据库的路径/文件名。
dbfile = new File(currentdbfilename);
.......
try {
// Stage 1 Create a copy of the database
Log.i(logtag, "Stage 1 (make Copy of current DB)Starting");
FileInputStream fis = new FileInputStream(dbfile);
OutputStream backup = new FileOutputStream(copydbfilename);
while ((copylength = fis.read(buffer)) > 0) {
backup.write(buffer, 0, copylength);
}
backup.flush();
backup.close();
fis.close();
Log.i(logtag, "Stage 1 - Complete. Copy made of current DB.");
copytaken = true;
// Stage 2 - Delete the database file
if (dbfile.delete()) {
Log.i(logtag, "Stage 2 - Completed. Original DB deleted.");
origdeleted = true;
}
// Stage 3 copy from the backup to the deleted database file i.e. create it
Log.i(logtag, "Stage 3 - (Create new DB from backup) Starting.");
FileInputStream bkp = new FileInputStream(backupfilename);
OutputStream restore = new FileOutputStream(currentdbfilename);
copylength = 0;
while ((copylength = bkp.read(buffer)) > 0) {
restore.write(buffer, 0, copylength);
}
Log.i(logtag, "Stage 3 - Data Written");
restore.flush();
restore.close();
Log.i(logtag, "Stage 3 - New DB file flushed and closed");
restoredone = true;
bkp.close();
Log.i(logtag, "Stage 3 - Complete.");
} catch (IOException e) {
e.printStackTrace();
if(!copytaken) {
errlist.add("Restore failed copying current database. Error was " + e.getMessage());
} else {
if(!origdeleted) {
errlist.add("Restore failed to delete current database. Error was " + e.getMessage());
}
else {
if(!restoredone) {
errlist.add("Restore failed to recreate the database from the backup. Error was "+ e.getMessage());
errlist.add("Restore will attempt to revert to the original database.");
}
}
}
}
currentdbfilename 设置使用:-
currentdbfilename = this.getDatabasePath(
DBConstants.DATABASE_NAME)
.getPath();
copydbfilename 是通过微调器从可用备份列表中选择的(略有不同的是备份位于公共(public)外部存储中)。
关于android - 如何为非root设备恢复android中sqlite的数据库备份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41692316/
如何启用 Mercurial(中央/主)存储库的自动(增量)备份? 我来自颠覆,在那里我能够制作一个提交 Hook ,将更改上传到 S3。 编辑: 如果这种策略对 Mercurial 没有意义,那么什
我想定期创建我的github存储库的备份。是否有一种快速的方法可以在不知道整个列表的情况下将它们全部拉出? 沃尔特 最佳答案 您可以通过GitHub的API获取整个列表: curl http://gi
我正在使用 flatpages在我在本地服务器上开发的站点中。我需要备份平面页面的数据以在最终服务器中使用它。有谁知道怎么做? 最佳答案 在您的本地服务器上运行: python manage.py d
我们已将应用服务升级到 S1,并希望设置自动备份。这是一个带有 SQL 数据库的 .net core 应用程序。对于数据库部分,我得到以下内容: No supported connection str
我们使用一些 阻止 blob 来存储一些持久资源,然后 用于存储事件数据的页面 blob 我们需要备份 blob,因此我尝试使用 AzCopy。它在我的开发机器上工作正常,但在其他慢速机器上失败,并出
关闭。这个问题需要更多 focused .它目前不接受答案。 想改进这个问题?更新问题,使其仅关注一个问题 editing this post . 5年前关闭。 Improve this questi
我正在看这个例子 docker run --rm --volumes-from myredis -v $(pwd)/backup:/backup debian cp /data/dump.rdb /b
我们使用一些 阻止 blob 来存储一些持久资源,然后 用于存储事件数据的页面 blob 我们需要备份 blob,因此我尝试使用 AzCopy。它在我的开发机器上工作正常,但在其他慢速机器上失败,并出
我目前正在使用 Java,并且正在寻找一个程序,该程序可以在每次编译时保存我正在执行的操作的新版本。我不介意它是否不运行,我可以进去编辑类名,使其与 .java 名称匹配。由于我是一个初学者,我总是因
在 RabbitMQ 管理控制台中,出于导入和导出目的,我在概览页面底部看到了导入/导出定义链接。但是有了这个,我能够导出整套队列、交换等。 我有一个 MQ 服务器,其中包含多个应用程序的 MQ 设置
我在 Eclipse IDE 中做了一个 Maven 项目,但在某些时候,我决定以其他名称复制并粘贴工作区位置中的文件夹,以避免在迄今为止工作正常的原始项目中进行一些错误配置,但是,我在执行中遇到了问
有没有办法备份在任何给定元素上设置的所有事件? 背景故事:我有一些代码,当用户将鼠标悬停在某个图标上时(想想悬停帮助文本),会显示绝对定位的“弹出窗口”。如果用户将鼠标悬停在弹出窗口上,它会停留在周围
我需要将 MySQL 数据库移动到新位置。根据workbench,数据库大小只有200MB,但有些表有数百万行,报告索引和数GB的数据长度。结果,EXPORT 的大小为 15GB,导出 DB 并将其复
我有一个工作数据库 - 我想复制它的所有数据(甚至只是其中的 1 个表)并在磁盘上创建备份,并在另一个位置(不是同一台计算机)上创建一个“备份”数据库。另一台计算机未连接到互联网 我该怎么做? 最佳答
我有一个实时数据库,我想要做的是制作一份副本。我可以通过 SSH 和 phpMyAdmin 访问 MySQl。是否有一个命令可以在单个命令/操作中复制/备份数据库,而无需使用导出/导入? 谢谢 最佳答
我是 PostgreSQL 的新手,我正在寻找备份数据库的方法。我知道有 3 种方法 pg_dump,快照和复制以及使用 WAL。您建议使用哪一个来完整备份数据库?如果可能,请提供代码片段。 最佳答案
如何快速备份/恢复mysql数据库中的数据? 最佳答案 mysqldump命令行备份最快, (使用mysql命令行恢复,mysql -u #username# -p #database# < #dum
从管理的角度来看,我是 MySQL 的新手。 在过去的几个小时里,我一直在谷歌上搜索,但没有成功,我想知道是否有人可以为我指明正确的方向,让我知道要用谷歌搜索什么或提出建议。 基本上,我正在寻找有关如
我需要备份创建模式附带的数据库(转储)。使用 putty(通过 SSH)完成这项工作的命令行是什么?我研究并思考了这个命令,但它只执行表备份和数据。 mysqldump -h HOST -u LOGI
我正在尝试创建一个将整个/dev/sda1 备份到/mnt/Backup 的 bash 脚本 /dev/sda1 457G 3.5G 431G 1% / /dev/sdb1
我是一名优秀的程序员,十分优秀!