All Projects → dalenguyen → Firestore Backup Restore

dalenguyen / Firestore Backup Restore

Licence: mit
NPM package for backup and restore Firebase Firestore

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Firestore Backup Restore

Node Firestore Import Export
Firestore data import and export
Stars: ✭ 271 (-11.73%)
Mutual labels:  firebase, backup, firestore, restore
Node Firestore Backup
Google Firebase Firestore backup tool
Stars: ✭ 192 (-37.46%)
Mutual labels:  firebase, backup, firestore
eXperDB-Management
eXperDB-Management is a integrated management tool for PostgreSQL(for efficient operation and management).
Stars: ✭ 38 (-87.62%)
Mutual labels:  backup, restore
ioBroker.backitup
Backitup enables the cyclical creation of backups of an IoBroker / Homematic installation
Stars: ✭ 43 (-85.99%)
Mutual labels:  backup, restore
Reshifter
Kubernetes cluster state management
Stars: ✭ 292 (-4.89%)
Mutual labels:  backup, restore
esop
Cloud-enabled backup and restore tool for Apache Cassandra
Stars: ✭ 40 (-86.97%)
Mutual labels:  backup, restore
mongodb-backup-manager
🌿 A Full-stack MongoDB Backup System.
Stars: ✭ 42 (-86.32%)
Mutual labels:  backup, restore
Firesql
Query Firestore using SQL syntax
Stars: ✭ 304 (-0.98%)
Mutual labels:  firebase, firestore
helm-backup
Helm plugin which performs backup/restore of releases in a namespace to/from a file
Stars: ✭ 70 (-77.2%)
Mutual labels:  backup, restore
React Admin Firebase
A firebase data provider for the react-admin framework
Stars: ✭ 269 (-12.38%)
Mutual labels:  firebase, firestore
Pring
Cloud Firestore model framework for iOS - Google
Stars: ✭ 260 (-15.31%)
Mutual labels:  firebase, firestore
Vuefire
🔥 Firebase bindings for Vue.js & Vuex
Stars: ✭ 3,234 (+953.42%)
Mutual labels:  firebase, firestore
n3dr
Nexus3 Disaster Recovery (N3DR) is a tool that is capable of downloading all artifacts from a Nexus3 server and to migrate them to another Nexus3 server. Note that some repository formats are not supported at the moment.
Stars: ✭ 110 (-64.17%)
Mutual labels:  backup, restore
backup-docker
A simple command line tool to backup and restore docker containers along with their volumes
Stars: ✭ 58 (-81.11%)
Mutual labels:  backup, restore
restique
A wrapper around restic with profiles
Stars: ✭ 43 (-85.99%)
Mutual labels:  backup, restore
PHP-Backuper
A framework which will help you to make (incremental) backups of your site.
Stars: ✭ 16 (-94.79%)
Mutual labels:  backup, restore
myhoard
MySQL Backup and Point-in-time Recovery service
Stars: ✭ 62 (-79.8%)
Mutual labels:  backup, restore
elcarro-oracle-operator
El Carro is a new project that offers a way to run Oracle databases in Kubernetes as a portable, open source, community driven, no vendor lock-in container orchestration system. El Carro provides a powerful declarative API for comprehensive and consistent configuration and deployment as well as for real-time operations and monitoring.
Stars: ✭ 204 (-33.55%)
Mutual labels:  backup, restore
cya
Easy to use snapshot and restore utility for any Linux (Unix) OS and filesystem powered by BASH
Stars: ✭ 73 (-76.22%)
Mutual labels:  backup, restore
Burry.sh
Cloud Native Infrastructure BackUp & RecoveRY
Stars: ✭ 260 (-15.31%)
Mutual labels:  backup, restore

firestore-export-import

GitHub version Build Status David badge

NPM package for backup and restore Firebase Firestore

You can export and import data from firestore with sub collection.

Installation

Install using npm.

npm install firestore-export-import
OR
yarn add firestore-export-import

Get Google Cloud Account Credentials from Firebase

You can Generate New Private Key from Project Settings from Firebase Console.

After that you need to copy the databaseURL for initiating the App.

Usage

You have to import this package in a JavaScript file and work from there.

Export data from firestore

You can export collection and sub collection from your data. The sub collection is optional.

Export options - OPTIONAL

// Export options
const options = {
  docsFromEachCollection: 10, // limit number of documents when exporting
  refs: ['refKey', 'deep.level.key'], // reference Path
}
// In your index.js

const { backup, backups, initializeApp } = require('firestore-export-import')
const serviceAccount = require('./serviceAccountKey.json')

// Initiate Firebase App
// appName is optional, you can omit it.
const appName = '[DEFAULT]'
initializeApp(serviceAccount, appName)

// Start exporting your data
backup('collection-name', options).then((data) =>
  console.log(JSON.stringify(data))
)

Sub collections will be added under 'subCollection' object.

Get all collections data

This is a suggestion from jcummings2 and leningsv

The ['collectionName1', 'collectionName2'] is OPTIONAL, you can remove this parameter to get all of the current collections in your firestore.

The result is an object of collection's data.

