BigQuery 项目的克隆/备份

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

如何将包含 Google BigQuery 中数据集的项目备份到另一个 GCS 存储桶?使用 Python 脚本来完成此任务是否可行?如何自动化该过程?

只是想收集想法来实施灾难恢复。将项目克隆到另一个 GCP 存储桶中

数据结构如下:

 Project -> dataset -> table
                    -> table
                    -> ...

         -> dataset -> table
                    -> table
                    -> ...
         -> ...
google-bigquery google-cloud-storage disaster-recovery
1个回答
0
投票
  1. 考虑灾难恢复固然很棒,但重要的是要知道 Google BigQuery 提供了开箱即用的灾难系统。您存储在某个区域中的任何数据都会自动复制到该区域内的另一个区域,因此,如果一个位置发生故障,另一个位置应该为您提供所需的服务。当使用他们的“多区域”方法时,这一点尤其强大,您基本上只选择“美国” - 因此可以将其复制到更远的位置。查看更多信息这里
  2. 但是,Google 自己建议创建某种灾难恢复计划。建议的选项之一实际上是将数据导出到 GCS 中的另一个区域 - 参见此处

现在进入下一部分 - 绝对可以创建一个执行此备份的 python 脚本。您甚至可以按计划使用 Google Cloud 服务帐户将其作为 Google Cloud Function 运行,它会自动将您的整个数据集/项目复制到您决定执行此操作的任何位置。

您应该使用

google-bigquery
python 包,这将允许您连接到 bigquery 并创建导出作业。

您可以参考Google文档提供的示例代码来开始使用:

# from google.cloud import bigquery
# client = bigquery.Client()
# bucket_name = 'my-bucket'
project = "bigquery-public-data"
dataset_id = "samples"
table_id = "shakespeare"

destination_uri = "gs://{}/{}".format(bucket_name, "shakespeare.csv")
dataset_ref = bigquery.DatasetReference(project, dataset_id)
table_ref = dataset_ref.table(table_id)

extract_job = client.extract_table(
    table_ref,
    destination_uri,
    # Location must match that of the source table.
    location="US",
)  # API request
extract_job.result()  # Waits for job to complete.

print(
    "Exported {}:{}.{} to {}".format(project, dataset_id, table_id, destination_uri)
)
© www.soinside.com 2019 - 2024. All rights reserved.