Class: VGH::EC2::Snapshot
- Inherits:
-
Object
- Object
- VGH::EC2::Snapshot
- Defined in:
- lib/vgh/ec2/snapshot.rb
Overview
Creates a snapshot of the specified volume.
Usage
Snapshot.new(volume_id, description, )
Instance Attribute Summary collapse
-
#description ⇒ String
readonly
The description of the snapshot.
-
#snapshot ⇒ Object
readonly
The Snapshot object.
-
#tags ⇒ Hash
readonly
The tags hash.
-
#volume_id ⇒ String
readonly
The Volume ID.
Instance Method Summary collapse
-
#all_backups ⇒ Object
Returns a list of snapshots that are named the same with the current FQDN.
-
#backup_expiration ⇒ Object
Check for a an expiration period in the configuration file.
-
#checkpoints_to_keep ⇒ Object
How many checkpoints should be kept.
-
#create_snapshot ⇒ Object
Creates a snapshot for the specified volume.
-
#expired_backups ⇒ Array
Creates a list of expired snapshots according to the expiration time specified in the app’s configuration file.
-
#expired_checkpoints ⇒ Array
Creates a list of checkpoints that should be purged.
-
#purge_backups ⇒ Object
Purges expired snapshots.
-
#purge_checkpoints ⇒ Object
Purges expired snapshots.
-
#snap_and_tag(volume_id, description, tags) ⇒ Snapshot
Create and tag snapshot, and also purge expired ones.
-
#tag_snapshot ⇒ Object
Tags a Snapshot.
Instance Attribute Details
#description ⇒ String (readonly)
Returns The description of the snapshot.
30 31 32 |
# File 'lib/vgh/ec2/snapshot.rb', line 30 def description @description end |
#snapshot ⇒ Object (readonly)
Returns The Snapshot object.
36 37 38 |
# File 'lib/vgh/ec2/snapshot.rb', line 36 def snapshot @snapshot end |
#tags ⇒ Hash (readonly)
Returns The tags hash.
33 34 35 |
# File 'lib/vgh/ec2/snapshot.rb', line 33 def @tags end |
#volume_id ⇒ String (readonly)
Returns The Volume ID.
27 28 29 |
# File 'lib/vgh/ec2/snapshot.rb', line 27 def volume_id @volume_id end |
Instance Method Details
#all_backups ⇒ Object
Returns a list of snapshots that are named the same with the current FQDN.
121 122 123 124 125 |
# File 'lib/vgh/ec2/snapshot.rb', line 121 def all_backups @all ||= ec2.snapshots. with_owner('self'). tagged('Name').tagged_values(fqdn) end |
#backup_expiration ⇒ Object
Check for a an expiration period in the configuration file
99 100 101 102 103 104 105 106 107 |
# File 'lib/vgh/ec2/snapshot.rb', line 99 def backup_expiration expiration = config[:expiration] if expiration.nil? @backup_expiration = 7 else @backup_expiration = expiration end return @backup_expiration.to_i end |
#checkpoints_to_keep ⇒ Object
How many checkpoints should be kept
110 111 112 113 114 115 116 117 118 |
# File 'lib/vgh/ec2/snapshot.rb', line 110 def checkpoints_to_keep keep = config[:checkpoints] if keep.nil? @checkpoints_to_keep = 5 else @checkpoints_to_keep = keep end return @checkpoints_to_keep.to_i end |
#create_snapshot ⇒ Object
Creates a snapshot for the specified volume
40 41 42 43 44 45 46 |
# File 'lib/vgh/ec2/snapshot.rb', line 40 def create_snapshot @snapshot = ec2.volumes[volume_id]. create_snapshot("#{description}") .info "Created snapshot \"#{snapshot.id}\"" tag_snapshot return @snapshot end |
#expired_backups ⇒ Array
Creates a list of expired snapshots according to the expiration time specified in the app’s configuration file
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/vgh/ec2/snapshot.rb', line 76 def expired_backups @expired_backups = [] all_backups.tagged('BACKUP'). tagged('Name').tagged_values(fqdn). each {|snap| if snap.start_time < (Time.now - backup_expiration*24*60*60) @expired_backups.push snap end } return @expired_backups end |
#expired_checkpoints ⇒ Array
Creates a list of checkpoints that should be purged
90 91 92 93 94 95 96 |
# File 'lib/vgh/ec2/snapshot.rb', line 90 def expired_checkpoints @expired_checkpoints = all_backups. tagged('CHECKPOINT'). tagged('Name').tagged_values(fqdn). sort_by(&:start_time).reverse. drop(checkpoints_to_keep) end |
#purge_backups ⇒ Object
Purges expired snapshots
58 59 60 61 62 63 |
# File 'lib/vgh/ec2/snapshot.rb', line 58 def purge_backups expired_backups.each do |snap| .info "Deleting expired snapshot (#{snap.id})" snap.delete end end |
#purge_checkpoints ⇒ Object
Purges expired snapshots
66 67 68 69 70 71 |
# File 'lib/vgh/ec2/snapshot.rb', line 66 def purge_checkpoints expired_checkpoints.each do |snap| .info "Deleting checkpoint (#{snap.id})" snap.delete end end |
#snap_and_tag(volume_id, description, tags) ⇒ Snapshot
Create and tag snapshot, and also purge expired ones
18 19 20 21 22 23 24 |
# File 'lib/vgh/ec2/snapshot.rb', line 18 def snap_and_tag(volume_id, description, ) @volume_id = volume_id @description = description @tags = create_snapshot return snapshot end |
#tag_snapshot ⇒ Object
Tags a Snapshot
49 50 51 52 53 54 55 |
# File 'lib/vgh/ec2/snapshot.rb', line 49 def tag_snapshot snap = snapshot .info "Tagging snapshot \"#{snap.id}\"..." .map {|key, value| ec2..create(snap, key, {:value => value}) } end |