Import and export firestore to/from a pouchdb
There are other tools that let you backup firestore but they seem to download your entire firestore into memory. This is problematic because it is very easy to run out of heap memory during the backup.
This tool currently does not support:
- subcollections
- document references
- geopoint, firestore date data
These might be added later if there's enough people wanting these features. I didn't use them for my firestore instance so I decided to skip them for now.
const admin = require("firebase-admin")
const { Firepouch } = require("firepouch")
function getAdminApp() {
const { CLIENT_EMAIL, PROJECT_ID, PRIVATE_KEY, DATABASE_URL, STORAGE_BUCKET } = process.env
const serviceAccount = {
clientEmail: CLIENT_EMAIL,
projectId: PROJECT_ID,
privateKey: (PRIVATE_KEY || "").replace(/\\n/g, "\n")
}
const adminApp = admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: DATABASE_URL,
storageBucket: STORAGE_BUCKET
})
return adminApp
}
async function start() {
const name = "my-backup"
const firepouch = new Firepouch({ app: getAdminApp() })
await firepouch.createBackup({ name })
}
start()
const admin = require("firebase-admin")
const { Firepouch } = require("firepouch")
const { getAdminApp } = require("./getAdminApp")
async function start() {
const name = "my-backup"
const firepouch = new Firepouch({ app: getAdminApp() })
await firepouch.restoreBackup({ name })
}
start()
const admin = require("firebase-admin")
const { Firepouch } = require("firepouch")
const { getAdminApp } = require("./getAdminApp")
async function start() {
const name = "my-backup"
const firepouch = new Firepouch({ app: getAdminApp() })
// create a backupArchive & upload it to cloud storage
await firepouch.createBackupToCloudStorage({ path: "backups/my-backup.zip" })
// restore from cloud storage
await firepouch.restoreBackupFromCloudStorage({ path: "backups/my-backup.zip" })
}
start()
const admin = require("firebase-admin")
const { Firepouch } = require("firepouch")
const { getAdminApp } = require("./getAdminApp")
async function start() {
const name = "my-backup"
const firepouch = new Firepouch({ app: getAdminApp() })
// create a backupArchive
await firepouch.createBackupToArchive({ dest: "my-backup.zip" })
// restore from archive
await firepouch.restoreFromArchive({ name: "my-backup.zip" })
}
start()