Created
July 26, 2018 01:24
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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