Created
January 22, 2020 15:45
-
-
Save jeffwhelpley/86a5a65cde3a0d17b41abcd1c1af093d to your computer and use it in GitHub Desktop.
Generate Firestore backup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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