הצגת רשימת הגיבויים

מציגה רשימה של גיבויים מאשכול ומטבלה ספציפיים.

דוגמת קוד

Node.js

במאמר ספריות הלקוח של Bigtable מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Bigtable.

כדי לבצע אימות ב-Bigtable, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

'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, צריך להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

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 .