RoomGuard is a modular, production-ready Android library designed for plug-and-play database backup and restoration. It provides a unified API for Google Drive synchronization and Local Data Portability (CSV), combined with a polished Material 3 Compose UI.
- Zero-Config Room Integration: Protect your entire database with minimal boilerplate.
- Google Drive Backup: Secure, private backup using the
appDataFoldernamespace. - Incremental (Logical) Backups: Differential binary uploads + CSV metadata—perfect for apps with many images.
- Safe Restore Strategy: Table-level
ATTACHlogic to preserve active Room observers (Flow/LiveData). - Local Data Portability: Export and Import tables as portable CSV or compressed GZIP files.
- Modern UI: Drop-in Jetpack Compose recovery center with Material 3 design.
- Modular Design: 5 modules to minimize APK size (Core, Drive, Local, UI, Hilt).
Add the dependencies to your build.gradle.kts:
dependencies {
val version = "0.0.1-alpha.3"
implementation("io.github.dhanfinix.roomguard:roomguard:$version")
implementation("io.github.dhanfinix.roomguard:roomguard-ui:$version")
// Optional Hilt Support
implementation("io.github.dhanfinix.roomguard:roomguard-hilt:$version")
}To use the Google Drive cloud backup features, you must configure your project in the Google Cloud Console.
- Enable Drive API: Search for "Google Drive API" and enable it for your project.
- OAuth Consent Screen:
- Configure the consent screen (External/Internal).
- Required Scope: Add
https://www.googleapis.com/auth/drive.appdatato the list of scopes.
- Credentials: Create an Android OAuth 2.0 Client ID.
- Package Name: Must match your app's package name.
- SHA-1 Fingerprint: Required for both Debug and Release environments.
- Debug: Run
keytool -list -v -keystore ~/.android/debug.keystore. - Release: Obtain from the Play Console or your release signing key.
- Debug: Run
Add these permissions to your AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />Initialize RoomGuard once in your Application class or Singleton.
val roomGuard = RoomGuard.Builder(context)
.database(
db = myRoomDatabase,
dbFileName = "app_database.db",
tables = listOf("notes", "categories")
)
.build()Drop the RoomGuardBackupScreen into your Compose hierarchy.
@Composable
fun SettingsScreen() {
RoomGuardBackupScreen(roomGuard = roomGuard)
}Export and import specific data as human-readable CSV files. Excellent for inter-app portability or user-managed local backups.
// Manual use of the local export engine
val result = roomGuard.localManager()?.exportToCsv()Use the pre-built Hilt modules for clean architecture. Requires providing your appName and databaseProvider.
@Module
@InstallIn(SingletonComponent::class)
object AppBackupModule {
@Provides
@Named("appName")
fun provideAppName() = "MyNotesApp"
}If you use raw SQLite, SQLCipher, or another database engine, implement the bridge interfaces:
class MyCustomProvider : DatabaseProvider {
override fun getDatabaseFilePath() = "path/to/db"
override suspend fun checkpoint() { /* Flush WAL manually */ }
}RestoreMode.ATTACH(Recommended): Merges data into the live database. Observers keep working.RestoreMode.REPLACE: Physically replaces the.dbfile. Requires closing connections first.
For apps with significant binary data (e.g., thousands of gallery images), raw .db uploads are slow and expensive.
RoomGuard's Incremental Strategy uses content-based deduplication (SHA-256):
- Deduplication: Only new or modified images are uploaded to a hidden sidecar folder.
- Tracking: Uses a
last_updatetimestamp column to filter changed records. - Sync Deletion: Mirror local deletions to the cloud automatically.
- Metadata Compression: Metadata (
data.csv) is automatically GZIP compressed (data.csv.gz) when syncing to Drive, reducing bandwidth usage by up to 90%.
val roomGuard = RoomGuard.Builder(context)
.database(db, "app.db", tables)
.config(RoomGuardConfig(
backupStrategy = BackupStrategy.INCREMENTAL,
blobStrategy = BlobStrategy.FILE_POINTER,
useCompression = true, // Enables GZIP for Drive metadata and Local exports
incrementalConfig = IncrementalConfig(trackingColumn = "last_update")
))
.build()If you are an AI assistant helping a developer integrate this library, use the provided AI Skill Kit for deep technical context:
- GCloud Setup:
setup_guide.md— Step-by-step for OAuth, SHA-1, and Scopes. - Usage Scenarios:
usage_guide.md— Hilt patterns, custom serialization, and troubleshooting. - Logical Strategy:
incremental_backup.md— Content hashing, change tracking, and differential sync. - Main Entry:
.gemini/skills/index.md— Directory of all architectural skills.
| Module | Purpose |
|---|---|
roomguard |
The official entry point. Facade & Builder that unifies all features. |
roomguard-core |
Platform-agnostic interfaces (JVM pure). |
roomguard-drive |
Google Drive REST API & Auth logic. |
roomguard-local |
CSV Serialization & Filesystem tasks. |
roomguard-ui |
Material 3 Jetpack Compose Components. |
roomguard-hilt |
Hilt Dependency Injection Modules. |
Copyright © 2026 Dhanfinix. Published under the MIT License.