Backup

Backup

Interact with backups like get detailed information from BigTable, create a backup, or restore a backup to a table.

Constructor

new Backup(cluster, name)

Parameters:
Name Type Description
cluster Cluster

The parent instance of this backup.

name string

Name of the backup.

Example
const {Bigtable} = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
const cluster = instance.cluster('my-cluster');
const backup = cluster.backup('my-backup');

Members

(readonly) endDate

A Date-compatible PreciseDate representing the time that the backup was finished.

(readonly) expireDate

A Date-compatible PreciseDate representing the expiration time of this backup.

(readonly) startDate

A Date-compatible PreciseDate representing the time that this backup was started.

Methods

create(config, callbackopt) → {void|Promise.<CreateBackupResponse>}

Starts creating a new Cloud Bigtable Backup.

The returned long-running operation can be used to track creation of the backup. Cancelling the returned operation will stop the creation and delete the backup.

Parameters:
Name Type Attributes Description
config CreateBackupConfig

Configuration object.

Properties
Name Type Attributes Description
expireTime BackupTimestamp

When the backup will be automatically deleted.

table string | Table

Table to create the backup from.

gaxOptions CallOptions <optional>

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html.

callback CreateBackupCallback <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

backup Backup

The newly created Backup.

operation Operation

An operation object that can be used to check the status of the request.

apiResponse object

The full API response.

Example
  const {Bigtable} = require('@google-cloud/bigtable');
  const bigtable = new Bigtable();

  async function createBackup() {
    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // const instanceId = 'YOUR_INSTANCE_ID';
    // const tableId = 'YOUR_TABLE_ID';
    // const clusterId = 'YOUR_CLUSTER_ID';
    // const backupId = 'YOUR_BACKUP_ID';

    const instance = bigtable.instance(instanceId);
    const cluster = instance.cluster(clusterId);

    const [backup, operation] = await cluster.createBackup(backupId, {
      table: tableId,
      expireTime: new Date(Date.now() + 7 * 60 * 60 * 1000), // 7 hours from now
    });

    console.log('Started a table backup operation.');
    await operation.promise();

    console.log(`Backup "${backup.id}" is now ready for use.`);
  }

  await createBackup();

delete(gaxOptionsOrCallbackopt, callbackopt) → {void|Promise.<DeleteBackupResponse>}

Deletes this pending or completed Cloud Bigtable backup.

Parameters:
Name Type Attributes Description
gaxOptionsOrCallback CallOptions | DeleteBackupCallback <optional>
callback DeleteBackupCallback <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

apiResponse object

The full API response.

Example
  const {Bigtable} = require('@google-cloud/bigtable');
  const bigtable = new Bigtable();

  async function deleteBackup() {
    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // const instanceId = 'YOUR_INSTANCE_ID';
    // const tableId = 'YOUR_TABLE_ID';
    // const clusterId = 'YOUR_CLUSTER_ID';
    // const backupId = 'YOUR_BACKUP_ID';
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);
    const cluster = table.cluster(clusterId);
    const backup = cluster.backup(backupId);

    await backup.delete();
    console.log(`Backup ${backupId} was deleted successfully.`);
  }

  await deleteBackup();

exists(gaxOptionsopt, callback)

Check if a backup exists.

Parameters:
Name Type Attributes Description
gaxOptions object <optional>

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html.

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

exists boolean

Whether the backup exists or not.

get(gaxOptionsopt, callback)

Get a backup if it exists.

Parameters:
Name Type Attributes Description
gaxOptions object <optional>

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html.

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

backup Backup

The Backup instance.

apiResponse object

The full API response.

