Class: Google::Cloud::Bigtable::Backup

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/bigtable/backup.rb,
lib/google/cloud/bigtable/backup/job.rb,
lib/google/cloud/bigtable/backup/list.rb

Overview

Backup

A backup of a Cloud Bigtable table. See Cluster#create_backup, Cluster#backup and Cluster#backups.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
instance = bigtable.instance "my-instance"
cluster = instance.cluster "my-cluster"

backup = cluster.backup "my-backup"

# Update
backup.expire_time = Time.now + 60 * 60 * 7
backup.save

# Delete
backup.delete

Defined Under Namespace

Classes: Job, List

Instance Method Summary collapse

Instance Method Details

#backup_idString

The unique identifier for the backup.

Returns:

  • (String)


98
99
100
# File 'lib/google/cloud/bigtable/backup.rb', line 98

def backup_id
  @grpc.name.split("/")[7]
end

#cluster_idString

The unique identifier for the cluster to which the backup belongs.

Returns:

  • (String)


89
90
91
# File 'lib/google/cloud/bigtable/backup.rb', line 89

def cluster_id
  @grpc.name.split("/")[5]
end

#creating?Boolean

The backup is currently being created, and may be destroyed if the creation process encounters an error.

Returns:

  • (Boolean)


197
198
199
# File 'lib/google/cloud/bigtable/backup.rb', line 197

def creating?
  state == :CREATING
end

#deleteBoolean

Permanently deletes the backup.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
instance = bigtable.instance "my-instance"
cluster = instance.cluster "my-cluster"

backup = cluster.backup "my-backup"

backup.delete

Returns:

  • (Boolean)

    Returns true if the backup was deleted.



468
469
470
471
472
# File 'lib/google/cloud/bigtable/backup.rb', line 468

def delete
  ensure_service!
  service.delete_backup instance_id, cluster_id, backup_id
  true
end

#encryption_infoGoogle::Cloud::Bigtable::EncryptionInfo

The encryption information for the backup. See also Instance::ClusterMap#add.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
instance = bigtable.instance "my-instance"
cluster = instance.cluster "my-cluster"

backup = cluster.backup "my-backup"

encryption_info = backup.encryption_info
encryption_info.encryption_type #=> :GOOGLE_DEFAULT_ENCRYPTION

Returns:



227
228
229
# File 'lib/google/cloud/bigtable/backup.rb', line 227

def encryption_info
  EncryptionInfo.from_grpc @grpc.encryption_info
end

#end_timeTime

The time that the backup was finished. The row data in the backup will be no newer than this timestamp.

Returns:

  • (Time)


170
171
172
# File 'lib/google/cloud/bigtable/backup.rb', line 170

def end_time
  Convert.timestamp_to_time @grpc.end_time
end

#expire_timeTime

The expiration time of the backup, with microseconds granularity that must be at least 6 hours and at most 30 days from the time the request is received. Once the expire time has passed, Cloud Bigtable will delete the backup and free the resources used by the backup.

Returns:

  • (Time)


140
141
142
# File 'lib/google/cloud/bigtable/backup.rb', line 140

def expire_time
  Convert.timestamp_to_time @grpc.expire_time
end

#expire_time=(new_expire_time) ⇒ Object

Sets the expiration time of the backup, with microseconds granularity that must be at least 6 hours and at most 30 days from the time the request is received. Once the #expire_time has passed, Cloud Bigtable will delete the backup and free the resources used by the backup.

Parameters:

  • new_expire_time (Time)

    The new expiration time of the backup.



151
152
153
# File 'lib/google/cloud/bigtable/backup.rb', line 151

def expire_time= new_expire_time
  @grpc.expire_time = Convert.time_to_timestamp new_expire_time
end

#instance_idString

The unique identifier for the instance to which the backup belongs.

Returns:

  • (String)


80
81
82
# File 'lib/google/cloud/bigtable/backup.rb', line 80

def instance_id
  @grpc.name.split("/")[3]
end

#pathString

The unique name of the backup. Value in the form projects/<project>/instances/<instance>/clusters/<cluster>/backups/<backup>.

