I'm trying to schedule a firebase auth:export into a bucket using pubsub. My purpose is to have a backup of auth (the output of firebase auth:export is perfectly fine for my purposes) every day.
This is the pubsub I tried:
const functions = require('firebase-functions')
const exec = require("child_process").exec
const datetime = new Date();
const formattedDate = datetime.toISOString().slice(0,10)
const commandString = `firebase auth:export auth_export_${formattedDate}.json --format=JSON && \
gsutil -m cp -r auth_export_${formattedDate}.json gs://backup_firebase_auth_daily && \
rm auth_export_${formattedDate}.json`
exports.scheduledFirebaseAuthExport = functions.pubsub
.schedule('every 24 hours')
.onRun(() => {
return exec(commandString, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
process.exit();
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
process.exit();
return;
}
console.log(stdout);
process.exit();
});
});
but I'm getting following error:
/bin/sh: 1: firebase: not found
I'm assuming this is because I cannot run command line scripts in whatever environment the pubsub is run.
Any other ways to get backup of firebase auth using Google Cloud API’s or firebase would be welcome.