Class Backup (7.3.0)

The Backup class represents a Cloud Spanner backup.

Create a Backup object to interact with or create a Cloud Spanner backup or copy a backup.

Package

@google-cloud/spanner

Example


const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();
const instance = spanner.instance('my-instance');
const backup = instance.backup('my-backup');

* @example
const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();
const instance = spanner.instance('my-instance');
const sourceBackup = instance.backup('my-source-backup');
const copyBackup = instance.copyBackup('my-copy-backup', 'my-source-backup');

Constructors

(constructor)(instance, name, sourceName)

constructor(instance: Instance, name: string, sourceName?: string);

Constructs a new instance of the Backup class

Parameters
NameDescription
instance Instance
name string
sourceName string

Properties

formattedName_

formattedName_: string;

id

id: string;

instanceFormattedName_

instanceFormattedName_: string;

metadata

metadata?: databaseAdmin.spanner.admin.database.v1.IBackup;

request

request: BackupRequest;

resourceHeader_

resourceHeader_: {
        [k: string]: string;
    };

sourceName

sourceName: string | undefined;

Methods

create(options)

create(options: CreateBackupOptions | CopyBackupOptions): Promise<CreateBackupResponse> | Promise<CopyBackupResponse>;

Create a backup.

Backup#create

Parameter
NameDescription
options CreateBackupOptions | CopyBackupOptions

Parameters for creating a backup.

Returns
TypeDescription
Promise<CreateBackupResponse> | Promise<CopyBackupResponse>