Example
  const {Bigtable} = require('@google-cloud/bigtable');
  const bigtable = new Bigtable();

  async function getBackup() {
    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // const instanceId = 'YOUR_INSTANCE_ID';
    // const tableId = 'YOUR_TABLE_ID';
    // const clusterId = 'YOUR_CLUSTER_ID';
    // const backupId = 'YOUR_BACKUP_ID';
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);
    const cluster = table.cluster(clusterId);

    // Create a reference to the backup before performing operations on it.
    const backup = cluster.backup(backupId);

    // Get the backup's metadata, with information such as when it will expire
    // and how big it is.
    const [metadata] = await backup.getMetadata();
    console.log(`The backup is ${metadata.sizeBytes} bytes.`);

    // Time properties have Date helpers to convert to a `PreciseDate`.
    console.log(
      `The backup will auto-delete at ${metadata.expireDate.toISOString()}`
    );
    console.log(
      `The backup finished being created at ${metadata.endTime.toISOString()}`
    );
  }

  await getBackup();

getMetadata(gaxOptionsopt, callback)

Get a backup if it exists.

Parameters:
Name Type Attributes Description
gaxOptions object <optional>

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html.

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

metadata object

The metadata.

apiResponse object

The full API response.

Example
  const {Bigtable} = require('@google-cloud/bigtable');
  const bigtable = new Bigtable();

  async function getBackup() {
    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // const instanceId = 'YOUR_INSTANCE_ID';
    // const tableId = 'YOUR_TABLE_ID';
    // const clusterId = 'YOUR_CLUSTER_ID';
    // const backupId = 'YOUR_BACKUP_ID';
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);
    const cluster = table.cluster(clusterId);

    // Create a reference to the backup before performing operations on it.
    const backup = cluster.backup(backupId);

    // Get the backup's metadata, with information such as when it will expire
    // and how big it is.
    const [metadata] = await backup.getMetadata();
    console.log(`The backup is ${metadata.sizeBytes} bytes.`);

    // Time properties have Date helpers to convert to a `PreciseDate`.
    console.log(
      `The backup will auto-delete at ${metadata.expireDate.toISOString()}`
    );
    console.log(
      `The backup finished being created at ${metadata.endTime.toISOString()}`
    );
  }

  await getBackup();

restore(tableId, gaxOptionsOrCallbackopt, callbackopt) → {void|Promise.<RestoreTableResponse>}

Create a new table by restoring from this completed backup.

The new table must be in the same instance as the instance containing the backup. The returned long-running operation can be used to track the progress of the operation, and to cancel it.

Parameters:
Name Type Attributes Description
tableId string

The id of the table to create and restore to. This table must not already exist.

gaxOptionsOrCallback CallOptions | RestoreTableCallback <optional>
callback RestoreTableCallback <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

table Table

The newly created Table.

operation Operation

An operation object that can be used to check the status of the request.

apiResponse object

The full API response.

Example

include:samples/backups.restore.js

region_tag:bigtable_restore_backup

setMetadata(metadata, gaxOptionsOrCallbackopt, callbackopt) → {void|Promise.<BackupSetMetadataResponse>}

Updates this pending or completed Cloud Bigtable Backup.

Parameters:
Name Type Attributes Description
metadata ModifiableBackupFields

The fields to be updated.

gaxOptionsOrCallback CallOptions | BackupSetMetadataCallback <optional>
callback BackupSetMetadataCallback <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

callback.apiResponse object

The full API response.

Example
  const {Bigtable} = require('@google-cloud/bigtable');
  const bigtable = new Bigtable();

  async function updateBackup() {
    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // const instanceId = 'YOUR_INSTANCE_ID';
    // const tableId = 'YOUR_TABLE_ID';
    // const clusterId = 'YOUR_CLUSTER_ID';
    // const backupId = 'YOUR_BACKUP_ID';
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);
    const cluster = table.cluster(clusterId);
    const backup = cluster.backup(backupId);

    // Extend a backup's life by updating its expiry date.
    const [metadata] = await backup.setMetadata({
      expireTime: new Date(Date.now() + 24 * 60 * 60 * 1000), // 24 hours
    });
    console.log(`The backup will now auto-delete at ${metadata.expireDate}.`);
  }

  await updateBackup();