new_backup 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- new_backup (1.0.3)
4
+ new_backup (1.0.4)
5
5
  RunIt
6
6
  dogapi
7
7
  fog
@@ -59,7 +59,7 @@ module NewBackup
59
59
  def api_key=(api_key)
60
60
  $dogger ||= DataDogger.new
61
61
  $dogger.api_key=api_key
62
- debug "#{self.class}##{__method__}@#{__LINE__}: $dogger.api_key: #{$dogger.api_key}"
62
+ debug "#{self.class}##{__method__}@#{File.basename(__FILE__)}:#{__LINE__}: $dogger.api_key: #{$dogger.api_key}"
63
63
  end
64
64
 
65
65
  def dogger(msg, options={})
@@ -71,12 +71,12 @@ module NewBackup
71
71
  else
72
72
  info msg
73
73
  end
74
- debug "#{self.class}##{__method__}@#{__LINE__}: $dogger exists? #{$dogger.inspect}"
75
- debug "#{self.class}##{__method__}@#{__LINE__}: $dogger.api_key: #{$dogger.api_key}"
74
+ debug "#{self.class}##{__method__}@#{File.basename(__FILE__)}:#{__LINE__}: $dogger exists? #{$dogger.inspect}"
75
+ debug "#{self.class}##{__method__}@#{File.basename(__FILE__)}:#{__LINE__}: $dogger.api_key: #{$dogger.api_key}"
76
76
  return if $dogger.api_key.nil? || $dogger.api_key.empty?
77
77
 
78
78
  $dogger.client ||= Dogapi::Client.new($dogger.api_key)
79
- debug "#{self.class}##{__method__}@#{__LINE__}: $dogger.client: #{$dogger.client.inspect}"
79
+ debug "#{self.class}##{__method__}@#{File.basename(__FILE__)}:#{__LINE__}: $dogger.client: #{$dogger.client.inspect}"
80
80
 
81
81
  $dogger.environment ||= (ENV['RAILS_ENV'].nil? || ENV['RAILS_ENV'].empty?) ? 'development' : ENV['RAILS_ENV']
82
82
 
@@ -93,7 +93,7 @@ module NewBackup
93
93
  body = options[:body] ||= msg
94
94
 
95
95
  this_event = Dogapi::Event.new(body, emit_options)
96
- debug "#{self.class}##{__method__}@#{__LINE__}: emit_options: #{emit_options.to_yaml}\nbody: #{body}\nthis_event: #{this_event.inspect}"
96
+ debug "#{self.class}##{__method__}@#{File.basename(__FILE__)}:#{__LINE__}: emit_options: #{emit_options.to_yaml}\nbody: #{body}\nthis_event: #{this_event.inspect}"
97
97
  $dogger.client.emit_event(this_event)
98
98
 
99
99
  end
@@ -42,7 +42,7 @@ module NewBackup
42
42
  # Initialize the Main loop, processing options and putting them in the right form
43
43
  def initialize(opts={})
44
44
 
45
- debug "#{self.class}##{__method__}:#{__LINE__}: original opts: #{opts.to_yaml}"
45
+ debug "#{self.class}##{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: original opts: #{opts.to_yaml}"
46
46
 
47
47
  if opts["config_file"] && File.exists?(opts["config_file"])
48
48
  converged_opts = DEFAULT_OPTIONS.merge(YAML.load(File.read(opts["config_file"]))).merge(opts)
@@ -52,7 +52,7 @@ module NewBackup
52
52
 
53
53
  converged_opts["timestamp"] = Time.now.strftime(converged_opts["timestamp_format"])
54
54
 
55
- debug "#{self.class}##{__method__}:#{__LINE__}: converged_opts: #{converged_opts.to_yaml}"
55
+ debug "#{self.class}##{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: converged_opts: #{converged_opts.to_yaml}"
56
56
 
57
57
  missing_options = REQUIRED_OPTIONS.select {|o| o unless converged_opts.has_key?(o)}
