将Firestore数据库还原到上一次导出中找到的确切状态

问题描述 投票:0回答:1

我具有以下https可调用的云函数,该函数可导入备份中找到的所有文档。


    const path = `${timestamp}`;

    const projectId = await auth.getProjectId();

    // we change the action for importDocuments
    const url = `https://firestore.googleapis.com/v1/projects/${projectId}/databases/(default):importDocuments`;
    const backup_route = `gs://${BUCKET_NAME}/${path}`;
    return client.request({
        url,
        method: 'POST',
        data: {
            inputUriPrefix: backup_route,
        }
    }).then(async (res: any) => {
        console.log(`Began backup restore from folder ${backup_route}`);
        return Promise.resolve(res.data.name);
    }).catch(async (e) => {
        return Promise.reject(new functions.https.HttpsError('internal', e.message));
    })

我使用此功能将数据库还原到导出时的确切状态。问题在于,导入操作不会影响在导出中找不到的文档。因此,导出后添加的新文档将保留在数据库中。

documentation中的以下引言解释了此行为:

如果数据库中的文档不受导入影响,则导入后它将保留在数据库中。

在开始导入操作之前删除整个数据库是我唯一的选择吗?我找不到可以实现所需性能的操作。

firebase google-cloud-firestore google-cloud-functions
1个回答
0
投票

提供的导出机制并不代表大多数人所说的“备份”,一旦数据丢失,该备份将被“恢复”。这只是出口。这对于将数据库副本导入其他位置很有用,从而使跨环境复制数据库变得容易,而无需编写大量代码。

如果要从导入中获得数据库的新副本而没有其他文档,则必须在导入之前清除其中的所有内容。

© www.soinside.com 2019 - 2024. All rights reserved.