Skip to content

Instantly share code, notes, and snippets.

@jeffwhelpley
Created January 22, 2020 15:45
Show Gist options
  • Save jeffwhelpley/86a5a65cde3a0d17b41abcd1c1af093d to your computer and use it in GitHub Desktop.
Save jeffwhelpley/86a5a65cde3a0d17b41abcd1c1af093d to your computer and use it in GitHub Desktop.
Generate Firestore backup
export async function exportData(projectId: string, clientEmail: string, privateKey: string) {
const timestamp = moment().format('YYYY-MM-DD_x');
const name = `projects/${projectId}/databases/(default)`;
const outputUriPrefix = `gs://${projectId}.appspot.com/backups/${timestamp}`;
const fsAdmin = new v1.FirestoreAdminClient({
projectId,
credentials: {
client_email: clientEmail,
private_key: privateKey
}
});
return new Promise((resolve, reject) => {
fsAdmin.exportDocuments({ name, outputUriPrefix }, (err: Error, operation: any) => {
if (err) {
reject(err);
} else {
console.log(`Long running operation: ${operation.name}`);
resolve(outputUriPrefix);
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment