Firebase collection backup script

 If you need save some separate collection on your computer or you want backup your data outside of Firebase and default options on Google bucket. 

Working together firestore.client and tinyDb you can store your data on your computer or any other server.

Google has a well-functioning system for import / export data, but in exceptional cases it needs extra copy, then you can execute it with such a script.

        dbfile = "data/CategoryToLabelMapper.json"
        cred = credentials.Certificate("firebase-adminsdk-m3mts-d27dbb2c96.json")
        db = firestore.client()
        tiny = TinyDB(dbfile)
        collection = db.collection('CategoryToLabelMapper')
        docs =
        for doc in docs:
            dic = doc.to_dict()
             tiny.insert({ dic})


So, your export file will be something like this. 


For default solution please follow this documentation. 

  1. Go to the Cloud Firestore Import/Export page in the Google Cloud Platform Console.

    Go to the Import/Export page

  2. Click Export.

  3. Click the Export one or more collection groups option. Use the dropdown menu to select one or more collection groups.

  4. Below Choose Destination, enter the name of a Cloud Storage bucket or use the Browse button to select a bucket.

  5. Click Export.

The console returns to the Import/Export page. If the operation successfully starts, the page adds an entry to the recent imports and exports page. On failure, the page displays an error message.