Kotlin - Room Database Backup And Restore Tools (Library)




Room Database Backup And Restore

  

If you are using room database, you can use this library for full backup and restore. Also you can encrypt output file with your desired secret key.
This library is also available at JitPack.io
this library is compatible to androidx



Setup

The simplest way to use this library is to add the library as dependency to your build.

Gradle

Add it in your root build.gradle at the end of repositories:
allprojects {
 repositories {
  ...
  maven { url 'https://jitpack.io' }
 }
}
Step 2. Add the dependency
dependencies {
 implementation 'com.github.salehyarahmadi:RoomDatabaseBackupAndRestore:v1.0.1'
}

Usage

Backup

new Backup.Init()
    .database(database)
    .path("path-to-save-backup-file")
    .fileName("filename.txt")
    .secretKey("your-secret-key") //optional
    .onWorkFinishListener(new OnWorkFinishListener() {
         @Override
         public void onFinished(boolean success, String message) {
             // do anything
         }
     })
     .execute();

Restore

new Restore.Init()
    .database(database)
    .backupFilePath("path-to-backup-file/filename.txt")
    .secretKey("your-secret-key") // if your backup file is encrypted, this parameter is required
    .onWorkFinishListener(new OnWorkFinishListener() {
        @Override
        public void onFinished(boolean success, String message) {
            // do anything
        }
    })
    .execute();

License

Post a Comment

Previous Post Next Post