{Promise

Example

const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();
const instance = spanner.instance('my-instance');
const oneDay = 1000 * 60 * 60 * 24;
const expireTime = Date.now() + oneDay;
const versionTime = Date.now() - oneDay;
const backup = instance.backup('my-backup');
const [, backupOperation] = await backup.create({
  databasePath: 'projects/my-project/instances/my-instance/databases/my-database',
  expireTime: expireTime,
  versionTime: versionTime,
  encryptionConfig: {
    encryptionType: 'CUSTOMER_MANAGED_ENCRYPTION',
    kmsKeyName: 'projects/my-project-id/my-region/keyRings/my-key-ring/cryptoKeys/my-key',
  },
});
// Await completion of the backup operation.
await backupOperation.promise();

create(options, callback)

create(options: CreateBackupOptions | CopyBackupOptions, callback: CreateBackupCallback | CopyBackupCallback): void;
Parameters
NameDescription
options CreateBackupOptions | CopyBackupOptions
callback CreateBackupCallback | CopyBackupCallback
Returns
TypeDescription
void

delete(gaxOptions)

delete(gaxOptions?: CallOptions): Promise<databaseAdmin.protobuf.IEmpty>;

Deletes a backup.

Backup#delete

Parameter
NameDescription
gaxOptions CallOptions

Request configuration options, See CallOptions for more details.

Returns
TypeDescription
Promise<databaseAdmin.protobuf.IEmpty>

{Promise

Example

const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();
const instance = spanner.instance('my-instance');
const backup = instance.backup('my-backup');
await backup.delete();

delete(callback)

delete(callback: DeleteCallback): void;
Parameter
NameDescription
callback DeleteCallback
Returns
TypeDescription
void

delete(gaxOptions, callback)

delete(gaxOptions: CallOptions, callback: DeleteCallback): void;
Parameters
NameDescription
gaxOptions CallOptions
callback DeleteCallback
Returns
TypeDescription
void

exists()

exists(): Promise<boolean>;

Checks whether the backup exists.

Returns
TypeDescription
Promise<boolean>

{Promise

Example

const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();
const instance = spanner.instance('my-instance');
const backup = instance.backup('my-backup');
const alreadyExists = await backup.exists();
console.log(`Does backup exist? ${alreadyExists}`);

exists(callback)

exists(callback: ExistsCallback): void;
Parameter
NameDescription
callback ExistsCallback
Returns
TypeDescription
void

formatName_(instanceName, name)

static formatName_(instanceName: string, name: string): string;

Format the backup name to include the instance name.

Parameters
NameDescription
instanceName string

The formatted instance name.

name string

The table name.

Returns
TypeDescription
string

{string}

Example

Backup.formatName_(
  'projects/grape-spaceship-123/instances/my-instance',
  'my-backup'
);
// 'projects/grape-spaceship-123/instances/my-instance/backups/my-backup'

getExpireTime()

getExpireTime(): Promise<PreciseDate | undefined>;

Retrieves the expiry time of the backup.

Returns
TypeDescription
Promise<PreciseDate | undefined>

{Promise<external:PreciseDate>} When resolved, contains the current expire time of the backup if it exists.

Example

const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();
const instance = spanner.instance('my-instance');
const backup = instance.backup('my-backup');
const expireTime = await backup.getExpireTime();
console.log(`Backup expires on ${expireTime.toISOString()}`);

getExpireTime(callback)

getExpireTime(callback: GetExpireTimeCallback): void;
Parameter
NameDescription
callback GetExpireTimeCallback
Returns
TypeDescription
void

getMetadata(gaxOptions)

getMetadata(gaxOptions?: CallOptions): Promise<GetMetadataResponse>;

Retrieves backup's metadata.

Parameter
NameDescription
gaxOptions CallOptions

Request configuration options, See CallOptions for more details.

Returns
TypeDescription
Promise<GetMetadataResponse>

{Promise

Example

const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();
const instance = spanner.instance('my-instance');
const backup = instance.backup('my-backup');
const [backupInfo] = await backup.getMetadata();
console.log(`${backupInfo.name}: size=${backupInfo.sizeBytes}`);

getMetadata(callback)

getMetadata(callback: GetMetadataCallback): void;
Parameter
NameDescription
callback GetMetadataCallback
Returns
TypeDescription
void

getMetadata(gaxOptions, callback)

getMetadata(gaxOptions: CallOptions, callback: GetMetadataCallback): void;
Parameters
NameDescription
gaxOptions CallOptions
callback GetMetadataCallback
Returns
TypeDescription
void

getState()

getState(): Promise<EnumKey<typeof databaseAdmin.spanner.admin.database.v1.Backup.State> | undefined | null>;

Retrieves the state of the backup.

The backup state indicates if the backup has completed.

Returns
TypeDescription
Promise<EnumKey<typeof databaseAdmin.spanner.admin.database.v1.Backup.State> | undefined | null>

{Promise<EnumKey<typeof, databaseAdmin.spanner.admin.database.v1.Backup.State> | undefined>} When resolved, contains the current state of the backup if it exists.

Example

const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();
const instance = spanner.instance('my-instance');
const backup = instance.backup('my-backup');
const state = await backup.getState();
const backupCompleted = (state === 'READY');

getState(callback)

getState(callback: GetStateCallback): void;
Parameter
NameDescription
callback GetStateCallback
Returns
TypeDescription
void

updateExpireTime(expireTime)

updateExpireTime(expireTime: string | number | p.ITimestamp | PreciseDate): Promise<databaseAdmin.spanner.admin.database.v1.IBackup>;

Sets the expiry time of a backup.

Parameter
NameDescription
expireTime string | number | common.ITimestamp | PreciseDate

The expiry time to update with.

Returns
TypeDescription
Promise<databaseAdmin.spanner.admin.database.v1.IBackup>

{Promise<google.spanner.admin.database.v1.IBackup>} When resolved, the backup's expire time will have been updated.

Example

const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner();
const instance = spanner.instance('my-instance');
const backup = instance.backup('my-backup');
const oneDay = 1000 * 60 * 60 * 24;
const newExpireTime = Spanner.timestamp(Date.now() + oneDay);
await backup.updateExpireTime(newExpireTime);

updateExpireTime(expireTime, gaxOptions)

updateExpireTime(expireTime: string | number | p.ITimestamp | PreciseDate, gaxOptions?: CallOptions): Promise<databaseAdmin.spanner.admin.database.v1.IBackup>;
Parameters
NameDescription
expireTime string | number | common.ITimestamp | PreciseDate
gaxOptions CallOptions
Returns
TypeDescription
Promise<databaseAdmin.spanner.admin.database.v1.IBackup>

updateExpireTime(expireTime, callback)

updateExpireTime(expireTime: string | number | p.ITimestamp | PreciseDate, callback: UpdateExpireTimeCallback): void;
Parameters
NameDescription
expireTime string | number | common.ITimestamp | PreciseDate
callback UpdateExpireTimeCallback
Returns
TypeDescription
void

updateExpireTime(expireTime, gaxOptions, callback)

updateExpireTime(expireTime: string | number | p.ITimestamp | PreciseDate, gaxOptions: CallOptions, callback: UpdateExpireTimeCallback): void;
Parameters
NameDescription
expireTime string | number | common.ITimestamp | PreciseDate
gaxOptions CallOptions
callback UpdateExpireTimeCallback
Returns
TypeDescription
void