Skip to main content

Firebase Realtime Database (RTDB) lossless restore toolkit for large backups

Project description

Firebase RTDB Restore Toolkit — stream-split, verify, and losslessly restore large Firebase Realtime Database backups

Firebase RTDB Lossless Restore Toolkit

A simple, memory-efficient toolkit to restore large Firebase Realtime Database (RTDB) backups safely and without data loss.

GitHub release (latest SemVer) PyPI Run Tests License: MIT


The Problem

Restoring a large Firebase database backup (e.g., 1 GB+) using default tools is difficult for three reasons:

  1. 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.
  2. Request Size Limits: Firebase limits the size of a single write request. Large backup files will timeout or fail with payload size errors.
  3. 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 PATCH updates, 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-split
  • firebase-rtdb-validate
  • firebase-rtdb-upload
  • firebase-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:

  1. Go to your Firebase Console -> Project Settings -> Service accounts.
  2. Click Generate new private key and download the JSON file.
  3. Pass the path to this JSON file using the -s / --service-account option, 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:

  • --wipe wipes only the target path (-p); --wipe-root wipes the entire database root.
  • --dry-run previews exactly what would be wiped/uploaded without writing anything.
  • -w/--workers N uploads N chunks in parallel (default 1).
  • Uploads are resumable: completed chunks are recorded in a .upload-progress file 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

firebase_rtdb_tools-0.2.3.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

firebase_rtdb_tools-0.2.3-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

Details for the file firebase_rtdb_tools-0.2.3.tar.gz.

File metadata

  • Download URL: firebase_rtdb_tools-0.2.3.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for firebase_rtdb_tools-0.2.3.tar.gz
Algorithm Hash digest
SHA256 929cd0371a12bcdf2a9124197c7213f10bd340ab5b4a277ca66acc331f8cc73d
MD5 91238dc7784345ea3a73e6161e864470
BLAKE2b-256 c42956f979ad23e2d2e0ae80befd7a68854210bd58ddf45a8d625936874b9519

See more details on using hashes here.

Provenance

The following attestation bundles were made for firebase_rtdb_tools-0.2.3.tar.gz:

Publisher: publish.yml on berkayturanci/firebase-rtdb-restore

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file firebase_rtdb_tools-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for firebase_rtdb_tools-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2c686eff71a324156aa24ee4839881bb08e0b20bba6c8fdd24a59b6954fd29cc
MD5 cf2fe4557fad281867068a97a70f9c18
BLAKE2b-256 c9e51ccd621d2403f343b7e151a30e4471c3c11a61d86ad4b247d6179602eec8

See more details on using hashes here.

Provenance

The following attestation bundles were made for firebase_rtdb_tools-0.2.3-py3-none-any.whl:

Publisher: publish.yml on berkayturanci/firebase-rtdb-restore

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page