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)


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

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

#cluster_idString

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

Returns:

  • (String)


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

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)


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

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.



296
297
298
299
300
# File 'lib/google/cloud/bigtable/backup.rb', line 296

def delete
  ensure_service!
  service.delete_backup instance_id, cluster_id, backup_id
  true
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)


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

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)


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

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.



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

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)


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

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)


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

def path
  @grpc.name
end

#project_idString

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

Returns:

  • (String)


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

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

#ready?Boolean

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

Returns:

  • (Boolean)


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

def ready?
  state == :READY
end

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

Reloads backup data.



275
276
277
278
# File 'lib/google/cloud/bigtable/backup.rb', line 275

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

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

Creates a new table by restoring from a completed 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

Parameters:

  • table_id (String)

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

Returns:



238
239
240
241
# File 'lib/google/cloud/bigtable/backup.rb', line 238

def restore table_id
  grpc = service.restore_table table_id, instance_id, cluster_id, backup_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.



263
264
265
266
267
# File 'lib/google/cloud/bigtable/backup.rb', line 263

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

#size_bytesInteger

The size of the backup in bytes.

Returns:

  • (Integer)


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

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:



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

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)


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

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)


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

def state
  @grpc.state
end