How to create couchbase database backup file on android device

I want to implement Whatsapp like database backup-restore functionality. I am using couchbase lite in my android application for storing the data. I want to get the couchbase backup file and store that file on google drive and then when needed I should be able to restore the database by downloading it from google drive.

  • How I can create a backup file or get the database file in Android app.
  • How I can restore the downloaded file into my mobile.
  • How I can restore only chunk of data into my existing database.

First of all, to find out your database location by calling DatabaseConfiguration object’s getDirectory(), You may write log to find out, such as

Log.i(TAG, “database_create directory=” + config.getDirectory());

then adb logcat will show something like:

06-10 15:24:31.899 1878 1908 I DATABASE: database_create directory=/data/data/com.couchbase.testapp/files

then use adb pull command to download the database, actually the database includes a bunch of files under your-db_name.cblite2.

Later on you can use adb push to restore the database files into the same location where your database supposes to be stored.

I am not sure if it’s possible to restore a subset of data into an existing database.