Backup your Firestore data with our step-by-step guide. Set up Google Cloud and Firebase, configure Node.js exports, automate backups, and verify your data.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Set Up Your Google Cloud Project
Step 2: Enable Cloud Firestore and Cloud Storage in Firebase
Step 3: Configure Firestore Exports
Step 4: Set Up Firebase Admin SDK in Your Server Environment
Install Firebase Admin SDK in your project directory using npm or yarn:
npm install firebase-admin
Initialize Firebase Admin SDK in your script:
const admin = require('firebase-admin');
admin.initializeApp({
credential: admin.credential.applicationDefault(), // Ensure you have set the GOOGLE_APPLICATION_CREDENTIALS environment variable
databaseURL: 'YOUR_FIREBASE_DATABASE\_URL'
});
const firestore = admin.firestore();
Step 5: Create Firestore Export Script
const { exec } = require('child\_process');
const projectId = 'YOUR_PROJECT_ID';
const bucket = 'YOUR_BUCKET_NAME';
const currentTime = new Date().toISOString();
const collectionGroupIds = ['YOUR_COLLECTION_IDS'];
const command = `gcloud firestore export gs://${bucket}/${currentTime} --collection-ids=${collectionGroupIds.join(',')} --project=${projectId}`;
exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
if (stderr) {
console.error(`Standard Error: ${stderr}`);
return;
}
console.log(`Standard Output: ${stdout}`);
});
Step 6: Schedule Automated Backups
For example, using cron:
0 2 _ _ * /path/to/node /path/to/your/export-script.js >/dev/null 2>&1
This runs the script every day at 2 AM.
Step 7: Verify Backup Data
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.