58
58
  raise "Missing required options #{missing_options.inspect} in either configuration or command line" if missing_options.count > 0
@@ -94,8 +94,7 @@ module NewBackup
94
94
  :nos3 => converged_opts["nos3"]
95
95
  }
96
96
 
97
-
98
- debug "Options:\n#{@options.to_yaml}"
97
+ debug "#{self.class}##{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: Options:\n#{@options.to_yaml}"
99
98
 
100
99
  # Fill in the hidden values after showing the options
101
100
  @options[:aws][:access_key] = converged_opts["aws_access_key_id"]
@@ -103,11 +102,9 @@ module NewBackup
103
102
  @options[:mysql][:password] = converged_opts["mysql_password"]
104
103
  @options[:datadog][:api_key] = converged_opts["datadog_apikey"]
105
104
 
106
- debug @options.to_yaml
107
-
108
105
  $dogger = DataDogger.new
109
106
  $dogger.api_key=@options[:datadog][:api_key] unless @options[:debug]
110
- debug "#{self.class}##{__method__}@#{__LINE__}: $dogger.api_key: #{$dogger.api_key}"
107
+ debug "#{self.class}##{__method__}@#{File.basename(__FILE__)}:#{__LINE__}: $dogger.api_key: #{$dogger.api_key}"
111
108
 
112
109
  end
113
110
 
@@ -115,13 +112,13 @@ module NewBackup
115
112
  dogger "Beginning RDS-S3-Backup"
116
113
  begin
117
114
 
118
- raise "#{self.class}##{__method__}:#{__LINE__}: Dump directory #{@options[:dump_directory]} does not exist!" unless File.directory?(@options[:dump_directory])
115
+ raise "#{self.class}##{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: Dump directory #{@options[:dump_directory]} does not exist!" unless File.directory?(@options[:dump_directory])
119
116
 
120
117
 
121
118
  raw_file = File.join(File.expand_path(@options[:dump_directory]),save_file_name)
122
- debug "#{self.class}##{__method__}:#{__LINE__}: raw_file: #{raw_file}"
119
+ debug "#{self.class}##{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: raw_file: #{raw_file}"
123
120
  clean_file = File.join(File.expand_path(@options[:dump_directory]),clean_file_name)
124
- debug "#{self.class}##{__method__}:#{__LINE__}: clean_file: #{clean_file}"
121
+ debug "#{self.class}##{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: clean_file: #{clean_file}"
125
122
 
126
123
  if (@options[:nords])
127
124
  info "Not running RDS"
@@ -134,11 +131,8 @@ module NewBackup
134
131
  else
135
132
 
136
133
  NewBackup::MyRds.new(@options).restore do |db|
137
- info "Dump raw database"
138
134
  db.dump(raw_file)
139
- info "Obfuscate database"
140
135
  db.obfuscate
141
- info "Dump clean database"
142
136
  db.dump(clean_file)
143
137
  end
144
138
  end
@@ -150,14 +144,11 @@ module NewBackup
150
144
  s3 = NewBackup::MyS3.new(@options)
151
145
  s3.connect do |connection|
152
146
  s3.connect_bucket(connection, @options[:s3][:raw_bucket]) do |bucket|
153
- info "Save raw db dump"
154
147
  s3.put_file bucket, raw_file
155
- info "Prune excess backups"
156
148
  s3.prune bucket, @options[:s3][:dump_ttl]
157
149
  end
158
150
 
159
151
  s3.connect_bucket(connection, @options[:s3][:clean_bucket]) do |bucket|
160
- info "Save cleaned db dump"
161
152
  s3.put_file bucket, clean_file
162
153
  end
163
154
  end
@@ -168,7 +159,7 @@ module NewBackup
168
159
  dogger "Fatal error in #{self.class}#run: #{e.class}: #{e}" ,
169
160
  :type => :error,
170
161
  :body => "Backtrace:\n#{e.backtrace.join("\n")}"
