Skip to content

Instantly share code, notes, and snippets.

@adamghill
Created July 26, 2018 01:24
Show Gist options
  • Save adamghill/7fb8273271232e1e08a0c6a03840d6b2 to your computer and use it in GitHub Desktop.
Save adamghill/7fb8273271232e1e08a0c6a03840d6b2 to your computer and use it in GitHub Desktop.
Shell script to move data from one Firebase realtime database to another (helpful for live->test migrations)
#! /bin/bash
live_database="LIVE_DATABASE_NAME"
test_database="TEST_DATABASE_NAME"
read -p "This is a destructive operation on the test Firebase database ($test_database). Are you sure you want to continue? (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
nodes=( "NODE_1" "NODE_2" )
for node in "${nodes[@]}"
do
echo "Try to populate /$node..."
# tee is used because some nodes failed to set with bad JSON errors
firebase database:get /$node --instance $live_database | tee | firebase database:set /$node --instance $test_database --confirm
if [ $? -eq 0 ]; then
echo "Populating /$node succeeded."
else
echo "Looks like getting $node failed. Attempting to save the JSON to $node.json for manual importing."
firebase database:get /$node --instance $live_database > $node.json
fi
echo
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment