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.
Why This Exists
Firebase RTDB exports are easy to create, but restoring large backups safely is harder than it looks. Teams often discover the risk only during an incident: the console import path overwrites data, one-shot scripts run into request limits, and many JSON processors load too much into memory.
This project is built for the recovery path where correctness matters more than cleverness. It gives you a repeatable split -> validate -> dry-run -> upload workflow, with explicit destructive flags, resumable progress, release checksums, an SBOM, and a production restore runbook.
Terminal Demo
$ pip install firebase-rtdb-tools
$ firebase-rtdb-split backup.json -o ./chunks -n users -c 1000
Done: 2048 entries -> 3 chunk files.
$ firebase-rtdb-validate backup.json ./chunks -n users
RESULT: PASSED - chunks are a 100% lossless split.
$ firebase-rtdb-upload ./chunks -s serviceAccountKey.json -p /users --dry-run
Dry run complete: 3 chunks checked, 0 writes performed.
Want to share the project? See the Launch Kit for short posts, long-form copy, and community-specific submission drafts.
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"
Before You Restore Production Data
⚠️ WARNING: Destructive operations like --wipe and --wipe-root can cause irreversible data loss if misused.
If you are restoring production data, please stop and read the Production Restore Runbook before proceeding. The runbook covers:
- Safe dry-run previews
- Resuming from partial uploads
- Handling exponential backoff and rate limits
- Validating post-restore state
For a full list of all parameters, see the CLI/API Reference. Other resources: Contributing Guide | Security Policy | Release Notes.
Choose Your Workflow
| Goal | Command Flag | Behavior |
|---|---|---|
| Evaluate/Preview | --dry-run |
Reads chunks and simulates the upload without writing any data. |
| Append/Resume | (default) | Uses additive PATCH to merge data. Does not erase existing siblings. |
| Target Wipe | --wipe |
Wipes ONLY the specific target node (-p /users) before uploading chunks. |
| Root Wipe | --wipe-root |
🚨 Wipes the ENTIRE database root (/) before uploading. |
| Oversized Recovery | upload-single |
Recursively splits and uploads a single giant node key-by-key. |
Quick Examples
The commands below are quick examples. For production-safe procedures, refer to the Production Restore Runbook.
New here? Try the whole split → validate flow on safe, synthetic data first — no Firebase project needed. See
examples/README.md.
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.
Metadata
Release files for firebase-rtdb-tools 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| firebase_rtdb_tools-0.2.3.tar.gz | 23.1 kB | With provenance | Details for firebase_rtdb_tools-0.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| firebase_rtdb_tools-0.2.3-py3-none-any.whl | Python 3 | none | any | Details for firebase_rtdb_tools-0.2.3-py3-none-any.whl |
Total release size: 42.9 kB
Release files / firebase_rtdb_tools-0.2.3.tar.gz
| Download URL | firebase_rtdb_tools-0.2.3.tar.gz |
|---|---|
| Size | 23.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
929cd0371a12bcdf2a9124197c7213f10bd340ab5b4a277ca66acc331f8cc73d
|
|
BLAKE2b-256 checksum How to use checksums |
c42956f979ad23e2d2e0ae80befd7a68854210bd58ddf45a8d625936874b9519
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 31, 2026.
Transparency logRelease files / firebase_rtdb_tools-0.2.3-py3-none-any.whl
| Download URL | firebase_rtdb_tools-0.2.3-py3-none-any.whl |
|---|---|
| Size | 19.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2c686eff71a324156aa24ee4839881bb08e0b20bba6c8fdd24a59b6954fd29cc
|
|
BLAKE2b-256 checksum How to use checksums |
c9e51ccd621d2403f343b7e151a30e4471c3c11a61d86ad4b247d6179602eec8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 31, 2026.
Transparency logSecurity for firebase-rtdb-tools 0.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for firebase_rtdb_tools-0.2.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 31, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.