steadyequipment / node-firestore-backup

Google Firebase Firestore backup tool
190 stars 51 forks source link
backup cli firebase firestore

firestore-backup

A Google Firebase Firestore backup tool.

codebeat badge Codacy Badge David badge

Note: Firebase now has an official backup and restore tool

Read more about how to use it here: https://firebase.google.com/docs/firestore/manage-data/export-import

Installation

Install using npm.

npm install -g firestore-backup

or yarn

yarn global add firestore-backup

Alternatively download the source.

git clone https://github.com/steadyequipment/node-firestore-backup.git

Retrieving Google Cloud Account Credentials

  1. Visit the Firebase Console
  2. Select your project
  3. Navigate to Project Settings (at the time of writing the gear icon button at the top left of the page).
  4. Navigate to Service Accounts
  5. Click Generate New Private Key

This downloaded json file contains the proper credentials needed for firestore-backup to authenticate.

Usage

Backup:

Example:

firestore-backup --accountCredentials path/to/credentials/file.json --backupPath /backups/myDatabase

Backup with pretty printing:

Example:

firestore-backup --accountCredentials path/to/credentials/file.json --backupPath /backups/myDatabase --prettyPrint

Backup from a starting path:

Example:

firestore-backup --accountCredentials path/to/credentials/file.json --backupPath /backups/myDatabase --databaseStartPath /myCollection/document_3

Limit number of requests:

Example:

firestore-backup --accountCredentials path/to/credentials/file.json --backupPath /backups/myDatabase --requestCountLimit 2

Exclude top level collections from backup:

Note: because of how the command line parsing library works multiple collection ids must be specified as separate parameters.

Example:

firestore-backup --accountCredentials path/to/credentials/file.json --backupPath /backups/myDatabase --excludeCollections myFirstAnnoyingCollection --excludeCollections mySecondAnnoyingCollection

Exclude paths by regex:

These patterns can support excluding several different sections of trees, e.g.:

Note: when combining excludePattern with databaseStartPath, the patterns are tested against the full path of the document off the root of database (with a leading slash).

Note: because of how the command line parsing library works multiple exclude patterns must be specified as separate parameters.

Example:

firestore-backup --accountCredentials path/to/credentials/file.json --backupPath /backups/myDatabase --excludePattern '^/collectionToIgnore' --excludePattern '^/[^/]*/[^/]*/subcollectionToIgnore'

Fetch documents in batches:

Example:

firestore-backup --accountCredentials path/to/credentials/file.json --backupPath /backups/myDatabase --batchSize 25

Relax:

That's it! ✨🌈

Contributions

This project has been made much better by it's contributors, feel free to report bugs and make feature requests in the Issue Tracker, fork and create pull requests!