rds_backup_service 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/config/{settings.yml → settings.example.yml} +10 -0
- data/lib/rds_backup_service/config.rb +5 -1
- data/lib/rds_backup_service/model/backup_job.rb +1 -0
- data/lib/rds_backup_service/model/email.rb +16 -10
- data/lib/rds_backup_service/rds_backup_service.rb +2 -0
- data/lib/rds_backup_service/version.rb +1 -1
- metadata +4 -4
data/.gitignore
CHANGED
@@ -24,3 +24,13 @@ backup_bucket: rdsbackups
|
|
24
24
|
# defaults to Ruby's Dir.tmpdir
|
25
25
|
|
26
26
|
#tmp_dir: "/tmp"
|
27
|
+
|
28
|
+
# The "From" address in sent emails
|
29
|
+
# defaults to rdsbackups@localhost
|
30
|
+
|
31
|
+
#email_from: "rdsbackups@localhost"
|
32
|
+
|
33
|
+
# Use TLS when sending email over ESMTP?
|
34
|
+
# defaults to false
|
35
|
+
|
36
|
+
#email_tls: false
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'fileutils'
|
1
2
|
module RDSBackup
|
2
3
|
# models logic for post-configuration setup
|
3
4
|
module Config
|
@@ -9,6 +10,7 @@ module RDSBackup
|
|
9
10
|
# Configuration
|
10
11
|
log.info "Scanning system..."
|
11
12
|
(system = Ohai::System.new).all_plugins
|
13
|
+
FileUtils.rm_f("1")
|
12
14
|
log.info "Reading config files..."
|
13
15
|
settings = RDSBackup.settings
|
14
16
|
ec2_group_name = settings['ec2_security_group']
|
@@ -54,7 +56,9 @@ module RDSBackup
|
|
54
56
|
log.warn "Not running in EC2 - open RDS groups to this host!"
|
55
57
|
else
|
56
58
|
unless this_host = ec2.servers.get(system[:ec2][:instance_id])
|
57
|
-
|
59
|
+
accts = RDSBackup.read_accounts.select{|id,acc| acc[:service] == 'Compute'}
|
60
|
+
raise "At least one S3 account must be defined" if accts.empty?
|
61
|
+
log.warn "Not running in EC2 account #{accts.first[0]}!"
|
58
62
|
else
|
59
63
|
log.info "Running in EC2. Current Security Groups = #{this_host.groups}"
|
60
64
|
unless this_host.groups.include? ec2_group_name
|
@@ -240,6 +240,7 @@ module RDSBackup
|
|
240
240
|
@log.info "Emailing #{@options[:email]}..."
|
241
241
|
begin
|
242
242
|
RDSBackup::Email.new(self).send!
|
243
|
+
@log.info "Email sent to #{@options[:email]} for job #{backup_id}"
|
243
244
|
rescue Exception => e
|
244
245
|
@log.warn "Error sending email: #{e.message.split("\n").first}"
|
245
246
|
end
|
@@ -3,31 +3,37 @@ module RDSBackup
|
|
3
3
|
# an email representation of a Job, that can send itself to recipients.
|
4
4
|
class Email
|
5
5
|
|
6
|
-
attr_reader :job
|
6
|
+
attr_reader :job, :settings
|
7
7
|
|
8
8
|
# constructor - requires an RDSBackup::Job
|
9
9
|
def initialize(backup_job)
|
10
|
-
@job = backup_job
|
10
|
+
@job, @settings = backup_job, RDSBackup.settings
|
11
|
+
use_tls = settings['email_tls'] != 'false'
|
12
|
+
Mail.defaults do
|
13
|
+
delivery_method :smtp, {enable_starttls_auto: use_tls}
|
14
|
+
end
|
11
15
|
end
|
12
16
|
|
13
17
|
# Attempts to send email through local ESMTP port 25.
|
14
18
|
# Raises an Exception on failure.
|
15
19
|
def send!
|
16
20
|
raise "job #{job.backup_id} has no email option" unless job.options[:email]
|
17
|
-
|
18
|
-
|
19
|
-
|
21
|
+
# define local variables for closure over Mail.new
|
22
|
+
from_address = settings['email_from']
|
23
|
+
to_address = job.options[:email]
|
24
|
+
subject_text = "Backup of RDS #{job.rds_id} (job ID #{job.backup_id})"
|
25
|
+
body_text = body
|
20
26
|
mail = Mail.new do
|
21
|
-
from
|
22
|
-
to
|
23
|
-
subject
|
24
|
-
body "#{
|
27
|
+
from from_address
|
28
|
+
to to_address
|
29
|
+
subject subject_text
|
30
|
+
body "#{body_text}\n"
|
25
31
|
end
|
26
32
|
mail.deliver!
|
27
33
|
end
|
28
34
|
|
29
35
|
# defines the body of a Job's status email
|
30
|
-
def
|
36
|
+
def body
|
31
37
|
msg = "Hello.\n\n"
|
32
38
|
if job.status == 200
|
33
39
|
msg += "Your backup of database #{job.rds_id} is complete.\n"+
|
@@ -43,6 +43,8 @@ module RDSBackup
|
|
43
43
|
'rds_security_group' => 'rds-backup-service',
|
44
44
|
'ec2_security_group' => 'rds-backup-service',
|
45
45
|
'tmp_dir' => Dir.tmpdir,
|
46
|
+
'email_from' => 'rdsbackups@localhost',
|
47
|
+
'email_tls' => 'false',
|
46
48
|
}.merge(YAML::load(
|
47
49
|
File.read(settings_file || "./config/settings.yml")))
|
48
50
|
end
|
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.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -188,7 +188,7 @@ files:
|
|
188
188
|
- Rakefile
|
189
189
|
- config.ru
|
190
190
|
- config/accounts.example.yml
|
191
|
-
- config/settings.yml
|
191
|
+
- config/settings.example.yml
|
192
192
|
- lib/rds_backup_service.rb
|
193
193
|
- lib/rds_backup_service/config.rb
|
194
194
|
- lib/rds_backup_service/model/backup_job.rb
|
@@ -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: 1295335590809769143
|
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: 1295335590809769143
|
227
227
|
requirements: []
|
228
228
|
rubyforge_project: rds_backup_service
|
229
229
|
rubygems_version: 1.8.24
|