snapshot_reload 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- snapshot_reload (0.0.1)
4
+ snapshot_reload (1.0.2)
5
5
  fog
6
6
  methadone (~> 1.2.3)
7
7
 
@@ -33,7 +33,7 @@ GEM
33
33
  net-ssh (>= 2.1.3)
34
34
  nokogiri (~> 1.5.0)
35
35
  ruby-hmac
36
- formatador (0.2.1)
36
+ formatador (0.2.4)
37
37
  gherkin (2.11.5)
38
38
  json (>= 1.4.6)
39
39
  json (1.7.5)
@@ -43,7 +43,7 @@ GEM
43
43
  multi_json (1.3.7)
44
44
  net-scp (1.0.4)
45
45
  net-ssh (>= 1.99.1)
46
- net-ssh (2.5.2)
46
+ net-ssh (2.6.2)
47
47
  nokogiri (1.5.5)
48
48
  rake (0.9.5)
49
49
  rdoc (3.12)
data/bin/snapshot_reload CHANGED
@@ -58,6 +58,13 @@ class App
58
58
  on('-q', '--quiet',
59
59
  "Be completely silent. Overrides --verbose switch")
60
60
 
61
+ # Add switch to save the contents of the target database before dropping
62
+ on('-x', '--[no-]save DUMPFILE',
63
+ "Save the contents of the target database prior to dropping it,",
64
+ "creating it, and loading in the snapshot. DUMPFILE is used as the",
65
+ "basename for the saved file as DUMPFILE.sql.gz",
66
+ "Default is to NOT save the data.")
67
+
61
68
  arg :config, :required,
62
69
  "Configuration file in same format as Rails config/database.yml file"
63
70
 
@@ -0,0 +1,49 @@
1
+ # feature file for testing the save option
2
+ #
3
+ # Author: Tamara Temple <tamara.temple@novu.com>
4
+ # Copyright: (c) 2012, Novu, LLC
5
+ # License: NONE
6
+ #
7
+
8
+
9
+ Feature: save the existing data in the target database before reloading
10
+ In order to keep potentially valuable data
11
+ As a tester
12
+ I want to dump the database before dropping the database
13
+
14
+
15
+
16
+
17
+
18
+
19
+ Scenario Outline: testing save option
20
+ Given a file named "config.yaml" with:
21
+ """
22
+ qa:
23
+ adapter: mysql2
24
+ host: localhost
25
+ encoding: utf8
26
+ database: novu_test
27
+ pool: 5
28
+ username: novuadmin
29
+ password:
30
+ """
31
+ Given a file named "dummy_source" with:
32
+ """
33
+ dummy content, we don't care
34
+ """
35
+ When I run `snapshot_reload --log-level debug <dryrun> --verbos --source dummy_source <saveoption> config.yaml`
36
+ Then the exit status should be <exit>
37
+ And the output should contain "<message>"
38
+
39
+ Scenarios: test data for save option
40
+ | saveoption | exit | message | dryrun |
41
+ | -x | 64 | ERROR -- : parse error: 'config' is required |
42
+ | -x dumpfile | 0 |saving to file dumpfile.sql.gz|
43
+ | --save | 64 | ERROR -- : parse error: 'config' is required |
44
+ | --save dumpfile | 0 |saving to file dumpfile.sql.gz|
45
+ | --save dumpfile | 0 |saving to file dumpfile.sql.gz|
46
+
47
+
48
+
49
+
@@ -10,11 +10,12 @@ Feature: Live testing of application
10
10
  I want to run the application with real credentials
11
11
  And and a real database configuration
12
12
 
13
-
13
+ # @no-clobber
14
+ # @announce
14
15
  Scenario Outline: run snapshot_reload with real credentials and configuration
15
16
  Given a file named "<config>" exists
16
17
  Given a file named "<creds>" exists