171
- debug e.backtrace.join("\n")
162
+ debug "#{self.class}##{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: Backtrace:\n #{e.backtrace.join("\n")}"
172
163
  raise e
173
164
 
174
165
 
@@ -25,7 +25,7 @@ module NewBackup
25
25
 
26
26
  # Initialize the class with options
27
27
  def initialize(options={})
28
- debug "Options: #{options}"
28
+ debug "#{self.class}##{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: Options: #{options}"
29
29
  @options = options
30
30
  end
31
31
 
@@ -62,8 +62,7 @@ module NewBackup
62
62
 
63
63
  # Get the RDS server
64
64
  def get_rds(connection)
65
- debug "rds instance_id: #{@options[:rds][:instance_id]}"
66
- debug "Connection servers: #{connection.servers}"
65
+ debug "#{self.class}##{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: rds instance_id: #{@options[:rds][:instance_id]}\nConnection servers: #{connection.servers}"
67
66
  rds_server = connection.servers.get(@options[:rds][:instance_id])
68
67
  raise "No RDS server!" if rds_server.nil?
69
68
  yield rds_server
@@ -76,7 +75,7 @@ module NewBackup
76
75
  rds_server.snapshots.new(:id => snap_name).save
77
76
  new_snapshot = rds_server.snapshots.get(snap_name)
78
77
  1.upto(MAX_TRIES) do |i|
79
- debug "waiting for new snapshot, try ##{i}"
78
+ debug "#{self.class}##{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: waiting for new snapshot, try ##{i}"
80
79
  new_snapshot.wait_for { ready? }
81
80
  end
82
81
 
@@ -100,7 +99,7 @@ module NewBackup
100
99
  )
101
100
  backup_server = connection.servers.get(backup_server_id)
102
101
  1.upto(MAX_TRIES) do |i|
103
- debug "waiting for backup server, try ##{i}"
102
+ debug "#{self.class}##{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: waiting for backup server, try ##{i}"
104
103
  backup_server.wait_for { ready? }
105
104
  end
106
105
 
@@ -124,12 +123,16 @@ module NewBackup
124
123
 
125
124
  # Return the snapshot name
126
125
  def snap_name
127
- "s3-dump-snap-#{@options[:timestamp]}".tap{|t| debug "Snap Name: #{t}"}
126
+ "s3-dump-snap-#{@options[:timestamp]}".tap do |t|
127
+ debug "#{self.class}##{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: Snap Name: #{t}"
128
+ end
128
129
  end
129
130
 
130
131
  # Return the backup server id
131
132
  def backup_server_id
132
- "#{@options[:rds][:instance_id]}-s3-dump-server-#{@options[:timestamp]}".tap{|t| debug "Backup Server ID: #{t}"}
133
+ "#{@options[:rds][:instance_id]}-s3-dump-server-#{@options[:timestamp]}".tap do |t|
134
+ debug "#{self.class}##{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: Backup Server ID: #{t}"
135
+ end
133
136
  end
134
137
 
135
138
 
@@ -56,7 +56,8 @@ module NewBackup
56
56
  # *&block*:: block passed to evaluate in context of bucket
57
57
  # (If no block given simply return the bucket pointer.)
58
58
  def connect_bucket(connection, bucket_name, &block)
59
- debug "#{self.class}##{__method__}:#{__LINE__}: connection: #{connection.inspect}"
59
+ debug "#{self.class}##{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: connection: #{connection.inspect}"
60
+ info "Connecting to #{bucket_name}"
60
61
  buckets = connection.directories
61
62
  raise "No buckets!" if buckets.nil? || buckets.empty?
62
63
  bucket = connection.directories.get(bucket_name)
@@ -79,6 +80,7 @@ module NewBackup
79
80
  # bucket:: directory where to put the file
80
81
  # fn:: name of file to upload (gzipped)
81
82
  def put_file(bucket,fn)
