new_backup 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .DS_Store
2
+ /.rspec
3
+ html
4
+ pkg
5
+ results.html
6
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p392@new_backup"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.16.20 ()" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
35
+
36
+ # If you use bundler, this might be useful to you:
37
+ # if [[ -s Gemfile ]] && {
38
+ # ! builtin command -v bundle >/dev/null ||
39
+ # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
40
+ # }
41
+ # then
42
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
+ # gem install bundler
44
+ # fi
45
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
+ # then
47
+ # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
48
+ # fi
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in new_backup.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,82 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ new_backup (1.0.1)
5
+ RunIt
6
+ dogapi
7
+ fog
8
+ methadone (~> 1.2.6)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ RunIt (1.0.1)
14
+ aruba (0.5.3)
15
+ childprocess (>= 0.3.6)
16
+ cucumber (>= 1.1.1)
17
+ rspec-expectations (>= 2.7.0)
18
+ builder (3.2.0)
19
+ childprocess (0.3.9)
20
+ ffi (~> 1.0, >= 1.0.11)
21
+ columnize (0.3.6)
22
+ cucumber (1.3.1)
23
+ builder (>= 2.1.2)
24
+ diff-lcs (>= 1.1.3)
25
+ gherkin (~> 2.12.0)
26
+ multi_json (~> 1.3)
27
+ debugger (1.6.0)
28
+ columnize (>= 0.3.1)
29
+ debugger-linecache (~> 1.2.0)
30
+ debugger-ruby_core_source (~> 1.2.1)
31
+ debugger-linecache (1.2.0)
32
+ debugger-ruby_core_source (1.2.2)
33
+ diff-lcs (1.2.4)
34
+ dogapi (1.6.0)
35
+ json (>= 1.5.1)
36
+ excon (0.22.1)
37
+ ffi (1.8.1)
38
+ fog (1.11.1)
39
+ builder
40
+ excon (~> 0.20)
41
+ formatador (~> 0.2.0)
42
+ json (~> 1.7)
43
+ mime-types
44
+ net-scp (~> 1.1)
45
+ net-ssh (>= 2.1.3)
46
+ nokogiri (~> 1.5.0)
47
+ ruby-hmac
48
+ formatador (0.2.4)
49
+ gherkin (2.12.0)
50
+ multi_json (~> 1.3)
51
+ json (1.8.0)
52
+ methadone (1.2.6)
53
+ bundler
54
+ mime-types (1.23)
55
+ multi_json (1.7.3)
56
+ net-scp (1.1.1)
57
+ net-ssh (>= 2.6.5)
58
+ net-ssh (2.6.7)
59
+ nokogiri (1.5.9)
60
+ rake (0.9.6)
61
+ rdoc (4.0.1)
62
+ json (~> 1.4)
63
+ rspec (2.13.0)
64
+ rspec-core (~> 2.13.0)
65
+ rspec-expectations (~> 2.13.0)
66
+ rspec-mocks (~> 2.13.0)
67
+ rspec-core (2.13.1)
68
+ rspec-expectations (2.13.0)
69
+ diff-lcs (>= 1.1.3, < 2.0)
70
+ rspec-mocks (2.13.1)
71
+ ruby-hmac (0.4.0)
72
+
73
+ PLATFORMS
74
+ ruby
75
+
76
+ DEPENDENCIES
77
+ aruba
78
+ debugger
79
+ new_backup!
80
+ rake (~> 0.9.2)
81
+ rdoc
82
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2013 YOUR NAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # NewBackup
2
+
3
+ Backs up an RDS instance, saving the backup in an S3 bucket.
4
+ Runs an obfuscation script on the backup, saving that in an S3 bucket as "clean".
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'new_backup'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install new_backup
19
+
20
+ ## Usage
21
+
22
+ $ new_backup [options] config-file
23
+
24
+ ## Configuration
25
+
26
+ The `config-file` on the command line needs to contain the following:
27
+
28
+ fog_timeout: (in seconds)
29
+ dump_directory: (directory to save files)
30
+ dump_ttl: (number of backups to keep)
31
+ aws_region:
32
+ db_instance_type:
33
+ timestamp_format: (strftime format string, no spaces for extra goodness)
34
+ rds_instance_id: (AWS RDS instance to back up)
35
+ db_subnet_group_name: (AWS RDS Subnet Group)
36
+ backup_bucket: (AWS S3 bucket to contain the raw backups)
37
+ s3_bucket: (AWS S3 bucket to contain the cleaned (obfuscated) backups)
38
+ s3_prefix: (Prefix, aka "subdirectory", to store backups in)
39
+ aws_s3_region: (AWS S3 region to use for saving)
40
+ mysql_username: (user name of data base)
41
+ mysql_database: (data base in RDS instance to back up)
42
+ mysql_password: (password for user)
43
+ obfuscate_script: (path to script to run to obfuscate the database)
44
+ datadog_apikey: (Datadog API key to use to report progress and errors)
45
+ aws_access_key_id: (Your AWS access key)
46
+ aws_secret_access_key: (Your AWS secret key)
47
+
48
+ The file `sample-config.yml` can be modified to your suiting.
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create new Pull Request
data/README.rdoc ADDED
@@ -0,0 +1,53 @@
1
+ = new_backup - Backup and obfuscate an RDS instance, storing results in an S3 bucket
2
+
3
+ Author:: Tamara Temple (tamara.temple@novu.com)
4
+ Copyright:: Copyright (c) 2013 Novu, LLC
5
+
6
+ License:: mit, see LICENSE.txt
7
+
8
+ new_backup creates a snapshot of an RDS instance, and then dumps the
9
+ snapshot to a file, compressing it, and saving that file to S3. It
10
+ also runs a script to obfuscate the database snapshot, dumps and
11
+ compresses the cleaned database, and saves that file to S3 as well.
12
+
13
+ == Links
14
+
15
+ * {Source on Github}[https://github.com/novu/new-backup]
16
+
17
+ == Install
18
+
19
+ To install, enter the following:
20
+
21
+ $ gem install new-backup
22
+
23
+ This is a stand-alone utility, so it would probably be best to install
24
+ this gem at a system-wide level.
25
+
26
+ == Examples
27
+
28
+ Run the backup using the info as specified in the file `config.yml`
29
+
30
+ $ new-backup config.yml
31
+
32
+ Turn on debug-level logging:
33
+
34
+ $ new-backup --log-level debug config.yml
35
+
36
+ For help, run:
37
+
38
+ $ new-backup --help
39
+
40
+
41
+ == Configuration
42
+
43
+ The `sample-config.yml` file contains the necessary elements to
44
+ configure the script. Copy it and modify it so it meets your needs.
45
+
46
+
47
+ == Contributing
48
+
49
+ * Fork it
50
+ * Create your feature branch (`git checkout -b my-new-feature`)
51
+ * Commit your changes (`git commit -am 'Add some feature'`)
52
+ * Push to the branch (`git push origin my-new-feature`)
53
+ * Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,70 @@
1
+ def dump_load_path
2
+ puts $LOAD_PATH.join("\n")
3
+ found = nil
4
+ $LOAD_PATH.each do |path|
5
+ if File.exists?(File.join(path,"rspec"))
6
+ puts "Found rspec in #{path}"
7
+ if File.exists?(File.join(path,"rspec","core"))
8
+ puts "Found core"
9
+ if File.exists?(File.join(path,"rspec","core","rake_task"))
10
+ puts "Found rake_task"
11
+ found = path
12
+ else
13
+ puts "!! no rake_task"
14
+ end
15
+ else
16
+ puts "!!! no core"
17
+ end
18
+ end
19
+ end
20
+ if found.nil?
21
+ puts "Didn't find rspec/core/rake_task anywhere"
22
+ else
23
+ puts "Found in #{path}"
24
+ end
25
+ end
26
+ require 'bundler'
27
+ require 'rake/clean'
28
+
29
+ begin
30
+ require 'rspec/core/rake_task'
31
+ rescue LoadError
32
+ dump_load_path
33
+ raise
34
+ end
35
+
36
+ require 'cucumber'
37
+ require 'cucumber/rake/task'
38
+ gem 'rdoc' # we need the installed RDoc gem, not the system one
39
+ require 'rdoc/task'
40
+
41
+ include Rake::DSL
42
+
43
+ Bundler::GemHelper.install_tasks
44
+
45
+
46
+ RSpec::Core::RakeTask.new do |t|
47
+ # Put spec opts in a file named .rspec in root
48
+ end
49
+
50
+
51
+ CUKE_RESULTS = 'results.html'
52
+ CLEAN << CUKE_RESULTS
53
+ Cucumber::Rake::Task.new(:features) do |t|
54
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
55
+ t.fork = false
56
+ end
57
+
58
+ Rake::RDocTask.new do |rd|
59
+
60
+ rd.main = "README.rdoc"
61
+
62
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
63
+ end
64
+
65
+ task :default => [:spec,:features]
66
+
67
+ desc 'Live testing to AWS test instances'
68
+ task :live_test do |t, args|
69
+ sh "bundle exec bin/new_backup --log-level debug --debug tmp/livetest-config.yml"
70
+ end
data/bin/new_backup ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'methadone'
5
+ require 'yaml'
6
+ require 'new_backup.rb'
7
+
8
+ class App
9
+ include Methadone::Main
10
+ include Methadone::CLILogging
11
+
12
+ main do |config_file| # Add args you want: |like,so|
13
+ options["config_file"] = config_file
14
+ NewBackup::Main.new(options).run
15
+ end
16
+
17
+ # supplemental methods here
18
+
19
+ # Declare command-line interface here
20
+
21
+ description "Backup raw and clean data from RDS to S3"
22
+
23
+ # Accept flags via:
24
+ # on("--flag VAL","Some flag")
25
+ # options[flag] will contain VAL
26
+ #
27
+ # Specify switches via:
28
+ # on("--[no-]switch","Some switch")
29
+ on("--debug", "Turn on debug mode")
30
+ on("--nords", "Don't run the RDS portion")
31
+ on("--nos3", "Don't run the S3 portion")
32
+ #
33
+ # Or, just call OptionParser methods on opts
34
+ #
35
+ # Require an argument
36
+ arg :config_file, "Specify the configuration file path to set options for the backup",
37
+ "See #{File.dirname(File.dirname(__FILE__))}/sample-config.yml as an example"
38
+ #
39
+ # # Make an argument optional
40
+ # arg :optional_arg, :optional
41
+
42
+ version NewBackup::VERSION
43
+
44
+ use_log_level_option
45
+
46
+ go!
47
+ end
@@ -0,0 +1,14 @@
1
+ Feature: My bootstrapped app kinda works
2
+ In order to get going on coding my awesome app
3
+ I want to have aruba and cucumber setup
4
+ So I don't have to do it myself
5
+
6
+ Scenario: App just runs
7
+ When I get help for "new_backup"
8
+ Then the exit status should be 0
9
+ And the banner should be present
10
+ And the banner should document that this app takes options
11
+ And the following options should be documented:
12
+ |--version|
13
+ And the banner should document that this app's arguments are:
14
+ |config_file|which is required|
@@ -0,0 +1 @@
1
+ # Put your step definitions here
@@ -0,0 +1,16 @@
1
+ require 'aruba/cucumber'
2
+ require 'methadone/cucumber'
3
+
4
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
5
+ LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
6
+
7
+ Before do
8
+ # Using "announce" causes massive warnings on 1.9.2
9
+ @puts = true
10
+ @original_rubylib = ENV['RUBYLIB']
11
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
12
+ end
13
+
14
+ After do
15
+ ENV['RUBYLIB'] = @original_rubylib
16
+ end
data/lib/new_backup.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "new_backup/version"
2
+ require 'new_backup/datadog.rb'
3
+ require 'new_backup/main.rb'
4
+ require 'new_backup/myrds.rb'
5
+ require 'new_backup/mys3.rb'
6
+ require 'new_backup/mysqlcmds.rb'
7
+
8
+ module NewBackup
9
+ # Your code goes here...
10
+ end
@@ -0,0 +1,92 @@
1
+ =begin
2
+
3
+ = datadog.rb
4
+
5
+ *Copyright*:: (C) 2013 by Novu, LLC
6
+ *Author(s)*:: Tamara Temple <tamara.temple@novu.com>
7
+ *Since*:: 2013-05-01
8
+
9
+ == Description
10
+
11
+ Manage the connection and communication from the app to DataDog service.
12
+
13
+ == Usage
14
+
15
+ require '.../datadog.rb'
16
+
17
+ class MyClass
18
+
19
+ include DataDog
20
+ api_key = 'Your DD API Key'
21
+ dogger "Hi from MyClass!"
22
+
23
+ begin
24
+ # some operations
25
+ rescue Exception => e
26
+ dogger "Woops, an Error", :type => :error, :body => "#{e.class}: #{e}\n#{e.backtrace.join("\n")}"
27
+ end
28
+
29
+ # ... other class code
30
+
31
+ end
32
+
33
+ == Caveats
34
+
35
+ This module integrates with methadone, using it's logging features in
36
+ addition to sending the log message to data dog. This isn't
37
+ necessarily the most robust intermingling...
38
+
39
+ =end
40
+
41
+ require 'dogapi'
42
+ require 'methadone'
43
+
44
+ module NewBackup
45
+
46
+ module DataDog
47
+
48
+ include Methadone::CLILogging
49
+
50
+ @api_key = nil
51
+ @environment = (ENV['RAILS_ENV'].nil? || ENV['RAILS_ENV'].empty?) ? 'development' : ENV['RAILS_ENV']
52
+
53
+ module_function
54
+
55
+ def api_key
56
+ @api_key
57
+ end
58
+
59
+ def api_key=(api_key)
60
+ @api_key=api_key
61
+ end
62
+
63
+ def dogger(msg, options={})
64
+
65
+ return if msg.nil? || msg.empty?
66
+
67
+ if options[:type] == :error
68
+ error msg
69
+ else
70
+ info msg
71
+ end
72
+
73
+ return if @api_key.nil? || @api_key.empty?
74
+
75
+ @client ||= Datadog::Client.new(@api_key)
76
+
77
+ emit_options = {
78
+ :msg_title => msg,
79
+ :alert_type => (options[:type] == :error) ? 'Error' : 'Normal',
80
+ :tags => [ "host:#{`hostname`}", "env:#{@environment}" ],
81
+ :priority => 'normal',
82
+ :source => 'MyApps'}
83
+
84
+ body = options[:body] ||= msg
85
+
86
+ @client.emit_event(Dogapi::Event.new(body, emit_options))
87
+
88
+ end
89
+
90
+ end
91
+
92
+ end