17
- When I run `snapshot_reload --log-level debug --verbose --aws-conf ../../<creds> --source s3://<bucket>/<folder>/<file> ../../<config>`
18
+ When I run `snapshot_reload --log-level debug --verbose --aws-conf ../../<creds> --source s3://<bucket>/<folder>/<file> <save> ../../<config>`
18
19
  Then the exit status should be 0
19
20
  And the output should match /.*Getting <folder>.<file> from <bucket>, range bytes=\d+-\d+.*/
20
21
  And the output should match /.*Wrote \d+ bytes to <file>.*/
@@ -24,6 +25,7 @@ Feature: Live testing of application
24
25
  And the output should match /.*Command issued: gunzip .* | mysql .* drop.*/
25
26
 
26
27
  Scenarios: test data
27
- | config | creds | bucket | folder | file |
28
- | testdata/config.yml | testdata/my-aws-cred | tam-test-2 | db-backups | novu-2012-12-11.sql.gz |
28
+ | config | creds | bucket | folder | file | save |
29
+ | testdata/config.yml | testdata/my-aws-cred | tam-test-2 | db-backups | novu-2012-12-11.sql.gz | |
30
+ | testdata/config.yml | testdata/my-aws-cred | tam-test-2 | db-backups | novu-2012-12-11.sql.gz | --save /tmp/dumpfile |
29
31
 
@@ -24,6 +24,7 @@ Feature: ensure command line options work as expected
24
24
  |--aws-conf AWS_CONFIG|
25
25
  |--aws-key AWSKEY|
26
26
  |--aws-secret AWSSECRET|
27
+ |--[no-]save DUMPFILE|
27
28
  And the banner should document that this app's arguments are:
28
29
  |config|which is required|
29
30
 
@@ -27,5 +27,6 @@ module SnapshotReload
27
27
  ENOBUCKET = 12
28
28
  ENOOBJECT = 13
29
29
  ENOS3FILES = 14
30
+ ENOSAVEFILE = 15
30
31
 
31
32
  end
@@ -17,11 +17,25 @@ module SnapshotReload
17
17
  include Methadone::SH
18
18
 
19
19
  def reload
20
+ save_db if @save_before
20
21
  drop_db
21
22
  create_db
22
23
  load_db
23
24
  end
24
25
 
26
+ def save_db
27
+ info("saving to file #{@save_file}") if @verbose
28
+ passopt = @password.present? ? "--password=#{password}" : ''
29
+ cmd = "mysqldump --host=#{@host} --user=#{username} #{passopt} #{@database} | gzip > #{@save_file}"
30
+ run_it(cmd)
31
+ unless File.exists?(@save_file) or @dry_run
32
+ fatal("Could not save data to #{@save_file}")
33
+ exit(ENOSAVEFILE)
34
+ else
35
+ info("data written to #{@save_file}") if @verbose
36
+ end
37
+ end
38
+
25
39
  def drop_db
26
40
  mysqladmin_go("drop")
27
41
  end # method drop
@@ -30,19 +44,20 @@ module SnapshotReload
30
44
  mysqladmin_go("create")
31
45
  end
32
46
 
47
+ def load_db
48
+ passopt = @password.present? ? "--password=#{@password}" : ''
49
+ fetch_snapshot
50
+ cmd = "gunzip < #{self.sql_file} | mysql --host=#{@host} --user=#{@username} #{passopt} #{@database}"
51
+ run_it(cmd)
52
+ end
53
+
33
54
  def mysqladmin_go(command)
34
55
  return false unless "drop create".include?(command)
35
- passopt = (@password.nil? or @password.empty?) ? '' : "--password=#{@password}"
56
+ passopt = @password.present? ? "--password=#{@password}" : ''
36
57
  cmd = "mysqladmin --host=#{@host} --user=#{@username} #{passopt} --force #{command} #{@database}"
37
58
  run_it(cmd)
38
59
  end # mysqladmin_go method
39
60
 
