Firebase Realtime Database (RTDB) lossless restore toolkit for large backups
Project description
Firebase RTDB Lossless Restore Toolkit
A simple, memory-efficient toolkit to restore large Firebase Realtime Database (RTDB) backups safely and without data loss.
The Problem
Restoring a large Firebase database backup (e.g., 1 GB+) using default tools is difficult for three reasons:
- The Overwrite Trap: Importing a JSON file in the Firebase Console completely erases all existing data at that path first. You cannot upload a large backup in pieces because each new piece wipes out the previous ones.
- Request Size Limits: Firebase limits the size of a single write request. Large backup files will timeout or fail with payload size errors.
- Out-Of-Memory Crashes: Loading a giant JSON backup file into memory will crash standard scripts.
The Solution
This toolkit solves these problems using four simple steps:
- Stream Splitting: Splits a giant JSON file into smaller chunks without loading the whole file into memory. It reads the file in tiny 128 KB blocks.
- Lossless Verification: Automatically checks that no data was lost during splitting by comparing SHA-256 fingerprints of every single entry.
- Batch Uploading: Groups entries into safe ≤ 4 MB batches and uploads them using additive
PATCHupdates, merging data without erasing anything else. - Oversized Entry Recovery: Recursively splits individual massive entries (like a single user with huge data) child-key by child-key so they fit under request limits.
Installation
Via PyPI
pip install firebase-rtdb-tools
This installs four simple command-line tools:
firebase-rtdb-splitfirebase-rtdb-validatefirebase-rtdb-uploadfirebase-rtdb-upload-single
If PyPI does not show the package yet, install from source until the next release workflow publishes successfully.
From Source
git clone https://github.com/berkayturanci/firebase-rtdb-restore.git
cd firebase-rtdb-restore
pip install -r requirements.txt
For local development, install the editable package with development tools:
pip install -e ".[dev]"
How to Get Your Firebase Service Account Key
To upload data to your Firebase database:
- Go to your Firebase Console -> Project Settings -> Service accounts.
- Click Generate new private key and download the JSON file.
- Pass the path to this JSON file using the
-s/--service-accountoption, or set the environment variable:export FIREBASE_SERVICE_ACCOUNT_KEY="/path/to/serviceAccountKey.json"
Simple Restore Workflow
Step 1: Split the giant backup file
Split the backup JSON into smaller files (default is 1,000 entries per file):
make split BACKUP=backup.json CHUNKS=./chunks NODE=users
(Or use firebase-rtdb-split backup.json -o ./chunks -n users -c 1000)
Step 2: Verify the split
Check that the split was 100% exact and no data was lost:
make validate BACKUP=backup.json CHUNKS=./chunks NODE=users
(Or use firebase-rtdb-validate backup.json ./chunks -n users)
Do not proceed if this step fails.
Step 3: Upload chunks to Firebase
Upload all chunks to your database. This merges data additively and will not overwrite other sibling nodes:
# Option A: Append/Resume (merges chunks into /users without wiping anything else)
make upload CHUNKS=./chunks SA=serviceAccountKey.json DBPATH=/users
# Option B: Clean restore of the TARGET path (wipes /users first, leaves siblings intact)
make upload-wipe CHUNKS=./chunks SA=serviceAccountKey.json DBPATH=/users
# Option C: Full reset (wipes the ENTIRE database root first — destroys all data)
make upload-wipe-root CHUNKS=./chunks SA=serviceAccountKey.json DBPATH=/users
(Or use firebase-rtdb-upload ./chunks -s serviceAccountKey.json -p /users --wipe)
Upload options:
--wipewipes only the target path (-p);--wipe-rootwipes the entire database root.--dry-runpreviews exactly what would be wiped/uploaded without writing anything.-w/--workers Nuploads N chunks in parallel (default 1).- Uploads are resumable: completed chunks are recorded in a
.upload-progressfile inside the chunks directory and skipped automatically when you re-run after a failure. Transient write errors are retried with exponential backoff.
Step 4: Handle giant entries (if any)
If the upload script reports that a specific entry failed because it is too large to fit in a single request:
make upload-single UID=some_uid CHUNKS=./chunks/chunk_0000.json SA=serviceAccountKey.json DBPATH=/users
(Or use firebase-rtdb-upload-single some_uid ./chunks/chunk_0000.json -s serviceAccountKey.json -p /users)
License
MIT License. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file firebase_rtdb_tools-0.2.1.tar.gz.
File metadata
- Download URL: firebase_rtdb_tools-0.2.1.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
066fafb1ca4d09d0cefa3e8d833ce666e43fbd0f8532acead9ccd2db30bef9ae
|
|
| MD5 |
d01da7df0fb2d8c4ff4f3e3084e556e6
|
|
| BLAKE2b-256 |
b4058d9f8f44b001a8b225e00a5fc4ecb554c6ddb1d404db5f2aec6ddb5daf59
|
File details
Details for the file firebase_rtdb_tools-0.2.1-py3-none-any.whl.
File metadata
- Download URL: firebase_rtdb_tools-0.2.1-py3-none-any.whl
- Upload date:
- Size: 18.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a17577b6f087a25381ecb02dd92256702443d6239af23f82c3b7d88b3999319
|
|
| MD5 |
b2e7bd39a7dca01a79ff337b7a5352d3
|
|
| BLAKE2b-256 |
333835c58f8fd70e36a82b0ba06327dfb4b77e25009e0a3c14e0b3b58b2f4a40
|