Create a backup

Creates a table backup.

Code sample

Python

To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

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]))

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.