rds_backup_service 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -32,6 +32,8 @@ First install the dependencies:
|
|
32
32
|
|
33
33
|
* Ruby 1.9, rake, and bundler
|
34
34
|
* [Redis][] (for [Resque][] workers), or [DelayedJob][] (library only for now)
|
35
|
+
* mysqldump
|
36
|
+
* gzip
|
35
37
|
|
36
38
|
The RDS Backup Service can be installed as a standalone application or as a
|
37
39
|
Rack middleware library.
|
@@ -112,9 +114,9 @@ Place some code like this in your Controller or Model:
|
|
112
114
|
job = RDSBackup::Job.new(params[:rds_id])
|
113
115
|
job.write_to_s3
|
114
116
|
Delayed::Job.enqueue RDSBackup::DelayedJob.new(job.rds_id, {
|
115
|
-
|
116
|
-
|
117
|
-
|
117
|
+
backup_id: job.backup_id,
|
118
|
+
requested: job.requested.to_s,
|
119
|
+
email: params[:email],
|
118
120
|
})
|
119
121
|
|
120
122
|
|
@@ -12,15 +12,15 @@ module RDSBackup
|
|
12
12
|
|
13
13
|
# Constructor.
|
14
14
|
# @param [String] rds_instance_id the ID of the RDS instance to backup
|
15
|
-
# @param [Hash]
|
16
|
-
# -
|
17
|
-
# -
|
18
|
-
# -
|
19
|
-
# - logger - a Logger object, for printing this job's ongoing status
|
20
|
-
def initialize(rds_instance_id,
|
21
|
-
@rds_id, @options = rds_instance_id,
|
22
|
-
@backup_id = options[
|
23
|
-
@requested = options[
|
15
|
+
# @param [Hash] optional_params optional additional parameters:
|
16
|
+
# - :email - an email address to be notified on completion
|
17
|
+
# - :backup_id - a unique ID for this job, if necessary
|
18
|
+
# - :requested - a Time when this job was requested
|
19
|
+
# - :logger - a Logger object, for printing this job's ongoing status
|
20
|
+
def initialize(rds_instance_id, optional_params = {})
|
21
|
+
@rds_id, @options = rds_instance_id, optional_params.symbolize_keys
|
22
|
+
@backup_id = options[:backup_id] || "%016x" % (rand * 0xffffffffffffffff)
|
23
|
+
@requested = options[:requested] ? Time.parse(options[:requested]) : Time.now
|
24
24
|
@status = 200
|
25
25
|
@message = "queued"
|
26
26
|
@files = []
|
@@ -31,7 +31,7 @@ module RDSBackup
|
|
31
31
|
@snapshot_id = "rds-backup-service-#{rds_id}-#{backup_id}"
|
32
32
|
@new_rds_id = "rds-backup-service-#{backup_id}"
|
33
33
|
@new_password = "#{backup_id}"
|
34
|
-
@account_name = options[
|
34
|
+
@account_name = options[:account_name]
|
35
35
|
end
|
36
36
|
|
37
37
|
# returns a JSON-format String representation of this backup job
|
@@ -227,7 +227,7 @@ module RDSBackup
|
|
227
227
|
|
228
228
|
# Writes a new status message to the log, and writes the job info to S3
|
229
229
|
def update_status(message, new_status = nil)
|
230
|
-
@log = @options[
|
230
|
+
@log = @options[:logger] || RDSBackup.default_logger(STDOUT)
|
231
231
|
@message = message
|
232
232
|
@status = new_status if new_status
|
233
233
|
@status == 200 ? (@log.info message) : (@log.error message)
|
@@ -236,8 +236,8 @@ module RDSBackup
|
|
236
236
|
|
237
237
|
# Sends a status email
|
238
238
|
def send_mail
|
239
|
-
return unless @options[
|
240
|
-
@log.info "Emailing #{@options[
|
239
|
+
return unless @options[:email]
|
240
|
+
@log.info "Emailing #{@options[:email]}..."
|
241
241
|
begin
|
242
242
|
RDSBackup::Email.new(self).send!
|
243
243
|
rescue Exception => e
|
@@ -13,9 +13,9 @@ module RDSBackup
|
|
13
13
|
# Attempts to send email through local ESMTP port 25.
|
14
14
|
# Raises an Exception on failure.
|
15
15
|
def send!
|
16
|
-
raise "job #{job.backup_id} has no email option" unless job.options[
|
16
|
+
raise "job #{job.backup_id} has no email option" unless job.options[:email]
|
17
17
|
main_text = body_text # define local variables for closure over Mail.new
|
18
|
-
recipients
|
18
|
+
recipients = job.options[:email]
|
19
19
|
header = "Backup of RDS #{job.rds_id} (job ID #{job.backup_id})"
|
20
20
|
mail = Mail.new do
|
21
21
|
from 'rdsbackupservice@mdsol.com'
|
@@ -46,7 +46,7 @@ module RDSBackup
|
|
46
46
|
logger.info "Queuing backup of RDS #{rds_id} in account #{job.account_name}"
|
47
47
|
job.write_to_s3
|
48
48
|
::Resque.enqueue_to(:backups, Job, job.rds_id, job.options.
|
49
|
-
merge({
|
49
|
+
merge({backup_id: job.backup_id, requested: job.requested.to_s}))
|
50
50
|
|
51
51
|
[ 201, # return HTTP_CREATED, and
|
52
52
|
{ 'Location' => job.status_url }, # point to the S3 document
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rds_backup_service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -214,7 +214,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
214
214
|
version: '0'
|
215
215
|
segments:
|
216
216
|
- 0
|
217
|
-
hash:
|
217
|
+
hash: -2653342598528617899
|
218
218
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
219
219
|
none: false
|
220
220
|
requirements:
|
@@ -223,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
223
223
|
version: '0'
|
224
224
|
segments:
|
225
225
|
- 0
|
226
|
-
hash:
|
226
|
+
hash: -2653342598528617899
|
227
227
|
requirements: []
|
228
228
|
rubyforge_project: rds_backup_service
|
229
229
|
rubygems_version: 1.8.24
|