建立備份

建立資料表備份。

程式碼範例

Python

如要瞭解如何安裝及使用 Bigtable 的用戶端程式庫,請參閱「Bigtable 用戶端程式庫」。

如要向 Bigtable 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

import datetime

from google.cloud import bigtable_admin_v2

client = bigtable_admin_v2.BigtableTableAdminClient()
cluster_path = client.cluster_path(project_id, instance_id, cluster_id)
table_path = client.table_path(project_id, instance_id, table_id)

# Backups must expire between 6 hours and 90 days after they are created
expire_time = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(
    hours=8
)
print("Creating backup {} of table {}...".format(backup_id, table_id))
operation = client.create_backup(
    parent=cluster_path,
    backup_id=backup_id,
    backup=bigtable_admin_v2.Backup(
        source_table=table_path, expire_time=expire_time
    ),
)
backup = operation.result()
print("Created backup {}.".format(backup.name.split("/")[-1]))

後續步驟

如要搜尋及篩選其他 Google Cloud 產品的程式碼範例,請參閱Google Cloud 範例瀏覽工具。