83
+ info "Saving #{fn} to #{bucket.key}"
82
84
  s3_fn = File.join(@options[:s3][:prefix], File.basename(fn))
83
85
  options = {
84
86
  :key => s3_fn,
@@ -105,6 +107,7 @@ module NewBackup
105
107
  return if files.nil? || files.empty?
106
108
 
107
109
  if files.count > keep
110
+ info "Pruning down to #{keep} files"
108
111
  files.sort {|x,y| x.last_modified <=> y.last_modified}.
109
112
  take(files.count - keep).
110
113
  map(&:destroy)
@@ -39,7 +39,7 @@ module NewBackup
39
39
  :gzip => get_command('gzip')
40
40
  }
41
41
 
42
- debug "#{self.class}##{__method__}:#{__LINE__}: @commands: #{@commands}"
42
+ debug "#{self.class}##{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: @commands: #{@commands}"
43
43
 
44
44
  end
45
45
 
@@ -55,12 +55,13 @@ module NewBackup
55
55
  cmd << ">"
56
56
  cmd << save_file
57
57
 
58
- debug "#{self.class}##{__method__}:#{__LINE__}: cmd = #{cmd.join(" ")}"
58
+ debug "#{self.class}##{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: cmd = #{cmd.join(" ")}"
59
59
 
60
60
  saver = RunIt.new cmd.join(" ")
61
+ info "dumping #{self.database} to #{save_file}"
61
62
  saver.run
62
63
  raise "#{self.class}#save error: #{saver.result.exitstatus}: #{saver.error.inspect}" unless saver.result.success?
63
- debug "#{self.class}##{__method__}:#{__LINE__}: saver.output: #{saver.output}"
64
+ debug "#{self.class}##{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: saver.output: #{saver.output}"
64
65
  end
65
66
 
66
67
  def obfuscate
@@ -74,11 +75,12 @@ module NewBackup
74
75
  cmd << "<"
75
76
  cmd << self.obfuscate_script
76
77
 
77
- debug "#{self.class}##{__method__}:#{__LINE__}: cmd= #{cmd.join(" ")}"
78
+ debug "#{self.class}##{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: cmd= #{cmd.join(" ")}"
78
79
  obfuscator = RunIt.new cmd.join(" ")
80
+ info "Running #{self.obfuscate_script} on #{self.database}"
79
81
  obfuscator.run
80
- raise "#{self.class}##{__method__}:#{__LINE__}: error: #{obfuscator.result.exitstatus}: #{obfuscator.error.inspect}" unless obfuscator.result.success?
81
- debug "#{self.class}##{__method__}:#{__LINE__}: obfuscator.output: #{obfuscator.output}"
82
+ raise "#{self.class}##{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: error: #{obfuscator.result.exitstatus}: #{obfuscator.error.inspect}" unless obfuscator.result.success?
83
+ debug "#{self.class}##{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: obfuscator.output: #{obfuscator.output}"
82
84
  end
83
85
 
84
86
 
@@ -11,7 +11,7 @@
11
11
 
12
12
 
13
13
  module NewBackup
14
- VERSION = "1.0.3"
14
+ VERSION = "1.0.4"
15
15
  DESCRIPTION = "Backup an RDS database instance to S3, and create and obfuscated version"
16
16
  SUMMARY = DESCRIPTION
17
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: new_backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
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-05-23 00:00:00.000000000 Z
12
+ date: 2013-05-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
@@ -205,7 +205,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
205
205
  version: '0'
206
206
  segments:
207
207
  - 0
208
- hash: -1819741959940293617
208
+ hash: 1620806548271440799
209
209
  required_rubygems_version: !ruby/object:Gem::Requirement
210
210
  none: false
211
211
  requirements:
@@ -214,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
214
  version: '0'
215
215
  segments:
216
216
  - 0
217
- hash: -1819741959940293617
217
+ hash: 1620806548271440799
218
218
  requirements: []
219
219
  rubyforge_project:
220
220
  rubygems_version: 1.8.24