Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to backup/restore SQLite database on Android to Dropbox

I am currently developing an Android application which makes use of the SQLite database. I am looking for ideas how to backup/restore the database to and from external services such as Dropbox. I have gone through some explanations such as below:

Android backup/restore: how to backup an internal database?

Backup/restore sqlite db in android

These explanation are mainly about backing up locally, but I want to backup to cloud, as I mentioned, something like Dropbox.

Help please... Thanks in advance...

like image 779
Tom R. Avatar asked Oct 06 '14 08:10

Tom R.


People also ask

How do I backup SQLite database on Android?

1. copy your db to sdcard 2. if reinstall, copy db back to the app. @earthw0rmjim Any approach in which I can get the original state retained without the network.

Where is SQLite stored on Android?

The Android SDK provides dedicated APIs that allow developers to use SQLite databases in their applications. The SQLite files are generally stored on the internal storage under /data/data/<packageName>/databases.

Where do I put db files on Android?

You can add your database file in assets folder. you can add your db file in the assets folder. If it solution isn't true, should describe your problem.


1 Answers

Using the answer here, you can get a reference to your database in the form of a .db File object.

final String inFileName = "/data/data/<your.app.package>/databases/foo.db";
File dbFile = new File(inFileName);

Once you have this, it's easy to read/write to a user's Dropbox using the Dropbox Sync API.

  • Backup: Use writeFromExistingFile() to write this local File to the Dropbox directory
  • Restore: Use getReadStream() to get a FileInputStream that can write to the appropriate local path where your .db file goes.
like image 94
Nachi Avatar answered Sep 24 '22 06:09

Nachi