rafi0101 / Android-Room-Database-Backup

Simple tool to backup and restore your room database in Android
MIT License
239 stars 19 forks source link
android android-library android-room android-room-persistence-library backup backups encryption hacktoberfest kotlin restore room room-backup room-database

Android-Room-Database-Backup

Build Maven Central Room Version API Language PRWelcome License

Built with ❤︎ by Raphael Ebner


Simple tool to backup and restore your room database in Android

Features

Content

Changelog

Changelog and Upgrading notes

Getting started

Android-Room-Database-Backup library is pushed to Maven Central .
Add the dependency for Android-Room-Database-Backup to your app-level build.gradle file.

implementation 'de.raphaelebner:roomdatabasebackup:1.0.1'

If the version makes any technical problems please feel free to contact me. I made some changes in Gradle/Kotlin DSL and not sure if everything is working as excepted

Usage

Properties

Required

e.g. YourDatabase.kt

Optional

The following options are optional and the default options

Exit Codes

Here are all exit codes for the onCompleteListener.
They can be calles using OnCompleteListener.$NAME$

Exit Code Name Description
0 EXIT_CODE_SUCCESS No error, action successful
1 EXIT_CODE_ERROR Other Error
2 EXIT_CODE_ERROR_BACKUP_FILE_CHOOSER Error while choosing backup to restore. Maybe no file selected
3 EXIT_CODE_ERROR_BACKUP_FILE_CREATOR Error while choosing backup file to create. Maybe no file selected
4 EXIT_CODE_ERROR_BACKUP_LOCATION_FILE_MISSING [BACKUP_FILE_LOCATION_CUSTOM_FILE] is set but [RoomBackup.backupLocationCustomFile] is not set
5 EXIT_CODE_ERROR_BACKUP_LOCATION_MISSING [RoomBackup.backupLocation] is not set
6 EXIT_CODE_ERROR_BY_USER_CANCELED Restore dialog for internal/external storage was canceled by user
7 EXIT_CODE_ERROR_DECRYPTION_ERROR Cannot decrypt provided backup file
8 EXIT_CODE_ERROR_ENCRYPTION_ERROR Cannot encrypt database backup
9 EXIT_CODE_ERROR_RESTORE_BACKUP_IS_ENCRYPTED You tried to restore a encrypted backup but [RoomBackup.backupIsEncrypted] is set to false
10 EXIT_CODE_ERROR_RESTORE_NO_BACKUPS_AVAILABLE No backups to restore are available in internal/external sotrage
11 EXIT_CODE_ERROR_ROOM_DATABASE_MISSING No room database to backup is provided
12 EXIT_CODE_ERROR_STORAGE_PERMISSONS_NOT_GRANTED Storage permissions not granted for custom dialog
13 EXIT_CODE_ERROR_WRONG_DECRYPTION_PASSWORD Cannot decrypt provided backup file because the password is incorrect

Example Activity (Kotlin and Java)

Kotlin

Java

Example Fragment (Kotlin and Java)

Kotlin

FragmentActivity.kt
MainFragment.kt

Java

FragmentActivityJava.java
MainFragmentJava.java

Sample app

  1. Download this repo
  2. Unzip
  3. Android Studio --> File --> Open --> select this Project
  4. within the app folder you find the sample app

Developed by

License

MIT License

Copyright (c) 2024 Raphael Ebner

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.