For you to achieve that, it should not be something very complicated, so I hope I can help you.
To perform this, I will follow the example explained in the article Backup Firestore data to storage bucket on a schedule in GCP - which you can follow completely, in case you are interested - focusings in the upload from Firestore to Cloud Storage. I will explain which parts to use and how to use them, to achieve your agoal
Once you created your Cloud Storage bucket - it should have Multi-regional
and Nearline
configured in the settings - you need to use the below code as indicated after them.
index.js
file:
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1.FirestoreAdminClient();
// Replace BUCKET_NAME
const bucket = 'gs://<bucket-id>'
exports.scheduledFirestoreBackup = (event, context) => {
const databaseName = client.databasePath(
process.env.GCLOUD_PROJECT,
'(default)'
);
return client
.exportDocuments({
name: databaseName,
outputUriPrefix: bucket,
// Leave collectionIds empty to export all collections
// or define a list of collection IDs:
// collectionIds: ['users', 'posts']
collectionIds: [],
})
.then(responses => {
const response = responses[0];
console.log(`Operation Name: ${response['name']}`);
return response;
})
.catch(err => {
console.error(err);
});
};
package.json
file:
{
"dependencies": {
"@google-cloud/firestore": "^1.3.0"
}
}
These files should be created, with the configuration in the Cloud Function as following: an unique name; Cloud Sub/Pub
as trigger; topic name similar or equal to initiateFirestoreBackup
; using Node.js, source will be the above files written and function to execute scheduledFirestoreBackup
.
The above codes should be enough for you to export from your Firestore to your Cloud Storage, due to the fact that it will be getting all your collections - or you can define specifics - and sending to the bucket you already created.
Besides that, in case you want more information on uploading files to Cloud Storage using Cloud Functions, you can check here as well: Uploading files from Firebase Cloud Functions to Cloud Storage
Let me know if the information helped you!