vgh 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +0 -1
- data/CHANGELOG.rdoc +7 -1
- data/README.rdoc +3 -2
- data/conf/config.yml.example +5 -4
- data/lib/vgh/apps/checkpoint.rb +9 -5
- data/lib/vgh/apps/ec2_backup.rb +9 -5
- data/lib/vgh/cli.rb +7 -5
- data/lib/vgh/ec2/snapshot.rb +39 -16
- data/lib/vgh/system/mysql.rb +1 -1
- data/lib/vgh/version.rb +1 -1
- data/spec/ec2/snapshot_spec.rb +7 -1
- metadata +4 -4
data/.travis.yml
CHANGED
data/CHANGELOG.rdoc
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
-
=== 0.2.
|
1
|
+
=== 0.2.2
|
2
|
+
[Features]
|
3
|
+
- Add '--example' option to generate example configuration
|
4
|
+
- Add option to keep a number of checkpoints
|
5
|
+
[Bugs]
|
2
6
|
- Fix SQL and LVM checks
|
7
|
+
- Clean up the Snapshot class
|
3
8
|
|
4
9
|
=== 0.2.0
|
10
|
+
[Features]
|
5
11
|
- Add Checkpoint app
|
6
12
|
- Merged all configuration files to a single one
|
7
13
|
- Major code refactoring
|
data/README.rdoc
CHANGED
@@ -52,9 +52,10 @@ It should have the following format (where the keys are symbols):
|
|
52
52
|
:sub_key: 'sub value'
|
53
53
|
|
54
54
|
An example of the configuration file can be found in this gem's directory.
|
55
|
-
You can
|
55
|
+
You can copy it by using the +--example=PATH+ command line option.
|
56
56
|
|
57
|
-
Ex: <tt>vgh
|
57
|
+
Ex: <tt>mkdir /etc/vgh
|
58
|
+
vgh --example=/etc/vgh</tt>
|
58
59
|
|
59
60
|
Read the config.yml.example for a list of configuration options.
|
60
61
|
|
data/conf/config.yml.example
CHANGED
@@ -14,12 +14,13 @@
|
|
14
14
|
#:auto_scaling_endpoint: 'autoscaling.us-west-2.amazonaws.com'
|
15
15
|
|
16
16
|
|
17
|
-
|
18
|
-
# EC2-Backup app settings #
|
19
|
-
|
17
|
+
########################################
|
18
|
+
# EC2-Backup & Checkpoint app settings #
|
19
|
+
########################################
|
20
20
|
|
21
21
|
# Expiration period (defaults to 7 days)
|
22
|
-
#:expiration: 7 # Number of days to keep the snapshots
|
22
|
+
#:expiration: 7 # Number of days to keep the backup snapshots
|
23
|
+
#:checkpoints: 5 # How many checkpoints should be kept
|
23
24
|
|
24
25
|
# MySQL Settings
|
25
26
|
#:mysql_user: 'dbadmin' # The MySQL user that can flush the tables
|
data/lib/vgh/apps/checkpoint.rb
CHANGED
@@ -15,9 +15,13 @@ module APPS
|
|
15
15
|
# @return [Object] Volumes Class
|
16
16
|
attr_reader :volumes
|
17
17
|
|
18
|
+
# @return [Object] Snapshot Class
|
19
|
+
attr_reader :snapshot
|
20
|
+
|
18
21
|
# Initialize external classes
|
19
22
|
def initialize
|
20
23
|
@volumes ||= EC2::Volume.new
|
24
|
+
@snapshot = EC2::Snapshot.new
|
21
25
|
end
|
22
26
|
|
23
27
|
# Runs the checkpoint app logic
|
@@ -25,16 +29,16 @@ module APPS
|
|
25
29
|
|
26
30
|
System.lock
|
27
31
|
|
28
|
-
|
29
|
-
|
30
|
-
snap_and_tag(
|
32
|
+
volumes.list_tagged('CHECKPOINT').map {|vid|
|
33
|
+
snapshot.snap_and_tag(
|
31
34
|
vid,
|
32
|
-
"CHECKPOINT for #{vid}(#{
|
35
|
+
"CHECKPOINT for #{vid}(#{volumes.name_tag(vid)})",
|
33
36
|
{
|
34
37
|
'Name' => fqdn,
|
35
|
-
'CHECKPOINT' => "#{
|
38
|
+
'CHECKPOINT' => "#{vid}"
|
36
39
|
}
|
37
40
|
)
|
41
|
+
snapshot.purge_checkpoints_for vid
|
38
42
|
}
|
39
43
|
|
40
44
|
System.unlock
|
data/lib/vgh/apps/ec2_backup.rb
CHANGED
@@ -15,9 +15,13 @@ module APPS
|
|
15
15
|
# @return [Object] Volumes Class
|
16
16
|
attr_reader :volumes
|
17
17
|
|
18
|
+
# @return [Object] Snapshot Class
|
19
|
+
attr_reader :snapshot
|
20
|
+
|
18
21
|
# Initialize external classes
|
19
22
|
def initialize
|
20
23
|
@volumes ||= EC2::Volume.new
|
24
|
+
@snapshot = EC2::Snapshot.new
|
21
25
|
end
|
22
26
|
|
23
27
|
# Runs the ec2-backup app logic
|
@@ -25,16 +29,16 @@ module APPS
|
|
25
29
|
|
26
30
|
System.lock
|
27
31
|
|
28
|
-
|
29
|
-
|
30
|
-
snap_and_tag(
|
32
|
+
volumes.list.map {|vid|
|
33
|
+
snapshot.snap_and_tag(
|
31
34
|
vid,
|
32
|
-
"Backup for #{vid}(#{
|
35
|
+
"Backup for #{vid}(#{volumes.name_tag(vid)})",
|
33
36
|
{
|
34
37
|
'Name' => fqdn,
|
35
|
-
'BACKUP' => "#{
|
38
|
+
'BACKUP' => "#{vid}"
|
36
39
|
}
|
37
40
|
)
|
41
|
+
snapshot.purge_backups_for vid
|
38
42
|
}
|
39
43
|
|
40
44
|
System.unlock
|
data/lib/vgh/cli.rb
CHANGED
@@ -65,7 +65,7 @@ module VGH
|
|
65
65
|
confdir
|
66
66
|
verbose
|
67
67
|
logging
|
68
|
-
|
68
|
+
examples
|
69
69
|
help
|
70
70
|
version
|
71
71
|
validate(args)
|
@@ -135,10 +135,12 @@ module VGH
|
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
138
|
-
#
|
139
|
-
def
|
140
|
-
@optparse.on_tail('-
|
141
|
-
|
138
|
+
# Creates sample config folder
|
139
|
+
def examples
|
140
|
+
@optparse.on_tail('-e', '--example=PATH', 'Generate example configuration') do |path|
|
141
|
+
examples = Dir.glob(File.expand_path('../../conf/*', File.dirname(__FILE__)))
|
142
|
+
destination = File.expand_path(path)
|
143
|
+
FileUtils.cp examples, destination, :verbose => true
|
142
144
|
exit
|
143
145
|
end
|
144
146
|
end
|
data/lib/vgh/ec2/snapshot.rb
CHANGED
@@ -1,10 +1,5 @@
|
|
1
1
|
module VGH
|
2
2
|
|
3
|
-
# Creates the snapshots
|
4
|
-
def snap_and_tag(*args)
|
5
|
-
EC2::Snapshot.new(*args)
|
6
|
-
end
|
7
|
-
|
8
3
|
module EC2
|
9
4
|
|
10
5
|
# Creates a snapshot of the specified volume.
|
@@ -20,13 +15,11 @@ class Snapshot
|
|
20
15
|
# @param [String] description The description for the new snapshot
|
21
16
|
# @param [Hash] tags A Hash containing the names and values of the tags
|
22
17
|
# @return [Snapshot] The Snapshot object.
|
23
|
-
def
|
18
|
+
def snap_and_tag(volume_id, description, tags)
|
24
19
|
@volume_id = volume_id
|
25
20
|
@description = description
|
26
21
|
@tags = tags
|
27
22
|
create_snapshot
|
28
|
-
tag_snapshot
|
29
|
-
purge_backups
|
30
23
|
return snapshot
|
31
24
|
end
|
32
25
|
|
@@ -48,6 +41,7 @@ class Snapshot
|
|
48
41
|
@snapshot = ec2.volumes[volume_id].
|
49
42
|
create_snapshot("#{description}")
|
50
43
|
message.info "Created snapshot \"#{snapshot.id}\""
|
44
|
+
tag_snapshot
|
51
45
|
return @snapshot
|
52
46
|
end
|
53
47
|
|
@@ -61,26 +55,44 @@ class Snapshot
|
|
61
55
|
end
|
62
56
|
|
63
57
|
# Purges expired snapshots
|
64
|
-
def
|
65
|
-
|
58
|
+
def purge_backups_for(*args)
|
59
|
+
expired_backups_for(*args).each do |snap|
|
66
60
|
message.info "Deleting expired snapshot (#{snap.id})"
|
67
61
|
snap.delete
|
68
62
|
end
|
69
63
|
end
|
70
64
|
|
65
|
+
# Purges expired snapshots
|
66
|
+
def purge_checkpoints_for(*args)
|
67
|
+
expired_checkpoints_for(*args).each do |snap|
|
68
|
+
message.info "Deleting checkpoint (#{snap.id})"
|
69
|
+
snap.delete
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
71
73
|
# Creates a list of expired snapshots according to the expiration time
|
72
74
|
# specified in the app's configuration file
|
73
75
|
# @return [Array] An array of expired snapshot objects
|
74
|
-
def
|
76
|
+
def expired_backups_for(vid)
|
75
77
|
@expired_backups = []
|
76
|
-
all_backups.
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
all_backups.tagged('BACKUP').tagged_values(vid).
|
79
|
+
each {|snap|
|
80
|
+
if snap.start_time < (Time.now - backup_expiration*24*60*60)
|
81
|
+
@expired_backups.push snap
|
82
|
+
end
|
83
|
+
}
|
81
84
|
return @expired_backups
|
82
85
|
end
|
83
86
|
|
87
|
+
# Creates a list of checkpoints that should be purged
|
88
|
+
# @return [Array] An array of snapshot objects
|
89
|
+
def expired_checkpoints_for(vid)
|
90
|
+
@expired_checkpoints = all_backups.
|
91
|
+
tagged('CHECKPOINT').tagged_values(vid).
|
92
|
+
sort_by(&:start_time).reverse.
|
93
|
+
drop(checkpoints_to_keep)
|
94
|
+
end
|
95
|
+
|
84
96
|
# Check for a an expiration period in the configuration file
|
85
97
|
def backup_expiration
|
86
98
|
expiration = config[:expiration]
|
@@ -92,6 +104,17 @@ class Snapshot
|
|
92
104
|
return @backup_expiration.to_i
|
93
105
|
end
|
94
106
|
|
107
|
+
# How many checkpoints should be kept
|
108
|
+
def checkpoints_to_keep
|
109
|
+
keep = config[:checkpoints]
|
110
|
+
if keep.nil?
|
111
|
+
@checkpoints_to_keep = 5
|
112
|
+
else
|
113
|
+
@checkpoints_to_keep = keep
|
114
|
+
end
|
115
|
+
return @checkpoints_to_keep.to_i
|
116
|
+
end
|
117
|
+
|
95
118
|
# Returns a list of snapshots that are named the same with the current FQDN.
|
96
119
|
def all_backups
|
97
120
|
@all ||= ec2.snapshots.
|
data/lib/vgh/system/mysql.rb
CHANGED
@@ -36,7 +36,7 @@ class MySQL
|
|
36
36
|
# @return [Boolean]
|
37
37
|
def commands_present?
|
38
38
|
commands_present = false
|
39
|
-
if File.exists?(@mysqladmin_cmd) and File.exists?(@
|
39
|
+
if File.exists?(@mysqladmin_cmd) and File.exists?(@mysql_cmd)
|
40
40
|
commands_present = true
|
41
41
|
end
|
42
42
|
return commands_present
|
data/lib/vgh/version.rb
CHANGED
data/spec/ec2/snapshot_spec.rb
CHANGED
@@ -27,9 +27,15 @@ describe VGH::EC2::Snapshot do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it "Should create a list of expired backups" do
|
30
|
-
snap.
|
30
|
+
snap.expired_backups_for(@volume1.id).should be_an Array
|
31
31
|
end
|
32
32
|
|
33
|
+
it "Should create a list of expired checkpoints" do
|
34
|
+
snap.stub(:config).and_return({:checkpoints => 2})
|
35
|
+
snap.expired_checkpoints_for(@volume1.id).should be_an Array
|
36
|
+
end
|
37
|
+
|
38
|
+
|
33
39
|
it "Should return a backup expiration integer" do
|
34
40
|
snap.stub(:config).and_return({:expiration => 5})
|
35
41
|
snap.backup_expiration.should eq(5)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vgh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk
|
@@ -185,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
185
185
|
version: '0'
|
186
186
|
segments:
|
187
187
|
- 0
|
188
|
-
hash:
|
188
|
+
hash: -217298541
|
189
189
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
190
|
none: false
|
191
191
|
requirements:
|
@@ -194,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
194
|
version: '0'
|
195
195
|
segments:
|
196
196
|
- 0
|
197
|
-
hash:
|
197
|
+
hash: -217298541
|
198
198
|
requirements: []
|
199
199
|
rubyforge_project:
|
200
200
|
rubygems_version: 1.8.23
|