Skip to content

Instantly share code, notes, and snippets.

@crrobinson14
Created August 1, 2017 00:54
Show Gist options
  • Save crrobinson14/71a0d22aabe3a0d855d34b46b7d7a115 to your computer and use it in GitHub Desktop.
Save crrobinson14/71a0d22aabe3a0d855d34b46b7d7a115 to your computer and use it in GitHub Desktop.
Firebase Realtime Database Backup Script
#!/usr/bin/env bash
# This script uses a shallow-get technique to get a list of all top level keys
# in a Firebase Realtime Database, then extract the tree under each key into a
# separate JSON file, one per top level key.
#
# It’s great for making backups because you don’t end up with one ginormous
# export file which is really hard to manage with other tools.
#
# It can also immediately give you a sense of where your space is going per key,
# which is hard to do any other way. Just look at the size of each JSON file.
for i in `firebase database:get --shallow / | jq -r 'keys[]'`; do
firebase database:get --export -o backup/$i.json /$i
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment