snapscatter 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -17,12 +17,13 @@ Just use the gem command to install:
17
17
 
18
18
  You can have a look at the commands and options by just typing the name of the executable:
19
19
 
20
- Commands:
21
- snapscatter create # Create snapshots, optionally copying them to destination region
20
+ Snapscatter commands:
21
+ snapscatter create # Create snapshots, optionally copying them to an alternate region
22
22
  snapscatter help [COMMAND] # Describe available commands or one specific command
23
23
  snapscatter list # Show available snapshots
24
24
  snapscatter purge # purge snapshots older than the specified number of days
25
25
  snapscatter targets # Show volumes tagged for backup
26
+ snapscatter version # Shows current version of the program
26
27
 
27
28
  The best way to use this script is to make a shell wrapper for it that exports your AWS credentials
28
29
  as environment variables and then put it under the control of the cron demon.
@@ -35,7 +36,7 @@ value of `true`. You can then check the list of these volumes using the command
35
36
  ### Taking snapshots
36
37
 
37
38
  Use the command `create` to take snapshots of all the tagged volumes. Snapshots will be taken to your default
38
- AWS region, but you can optionally supply the '--destination' flag to create a copy onto another
39
+ AWS region, but you can optionally supply the `--alternate` flag to create a copy onto another
39
40
  region for disaster recovery.
40
41
 
41
42
  Every snapshot taken will have the `PurgeAllow` tag set with the value of `true`. If for some reason you want
@@ -45,7 +46,10 @@ a snapshot not to be purged indefinitely, you can set this tag to any other valu
45
46
  ### Purging snapshots
46
47
 
47
48
  You can call the `purge` command to delete any snapshots older than 30 days. This is the default retention policy