40
- def load_db
41
- passopt = (@password.nil? or @password.empty?) ? '' : "--password=#{@password}"
42
- fetch_snapshot
43
- cmd = "gunzip < #{self.sql_file} | mysql --host=#{@host} --user=#{@username} #{passopt} #{@database}"
44
- run_it(cmd)
45
- end
46
61
 
47
62
  def run_it(cmd)
48
63
  info("Dry-run, no commands will be executed.") if @dry_run and @verbose
@@ -11,7 +11,7 @@
11
11
 
12
12
 
13
13
  module SnapshotReload
14
- VERSION = "1.0.1"
14
+ VERSION = "1.0.2"
15
15
  SUMMARY = %q{Redeploy the obfuscated data from production to other servers}
16
16
  DESCRIPTION = %q{Take the obfuscated production data from it's nightly backup and place it into a working database. This script is run nightly to put obfuscated data into the Q* test server environments.}
17
17
 
@@ -22,8 +22,6 @@ module SnapshotReload
22
22
  class SnapshotReload
23
23
  include Methadone::CLILogging
24
24
 
25
- # attr_reader :config, :env, :host, :database, :username, :password, :source, :aws_key, :aws_secret, :sql_file
26
-
27
25
  def initialize(config, options=nil)
28
26
 
29
27
  options = Hash.new if options.nil?
@@ -45,6 +43,9 @@ module SnapshotReload
45
43
  @aws_secret = aws[1]
46
44
  end
47
45
 
46
+ @save_before = options.has_key?(:save)
47
+ @save_file = options[:save].gsub(/[^-_.\/[:alnum:]]*/, '') + ".sql.gz" if @save_before
48
+
48
49
  @dry_run = options['dry-run'] ||= false
49
50
 
50
51
  @verbose = options[:verbose] ||= false
@@ -64,6 +65,8 @@ module SnapshotReload
64
65
  info("source: #{@source.to_s}")
65
66
  info("aws key: #{@aws_key}")
66
67
  info("aws secret: #{@aws_secret}")
68
+ info("save before? #{@save_before.to_s}")
69
+ info("save file: #{@save_file}")
67
70
  info("dry run: #{@dry_run}")
68
71
  info("verbose: #{@verbose}")
69
72
  info("quiet: #{@quiet}")
@@ -113,6 +116,14 @@ module SnapshotReload
113
116
  @sql_file
114
117
  end
115
118
 
119
+ def save_before?
120
+ @save_before
121
+ end
122
+
123
+ def save_file
124
+ @save_file
125
+ end
126
+
116
127
  def dry_run?
117
128
  @dry_run
118
129
  end
Binary file
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snapshot_reload
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -127,6 +127,7 @@ files:
127
127
  - README.rdoc
128
128
  - Rakefile
129
129
  - bin/snapshot_reload
130
+ - features/save_option.feature
130
131
  - features/snapshot_live.feature
131
132
  - features/snapshot_reload.feature
132
133
  - features/step_definitions/snapshot_live_steps.rb
@@ -140,6 +141,9 @@ files:
140
141
  - lib/snapshot_reload/reload.rb
141
142
  - lib/snapshot_reload/validate.rb
142
143
  - lib/snapshot_reload/version.rb
144
+ - snapshot_reload-1.0.0.gem
145
+ - snapshot_reload-1.0.1.gem
146
+ - snapshot_reload-1.0.2.gem
143
147
  - snapshot_reload.gemspec
144
148
  - spec/snapshot_reload_spec.rb
145
149
  - spec/spec_helper.rb
@@ -168,6 +172,7 @@ signing_key:
168
172
  specification_version: 3
169
173
  summary: Redeploy the obfuscated data from production to other servers
170
174
  test_files:
175
+ - features/save_option.feature
171
176
  - features/snapshot_live.feature
172
177
  - features/snapshot_reload.feature
173
178
  - features/step_definitions/snapshot_live_steps.rb