You are viewing documentation for version 1 of the AWS SDK for Ruby. Version 2 documentation can be found here.

Class: AWS::EC2::Snapshot

Inherits:
Resource
  • Object
show all
Includes:
HasPermissions, TaggedItem
Defined in:
lib/aws/ec2/snapshot.rb

Overview

Represents an Amazon EBS snapshot.

Examples:

Taking a snapshot from a volume

snapshot = volume.create_snapshot("Database Backup 12/21/2010")
sleep 1 until [:completed, :error].include?(snapshot.status)

Managing snapshot permissions

unless snapshot.public?
  snapshot.permissions.add("12345678901")
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HasPermissions

#permissions, #private?, #public=, #public?

Methods included from TaggedItem

#add_tag, #clear_tags, #tags

Instance Attribute Details

#descriptionString (readonly)

The description of the snapshot provided at snapshot initiation.

Returns:

  • (String)

    the current value of description



52
53
54
# File 'lib/aws/ec2/snapshot.rb', line 52

def description
  @description
end

#idString (readonly)

Returns the snapshot's ID.

Returns:

  • (String)

    Returns the snapshot's ID.



64
65
66
# File 'lib/aws/ec2/snapshot.rb', line 64

def id
  @id
end

#owner_idString (readonly)

The AWS account ID of the snapshot owner.

Returns:

  • (String)

    the current value of owner_id



52
53
54
# File 'lib/aws/ec2/snapshot.rb', line 52

def owner_id
  @owner_id
end

#progressInteger (readonly)

The progress of the snapshot as a percentage.

Returns:

  • (Integer)

    the current value of progress



52
53
54
# File 'lib/aws/ec2/snapshot.rb', line 52

def progress
  @progress
end

#start_timeTime (readonly)

The time at which the snapshot was initiated.

Returns:

  • (Time)

    the current value of start_time



52
53
54
# File 'lib/aws/ec2/snapshot.rb', line 52

def start_time
  @start_time
end

#statusSymbol (readonly)

The status of the snapshot. Possible values:

  • :pending
  • :completed
  • :error

Returns:

  • (Symbol)

    the current value of status



52
53
54
# File 'lib/aws/ec2/snapshot.rb', line 52

def status
  @status
end

#volume_idString (readonly)

The ID of the volume this snapshot was created from.

Returns:

  • (String)

    the current value of volume_id



52
53
54
# File 'lib/aws/ec2/snapshot.rb', line 52

def volume_id
  @volume_id
end

#volume_sizeInteger (readonly)

The size of the volume from which the snapshot was created.

Returns:

  • (Integer)

    the current value of volume_size



52
53
54
# File 'lib/aws/ec2/snapshot.rb', line 52

def volume_size
  @volume_size
end

Instance Method Details

#create_volume(availability_zone, options = {}) ⇒ Volume

Creates a volume from the snapshot.

Parameters:

  • availability_zone (AvailabilityZone or String)

    The Availability Zone in which to create the new volume. See AWS::EC2#availability_zones for how to get a list of availability zones.

  • options (Hash) (defaults to: {})

    Additional options for creating the volume

Options Hash (options):

  • size (Integer)

    The desired size (in gigabytes) for the volume.

Returns:

  • (Volume)

    The newly created volume



114
115
116
117
118
119
120
# File 'lib/aws/ec2/snapshot.rb', line 114

def create_volume availability_zone, options = {}
  volumes = VolumeCollection.new(:config => config)
  volumes.create(options.merge(
    :availability_zone => availability_zone,
    :snapshot => self
  ))
end

#deletenil

Deletes the snapshot.

Returns:

  • (nil)


96
97
98
99
# File 'lib/aws/ec2/snapshot.rb', line 96

def delete
  client.delete_snapshot(:snapshot_id => id)
  nil
end

#exists?Boolean

Returns True if the snapshot exists.

Returns:

  • (Boolean)

    True if the snapshot exists.



123
124
125
126
127
128
# File 'lib/aws/ec2/snapshot.rb', line 123

def exists?
  resp =
    client.describe_snapshots(:filters => [{ :name => 'snapshot-id',
                                             :values => [id] }]) and
    !resp.snapshot_set.empty?
end

#volumeVolume

Returns The volume this snapshot was created from.

Returns:

  • (Volume)

    The volume this snapshot was created from.



131
132
133
# File 'lib/aws/ec2/snapshot.rb', line 131

def volume
  Volume.new(volume_id, :config => config) if volume_id
end