backups(['collectionName1', 'collectionName2']) // Array of collection's name is OPTIONAL
  .then((collections) => {
    // You can do whatever you want with collections
    console.log(JSON.stringify(collections))
  })

Export data with query

You are can back update based on query criteria. In this example, I am backing up all data from users collection, where name equals Dale Nguyen.

const queryByName = (collectionRef) =>
  collectionRef.where('name', '==', 'Dale Nguyen').get()

const users = await backup('users', {
  queryCollection: queryByName,
})

Import data to firestore (Predefined Document Id)

This code will help you to import data from a JSON file to firestore. You have two options:

  • Restore from a JSON file from your local machine
  • Restore from a JSON from a HTTP request

This will return a Promise<{status: boolean, message: string}>

Remember that, this action doesn't remove the collection. It will override or add new data to the collection. If you want to remove the current collection, you should do it from firebase console or using firebase firestore:delete

firebase firestore:delete [options] <<path>>

For local JSON

Usually the date, location & reference are not converted correctly when you backup the Firestore database. In order to import correctly, you have to pass to parameters for the options:

// Import options
const options = {
  dates: ['date1', 'date1.date2', 'date1.date2.date3'],
  geos: ['location', 'locations'],
  refs: ['refKey'],
}

If you don't want to specify dates, you can use another parameter in order to transform fields to date automatically.

// Import options with auto parse date
const options = {
  autoParseDates: true // use this one in stead of dates: [...]
  geos: ['location', 'locations'],
  refs: ['refKey'],
};

After that, the data will be converted based on their types.

// In your index.js
const { initializeApp, restore } = require('firestore-export-import')
const serviceAccount = require('./serviceAccountKey.json')

// Initiate Firebase App
// appName is optional, you can omit it.
const appName = '[DEFAULT]'
initializeApp(serviceAccount, databaseURL, appName)

// Start importing your data
// The array of date, location and reference fields are optional
restore('your-file-path.json', {
  dates: ['date1', 'date1.date2', 'date1.date2.date3'],
  geos: ['location', 'locations'],
  refs: ['refKey', 'arrayRef'],
})

For HTTP Request

import request from 'request-promise';
...
const backupData = await request('JSON-URL');
const status = await restore(JSON.parse(backupData), {
  dates: ['date'],
  geos: ['location']
});

The JSON is formated as below. The collection name is test. first-key and second-key are document ids.

{
  "test": {
    "first-key": {
      "website": "dalenguyen.me",
      "date": {
        "_seconds": 1534046400,
        "_nanoseconds": 0
      },
      "schedule": {
        "time": {
          "_seconds": 1534046400,
          "_nanoseconds": 0
        }
      },
      "three": {
        "level": {
          "time": {
            "_seconds": 1534046400,
            "_nanoseconds": 0
          }
        }
      },
      "custom": {
        "lastName": "Nguyen",
        "firstName": "Dale"
      },
      "location": {
        "_latitude": 49.290683,
        "_longitude": -123.133956
      },
      "locationNested": {
        "geopoint": {
          "_latitude": 49.290683,
          "_longitude": -123.133956
        }
      },
      "locations": [
        {
          "_latitude": 50.290683,
          "_longitude": -123.133956
        },
        {
          "_latitude": 51.290683,
          "_longitude": -123.133956
        }
      ],
      "email": "[email protected]",
      "secondRef": "test/second-key",
      "arrayRef": ["test/second-key", "test/second-key"],
      "nestedRef": {
        "secondRef": "test/second-key"
      },
      "subCollection": {
        "test/first-key/details": {
          "33J2A10u5902CXagoBP6": {
            "dogId": "2",
            "dogName": "hello"
          },
          "MSZTWEP7Lewx0Qr1Mu5s": {
            "dogName": "lala",
            "dogId": "2"
          }
        },
        "test/first-key/contacts": {
          "33J2A10u5902CXagoBP6": {
            "contactId": "1",
            "name": "Dale Nguyen"
          },
          "MSZTWEP7Lewx0Qr1Mu5s": {
            "contactId": "2",
            "name": "Yen Nguyen"
          }
        }
      }
    },
    "second-key": {
      "website": "google.com",
      "date": {
        "_seconds": 1534262435,
        "_nanoseconds": 0
      },
      "custom": {
        "lastName": "Potter",
        "firstName": "Harry"
      },
      "location": {
        "_latitude": 49.290683,
        "_longitude": -123.133956
      },
      "email": "[email protected]"
    }
  }
}

Import data to firestore (auto generate document id)

It works the same way as above. However the structure of JSON file is different. It's an array of documents.

// import-array-to-firestore.json
{
  "test": [
    {
      "name": "Dale Nguyen",
      "email": "[email protected]",
      "subCollection": {
        "details": [
          {
            "dogId": "2",
            "dogName": "hello"
          },
          {
            "dogName": "lala",
            "dogId": "2"
          }
        ]
      }
    },
    {
      "name": "Yen Nguyen",
      "email": "[email protected]"
    },
    {
      "name": "Harry Potter",
      "email": "[email protected]"
    }
  ]
}

Contributions

This project is based on firestore-import-export, feel free to report bugs and make feature requests in the Issue Tracker, fork and create pull requests!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].