Returns:

  • (String)


108
109
110
# File 'lib/google/cloud/bigtable/backup.rb', line 108

def path
  @grpc.name
end

#policy {|policy| ... } ⇒ Policy

Gets the Cloud IAM access control policy for the backup.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
instance = bigtable.instance "my-instance"
cluster = instance.cluster "my-cluster"

backup = cluster.backup "my-backup"

policy = backup.policy

Update the policy by passing a block.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
instance = bigtable.instance "my-instance"
cluster = instance.cluster "my-cluster"

backup = cluster.backup "my-backup"

backup.policy do |p|
  p.add "roles/owner", "user:owner@example.com"
end # 2 API calls

Yields:

  • (policy)

    A block for updating the policy. The latest policy will be read from the Bigtable service and passed to the block. After the block completes, the modified policy will be written to the service.

Yield Parameters:

  • policy (Policy)

    the current Cloud IAM Policy for this backup.

Returns:

  • (Policy)

    The current Cloud IAM Policy for the backup.

See Also:



270
271
272
273
274
275
276
277
# File 'lib/google/cloud/bigtable/backup.rb', line 270

def policy
  ensure_service!
  grpc = service.get_backup_policy instance_id, cluster_id, backup_id
  policy = Policy.from_grpc grpc
  return policy unless block_given?
  yield policy
  update_policy policy
end

#project_idString

The unique identifier for the project to which the backup belongs.

Returns:

  • (String)


71
72
73
# File 'lib/google/cloud/bigtable/backup.rb', line 71

def project_id
  @grpc.name.split("/")[1]
end

#ready?Boolean

The backup has been successfully created and is ready to serve requests.

Returns:

  • (Boolean)


206
207
208
# File 'lib/google/cloud/bigtable/backup.rb', line 206

def ready?
  state == :READY
end

#reload!Google::Cloud::Bigtable::Backup

Reloads backup data.



447
448
449
450
# File 'lib/google/cloud/bigtable/backup.rb', line 447

def reload!
  @grpc = service.get_backup instance_id, cluster_id, backup_id
  self
end

#restore(table_id, instance: nil) ⇒ Google::Cloud::Bigtable::Table::RestoreJob

Creates a new table by restoring data from a completed backup. The new table may be created in an instance different than that of the backup.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
instance = bigtable.instance "my-instance"
cluster = instance.cluster "my-cluster"

backup = cluster.backup "my-backup"

job = backup.restore "my-new-table"

job.wait_until_done!
job.done? #=> true

if job.error?
  status = job.error
else
  table = job.table
  optimized = job.optimize_table_operation_name
end

Create the table in a different instance.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
instance = bigtable.instance "my-instance"
cluster = instance.cluster "my-cluster"

backup = cluster.backup "my-backup"

table_instance = bigtable.instance "my-other-instance"
job = backup.restore "my-new-table", instance: table_instance

job.wait_until_done!
job.done? #=> true

if job.error?
  status = job.error
else
  table = job.table
  optimized = job.optimize_table_operation_name
end

Parameters:

  • table_id (String)

    The table ID for the new table. This table must not yet exist. Required.

  • instance (Instance, String) (defaults to: nil)

    The instance or the ID of the instance for the new table, if different from the instance of the backup. Optional.

Returns:



405
406
407
408
409
410
411
412
413
# File 'lib/google/cloud/bigtable/backup.rb', line 405

def restore table_id, instance: nil
  table_instance_id = instance.respond_to?(:instance_id) ? instance.instance_id : instance
  grpc = service.restore_table table_id,
                               instance_id,
                               cluster_id,
                               backup_id,
                               table_instance_id: table_instance_id
  Table::RestoreJob.from_grpc grpc, service
end

#saveBoolean Also known as: update

Updates the backup.

expire_time is the only updatable field.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
instance = bigtable.instance "my-instance"
cluster = instance.cluster "my-cluster"

backup = cluster.backup "my-backup"

# Update
backup.expire_time = Time.now + 60 * 60 * 7
backup.save