48
- but you can change it by using the optional '-d' flag (for `--days).
49
+ but you can change it by using the optional `-d` flag (for `--days`).
50
+
51
+ Snapshots will be deleted from your default AWS region. If you supply the `--alternate` flag, snapshots will also
52
+ be purged from the alternate region.
49
53
 
50
54
  You can also run this command with the `-n` (for `--noaction`) to only list the snapshots that would be purged
51
55
  under the specified retention policy, no snapshot will be purged.
@@ -53,8 +57,8 @@ under the specified retention policy, no snapshot will be purged.
53
57
  ### Listing snapshots
54
58
 
55
59
  The `list` command will show all the snapshots subject to be purged, that is, all snapshots with the `PurgAllow`
56
- tag set to `true`. The `-f`option for this command gives more information on every snapshot: snapshot id, volume id
57
- and date of creation.
60
+ tag set to `true`. The `-f` option for this command gives more information on every snapshot: snapshot id, volume id
61
+ and date of creation. Using the `-r` or `--region` flag you can change the target region.
58
62
 
59
63
  ### Consistent backups
60
64
 
@@ -77,13 +81,13 @@ Create a shell file like the following and put it under cron's control:
77
81
  export AWS_SECRET_ACCESS_KEY="YOURSECRETACCESSKEY"
78
82
 
79
83
  snapscatter purge -d 20
80
- snapscatter create --destination="us-west-1"
84
+ snapscatter create --alternate="us-west-1"
81
85
 
82
86
  You have to make two calls because the script won't purge and create snapshots on a single call.
83
87
 
84
88
  ## TODO
85
89
 
86
- * Take consistency speficication out of the volume and put it in a configuration file
90
+ * Take consistency specification out of the volume and put it in a configuration file
87
91
  * More database connectors
88
92
 
89
93
  ## Contributing
@@ -43,7 +43,7 @@ module Snapscatter
43
43
  snapshots = Snapscatter.list ec2
44
44
  snapshots.each do |snapshot|
45
45
  purge_date = snapshot.start_time.to_date + purge_after_days
46
- # puts "#{Date.today} > #{purge_date} == #{Date.today > purge_date}"
46
+ # say "#{Date.today} > #{purge_date} == #{Date.today > purge_date}"
47
47
  if Date.today > purge_date
48
48
  snapshot.delete if not list_only
49
49
  purged << snapshot
@@ -3,26 +3,34 @@ require_relative '../snapscatter'
3
3
 
4
4
  module Snapscatter
5
5
  class CLI < Thor
6
+ package_name "Snapscatter"
7
+ map "-v" => :version
8
+
9
+ desc 'version', 'Shows current version of the program'
10
+ def version
11
+ say "Snapscatter #{Snapscatter::VERSION}"
12
+ end
6
13
 
7
14
  desc 'targets', 'Show volumes tagged for backup'
8
15
  method_option :keys, type: :hash, banner: 'AWS security keys'
9
16
  def targets
10
17
  targets = Snapscatter.targets create_ec2
11
- targets.each { |target| puts target.id }
18
+ targets.each { |target| say target.id }
12
19
  end
13
20
 
14
21
  desc 'list', 'Show available snapshots'
15
22
  method_option :keys, type: :hash, banner: 'AWS security keys'
16
23
  method_option :full, type: :boolean, aliases: '-f', banner: 'Show useful info about snapshots'
24
+ method_option :region, type: :string, aliases: '-r', banner: 'Region to list snapshots from'
17
25
  def list
18
- snapshots = Snapscatter.list create_ec2
26
+ snapshots = Snapscatter.list create_ec2(region: options[:region])
19
27
  snapshots.each do |snapshot|
20
28
  output = [ snapshot.id ]
21
29
  if options[:full]
22
30
  output << snapshot.volume_id
23
31
  output << snapshot.start_time.strftime("%Y-%m-%d")
24
32
  end
25
- puts output.join(" ")
33
+ say output.join(" ")
26
34
  end
27
35
  end
28
36
 
@@ -30,14 +38,20 @@ module Snapscatter
30
38
  method_option :keys, type: :hash, banner: 'AWS security keys'
31
39
  method_option :days, type: :numeric, default: 30, aliases: '-d', banner: 'retention policy in days'
32
40
  method_option :noaction, type: :boolean, default: false, aliases: '-n', banner: 'do not purge, just show'
41
+ method_option :alternate, type: :string, banner: 'alternate region to purge snapshots from'
33
42
  def purge
34
- purged = Snapscatter.purge create_ec2, options[:days], true # options[:noaction] # remove in production
35
- purged.each { |snapshot| puts "#{snapshot.id}" }
43
+ purged = Snapscatter.purge create_ec2, options[:days], options[:noaction]
44
+ purged.each { |snapshot| say "#{snapshot.id}" }
45
+
46
+ if options.has_key? 'alternate'
47
+ purged = Snapscatter.purge create_ec2(region: options[:alternate]), options[:days], options[:noaction]
48
+ purged.each { |snapshot| say "#{snapshot.id}" }
49
+ end
36
50
  end
37
51
 
38
- desc 'create', 'Create snapshots, optionally copying them to destination region'
52
+ desc 'create', 'Create snapshots, optionally copying them to an alternate region'
39
53
  method_option :keys, type: :hash, banner: 'AWS security keys'
40
- method_option :destination, type: :string, banner: 'region to copy snapshots to'
54
+ method_option :alternate, type: :string, banner: 'region to copy snapshots to'
41
55
  def create
42
56
  source_ec2 = create_ec2
43
57
  targets = Snapscatter.targets source_ec2
@@ -59,14 +73,14 @@ module Snapscatter
59
73
 
60
74
  if snapshot.status == :completed
61
75
  output = ["created", snapshot.id, description]
62
- if options.has_key? 'destination'
63
- destination_ec2 = create_ec2(region: options[:destination])
64
- Snapscatter.copy destination_ec2, source_ec2.client.config.region, snapshot, description
65
- output << "#{options[:destination]}"
76
+ if options.has_key? 'alternate'
77
+ alternate_ec2 = create_ec2(region: options[:alternate])
78
+ Snapscatter.copy alternate_ec2, source_ec2.client.config.region, snapshot, description
79
+ output << "#{options[:alternate]}"
66
80
  end
67
- puts output.join(" ")
81
+ say output.join(" ")
68
82
  else
69
- puts "#{volume.id} (#{volume_name}): snapshot failed"
83
+ say "#{volume.id} (#{volume_name}): snapshot failed"
70
84
  end
71
85
  end
72
86
  end
@@ -1,3 +1,3 @@
1
1
  module Snapscatter
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snapscatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
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-10-22 00:00:00.000000000 Z
12
+ date: 2013-11-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor