将数据从 Firestore 导出到 GCS
Exporting data from Firestore to GCS
我尝试使用此代码段
将数据从 firestore 导出到 google 云存储
const functions = require('firebase-functions');
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1.FirestoreAdminClient();
const bucket = 'gs://BUCKET_NAME';
exports.scheduledFirestoreExport = functions.pubsub.schedule('every 24 hours').onRun(async() => {
const projectId = process.env.GCP_PROJECT || process.env.GCLOUD_PROJECT;
const databaseName = client.databasePath(projectId, '(default)');
const response = await client.exportDocuments({
name: databaseName,
outputUriPrefix: bucket,
collectionIds: [],
});
console.log(`Backup Successful :${response}`, {response});
//here I am trying to import the data to bigquery
});
我面临的问题是 client.exportDocuments 在 Google 云存储桶中创建文件之前几毫秒完成。因此,当我尝试访问它以进行导入时,它说没有这样的文件 exist.URL 是错误的。
对此有什么建议吗?
这是底层方法
databases.export documents.
response
是一个 Operation,它在 GCP 上可能是一个较长的 运行 进程。
您需要轮询(我认为没有办法订阅)操作端点,直到作业成功或失败。
如果完成,您就可以开始 BigQuery 作业了。
参见:Managing Export and Import operations
但是,这可能会超过 Cloud Function 的超时时间,因此在单个函数调用期间可能不应尝试。
您可能需要考虑创建另一个在导出完成后触发的进程。我没有这样做过。您可以创建一个由 GCS 事件触发的后台函数。我不知道。
我尝试使用此代码段
将数据从 firestore 导出到 google 云存储const functions = require('firebase-functions');
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1.FirestoreAdminClient();
const bucket = 'gs://BUCKET_NAME';
exports.scheduledFirestoreExport = functions.pubsub.schedule('every 24 hours').onRun(async() => {
const projectId = process.env.GCP_PROJECT || process.env.GCLOUD_PROJECT;
const databaseName = client.databasePath(projectId, '(default)');
const response = await client.exportDocuments({
name: databaseName,
outputUriPrefix: bucket,
collectionIds: [],
});
console.log(`Backup Successful :${response}`, {response});
//here I am trying to import the data to bigquery
});
我面临的问题是 client.exportDocuments 在 Google 云存储桶中创建文件之前几毫秒完成。因此,当我尝试访问它以进行导入时,它说没有这样的文件 exist.URL 是错误的。
对此有什么建议吗?
这是底层方法 databases.export documents.
response
是一个 Operation,它在 GCP 上可能是一个较长的 运行 进程。
您需要轮询(我认为没有办法订阅)操作端点,直到作业成功或失败。
如果完成,您就可以开始 BigQuery 作业了。
参见:Managing Export and Import operations
但是,这可能会超过 Cloud Function 的超时时间,因此在单个函数调用期间可能不应尝试。
您可能需要考虑创建另一个在导出完成后触发的进程。我没有这样做过。您可以创建一个由 GCS 事件触发的后台函数。我不知道。