Returns:

  • (Boolean)

    Returns true if the update succeeded.



435
436
437
438
439
# File 'lib/google/cloud/bigtable/backup.rb', line 435

def save
  ensure_service!
  @grpc = service.update_backup @grpc, [:expire_time]
  true
end

#size_bytesInteger

The size of the backup in bytes.

Returns:

  • (Integer)


179
180
181
# File 'lib/google/cloud/bigtable/backup.rb', line 179

def size_bytes
  @grpc.size_bytes
end

#source_table(perform_lookup: nil, view: nil) ⇒ Table

The table from which this backup was created.

Parameters:

  • perform_lookup (Boolean) (defaults to: nil)

    Creates table object without verifying that the table resource exists. Calls made on this object will raise errors if the table does not exist. Default value is false. Optional. Helps to reduce admin API calls.

  • view (Symbol) (defaults to: nil)

    Table view type. Default view type is :SCHEMA_VIEW. Valid view types are:

    • :NAME_ONLY - Only populates name.
    • :SCHEMA_VIEW - Only populates name and fields related to the table's schema.
    • :REPLICATION_VIEW - Only populates name and fields related to the table's replication state.
    • :FULL - Populates all fields.

Returns:



127
128
129
130
131
# File 'lib/google/cloud/bigtable/backup.rb', line 127

def source_table perform_lookup: nil, view: nil
  table = Table.from_path @grpc.source_table, service
  return table.reload! view: view if perform_lookup
  table
end

#start_timeTime

The time that the backup was started (i.e. approximately the time the CreateBackup request is received). The row data in this backup will be no older than this timestamp.

Returns:

  • (Time)


161
162
163
# File 'lib/google/cloud/bigtable/backup.rb', line 161

def start_time
  Convert.timestamp_to_time @grpc.start_time
end

#stateSymbol

The current state of the backup. Possible values are :CREATING and :READY.

Returns:

  • (Symbol)


188
189
190
# File 'lib/google/cloud/bigtable/backup.rb', line 188

def state
  @grpc.state
end

#test_iam_permissions(*permissions) ⇒ Array<String>

Tests the specified permissions against the Cloud IAM access control policy.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
instance = bigtable.instance "my-instance"
cluster = instance.cluster "my-cluster"

backup = cluster.backup "my-backup"

permissions = backup.test_iam_permissions(
  "bigtable.backups.delete",
  "bigtable.backups.get"
)
permissions.include? "bigtable.backups.delete" #=> false
permissions.include? "bigtable.backups.get" #=> true

Parameters:

  • permissions (String, Array<String>)

    permissions The set of permissions to check access for. Permissions with wildcards (such as * or bigtable.*) are not allowed. See Access Control.

Returns:

  • (Array<String>)

    The permissions that are configured for the policy.

See Also:



345
346
347
348
349
# File 'lib/google/cloud/bigtable/backup.rb', line 345

def test_iam_permissions *permissions
  ensure_service!
  grpc = service.test_backup_permissions instance_id, cluster_id, backup_id, permissions.flatten
  grpc.permissions.to_a
end

#update_policy(new_policy) ⇒ Policy Also known as: policy=

Updates the Cloud IAM access control policy for the backup. The policy should be read from #policy. See Policy for an explanation of the policy etag property and how to modify policies.

You can also update the policy by passing a block to #policy, which will call this method internally after the block completes.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
instance = bigtable.instance "my-instance"
cluster = instance.cluster "my-cluster"

backup = cluster.backup "my-backup"

policy = backup.policy
policy.add "roles/owner", "user:owner@example.com"
updated_policy = backup.update_policy policy

puts updated_policy.roles

Parameters:

  • new_policy (Policy)

    a new or modified Cloud IAM Policy for this backup

Returns:

  • (Policy)

    The policy returned by the API update operation.



308
309
310
311
312
# File 'lib/google/cloud/bigtable/backup.rb', line 308

def update_policy new_policy
  ensure_service!
  grpc = service.set_backup_policy instance_id, cluster_id, backup_id, new_policy.to_grpc
  Policy.from_grpc grpc
end