Class Backup (5.15.2)

The Backup class represents a Cloud Spanner backup.

Create a Backup object to interact with or create a Cloud Spanner 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');

Constructors

(constructor)(instance, name)

constructor(instance: Instance, name: string);

Constructs a new instance of the Backup class

Parameters
NameDescription
instance Instance
name 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;
    };

Methods

create(options)

create(options: CreateBackupOptions): Promise<CreateBackupResponse>;

Create a backup.

Backup#create

Parameter
NameDescription
options CreateBackupOptions

Parameters for creating a backup.

Returns
TypeDescription
Promise<CreateBackupResponse>

{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, callback: CreateBackupCallback): void;
Parameters
NameDescription
options CreateBackupOptions
callback CreateBackupCallback
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<google.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 google.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<google.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<google.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