백업 표시

지정된 클러스터 및 테이블의 백업을 나열합니다.

코드 샘플

Node.js

Bigtable용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Bigtable 클라이언트 라이브러리를 참조하세요.

Bigtable에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

'use strict';

const {BigtableTableAdminClient} = require('@google-cloud/bigtable').v2;
const {status} = require('@grpc/grpc-js');

const client = new BigtableTableAdminClient();

/**
 * Lists Bigtable backups in a specified cluster or across all clusters in an instance.
 *
 * @param {string} projectId - The Google Cloud project ID.
 * @param {string} instanceId - The ID of the Bigtable instance hosting the cluster.
 * @param {string} clusterId - The ID of the Bigtable cluster, or '-' to list backups across all clusters in the instance.
 */
async function listBackups(projectId, instanceId, clusterId) {
  try {
    const parent = `projects/${projectId}/instances/${instanceId}/clusters/${clusterId}`;
    const request = {
      parent,
    };

    const [backups] = await client.listBackups(request);
    console.log(`Listing backups in ${parent}:`);
    for (const backup of backups) {
      console.log(`- Backup name: ${backup.name}`);
      console.log(`  Source table: ${backup.sourceTable}`);
      console.log(`  State: ${backup.state}`);
      console.log(`  Size in bytes: ${backup.sizeBytes}`);
    }
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.error(`Resource not found: ${err.message}`);
    } else if (err.code === status.PERMISSION_DENIED) {
      console.error(`Permission denied: ${err.message}`);
    } else if (err.code !== undefined) {
      console.error(`API error code ${err.code}: ${err.message}`);
    } else {
      throw err;
    }
  }
}

module.exports = {listBackups};

Python

Bigtable용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Bigtable 클라이언트 라이브러리를 참조하세요.

Bigtable에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

import google.api_core.exceptions
from google.cloud import bigtable_admin_v2


def list_backups(project_id: str, instance_id: str, cluster_id: str) -> None:
    """Lists Bigtable backups in a cluster or across all clusters in an instance.

    Args:
        project_id: The Google Cloud project ID (for example, 'example-project-id').
        instance_id: The ID of the Bigtable instance (for example, 'example-instance-id').
        cluster_id: The ID of the Bigtable cluster, or '-' to list backups across all clusters.
    """
    client = bigtable_admin_v2.BigtableTableAdminClient()
    parent = f"projects/{project_id}/instances/{instance_id}/clusters/{cluster_id}"

    try:
        response = client.list_backups(parent=parent)
        for backup in response:
            print(f"Backup name: {backup.name}")
    except google.api_core.exceptions.GoogleAPICallError as error:
        print(f"API call failed: {error}")

다음 단계

다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저 참조하기