How to migrate data & settings from one firebase to another?

前端 未结 5 1790
盖世英雄少女心
盖世英雄少女心 2020-12-14 10:43

Are there any tools to aid in data migration from dev to staging to prod? If not, are there plans to build them?

I know you can Export JSON and Import JSON from Forg

5条回答
  •  攒了一身酷
    2020-12-14 11:06

    If you want an option that doesn't require cURL, and you have the firebase-tools project installed, you can run this:

    firebase database:get --export -o backup.json /
    

    Note that this should be run from a working directory configured as a Firebase project. The advantage of this option is it will use the Auth you've set up for that project, so you don't need to hard-code auth keys into command lines (for the security-conscious) and it doesn't rely on the deprecated auth-key pattern.

    Command-line Fu: Another cool technique if you want separate files for each top-level key is calling:

    for i in `firebase database:get --shallow / | jq -r 'keys[]'`; do
        echo "Downloading $i..."
        firebase database:get --export -o $i.json /$i
    done
    

    You will need the "jq" tool installed for this to work. Exporting each collection separately can be really useful if you later want to restore or work with just a portion of your data.

提交回复
热议问题