5

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...

Community
  • 1
  • 1
Tom R.
  • 71
  • 1
  • 1
  • 7

1 Answers1

6

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.
Community
  • 1
  • 1
Nachi
  • 4,218
  • 2
  • 37
  • 58
  • thanks for the direct answer! but that also means that i have to save the dropbox login info in sharedpreferences? if do i, rooted android's will be able to view the info. can i apply encryption without messing the backup/restore process? – Tom R. Oct 06 '14 at 20:04
  • 1
    You authenticate users to use your app using [startLink](https://www.dropbox.com/developers/sync/docs/android#com.dropbox.sync.android.DbxAccountManager.startLink). No login info is saved by you, the dropbox SDK handles the logging in for you. In general there is no secure solution for rooted phones. Encrypting data is of no use because on a rooted phone anyone could also find the decryption key. – Nachi Oct 08 '14 at 08:12