backup 2.3.0.3 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -2
- data/README.textile +40 -11
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/backup.gemspec +9 -2
- data/generators/backup/templates/config/backup.rb +31 -2
- data/lib/backup.rb +9 -14
- data/lib/backup/adapters/archive.rb +4 -0
- data/lib/backup/adapters/base.rb +20 -4
- data/lib/backup/adapters/custom.rb +5 -0
- data/lib/backup/adapters/mysql.rb +3 -0
- data/lib/backup/adapters/postgresql.rb +3 -0
- data/lib/backup/configuration/base.rb +1 -1
- data/lib/backup/configuration/helpers.rb +7 -0
- data/lib/backup/configuration/mail.rb +26 -0
- data/lib/backup/configuration/smtp.rb +19 -0
- data/lib/backup/mail/base.rb +89 -0
- data/lib/backup/mail/mail.txt +7 -0
- data/setup/backup.rb +30 -1
- metadata +16 -2
data/CHANGELOG
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATCH
|
2
|
-
=== 2.3.
|
2
|
+
=== 2.3.0.3 ====================================
|
3
3
|
|
4
|
-
|
4
|
+
- Small bug was patched. Error would occur when a list of triggers should be shown
|
5
5
|
|
6
6
|
|
7
7
|
BIG UPDATE
|
data/README.textile
CHANGED
@@ -4,27 +4,56 @@ h2. A Backup Ruby Gem
|
|
4
4
|
|
5
5
|
Backup is a Ruby Gem written for Unix and Rails environments. It can be used both with and without the Ruby on Rails framework! This gem offers a quick and simple solution to backing up databases such as MySQL/PostgreSQL and Files/Folders. All backups can be transferred to Amazon S3 or any remote server you have access to, using either SCP, SFTP or regular FTP. Backup handles Compression, Archiving, Encryption and Backup Cleaning (Cycling).
|
6
6
|
|
7
|
-
h2.
|
7
|
+
h2. Email Notification as of 2.3.1!
|
8
8
|
|
9
|
-
|
9
|
+
The first thing you will notice when you re-generate a new copy of the default "backup.rb" template, will be this:
|
10
10
|
|
11
|
-
|
11
|
+
bc.. notifier_settings do
|
12
|
+
|
13
|
+
to "example1@gmail.com"
|
14
|
+
from "example2@gmail.com"
|
15
|
+
|
16
|
+
smtp do
|
17
|
+
host "smtp.gmail.com"
|
18
|
+
port "587"
|
19
|
+
username "example1@gmail.com"
|
20
|
+
password "example1password"
|
21
|
+
authentication "plain"
|
22
|
+
domain "localhost.localdomain"
|
23
|
+
tls true
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
12
27
|
|
13
|
-
bc. sudo backup --find [trigger]
|
14
28
|
|
15
|
-
Rails Environment:
|
16
29
|
|
17
|
-
bc. rake backup:find trigger='trigger'
|
18
30
|
|
19
|
-
*Finders in Table Format*
|
20
31
|
|
21
|
-
|
32
|
+
p. This is disabled by default. You must uncomment it. Once you uncomment it, fill in your credentials. By default I setup a "gmail"-based configuration.
|
33
|
+
Once you've filled in your smtp credentials, all you have to do is set "notify false" to "notify true" inside each *backup* block you wish to be notified of on each successful backup.
|
34
|
+
|
35
|
+
|
36
|
+
bc.. backup 'mysql-backup-s3' do
|
37
|
+
|
38
|
+
adapter :mysql do
|
39
|
+
...
|
40
|
+
end
|
41
|
+
|
42
|
+
storage :s3 do
|
43
|
+
...
|
44
|
+
end
|
45
|
+
|
46
|
+
keep_backups 25
|
47
|
+
encrypt_with_password 'password'
|
48
|
+
notify false # set this to "true"
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
|
22
53
|
|
23
|
-
bc. sudo backup --table --find [trigger]
|
24
54
|
|
25
|
-
Rails Environment:
|
26
55
|
|
27
|
-
|
56
|
+
p. And that's it! Now after every 'mysql-backup-s3', given you've provided the correct smtp configuration, you will be notified of each backup that has been created by email!
|
28
57
|
|
29
58
|
|
30
59
|
h2. Backup goes independent with the release of version 2.3.0! Ruby on Rails is no longer "required"!
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.3.
|
1
|
+
2.3.1
|
data/backup.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{backup}
|
8
|
-
s.version = "2.3.
|
8
|
+
s.version = "2.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael van Rooijen"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-01-08}
|
13
13
|
s.default_executable = %q{backup}
|
14
14
|
s.description = %q{
|
15
15
|
Backup is a Ruby Gem written for Unix and Rails environments. It can be used both with and without the
|
@@ -48,11 +48,15 @@ Gem::Specification.new do |s|
|
|
48
48
|
"lib/backup/configuration/adapter_options.rb",
|
49
49
|
"lib/backup/configuration/base.rb",
|
50
50
|
"lib/backup/configuration/helpers.rb",
|
51
|
+
"lib/backup/configuration/mail.rb",
|
52
|
+
"lib/backup/configuration/smtp.rb",
|
51
53
|
"lib/backup/configuration/storage.rb",
|
52
54
|
"lib/backup/connection/s3.rb",
|
53
55
|
"lib/backup/environment/base.rb",
|
54
56
|
"lib/backup/environment/rails.rb",
|
55
57
|
"lib/backup/environment/unix.rb",
|
58
|
+
"lib/backup/mail/base.rb",
|
59
|
+
"lib/backup/mail/mail.txt",
|
56
60
|
"lib/backup/record/ftp.rb",
|
57
61
|
"lib/backup/record/s3.rb",
|
58
62
|
"lib/backup/record/scp.rb",
|
@@ -82,6 +86,7 @@ Gem::Specification.new do |s|
|
|
82
86
|
s.add_runtime_dependency(%q<activerecord>, [">= 2.3.5"])
|
83
87
|
s.add_runtime_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
|
84
88
|
s.add_runtime_dependency(%q<hirb>, [">= 0.2.9"])
|
89
|
+
s.add_runtime_dependency(%q<pony>, [">= 0.5"])
|
85
90
|
else
|
86
91
|
s.add_dependency(%q<aws-s3>, [">= 0.6.2"])
|
87
92
|
s.add_dependency(%q<net-ssh>, [">= 2.0.15"])
|
@@ -90,6 +95,7 @@ Gem::Specification.new do |s|
|
|
90
95
|
s.add_dependency(%q<activerecord>, [">= 2.3.5"])
|
91
96
|
s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
|
92
97
|
s.add_dependency(%q<hirb>, [">= 0.2.9"])
|
98
|
+
s.add_dependency(%q<pony>, [">= 0.5"])
|
93
99
|
end
|
94
100
|
else
|
95
101
|
s.add_dependency(%q<aws-s3>, [">= 0.6.2"])
|
@@ -99,6 +105,7 @@ Gem::Specification.new do |s|
|
|
99
105
|
s.add_dependency(%q<activerecord>, [">= 2.3.5"])
|
100
106
|
s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
|
101
107
|
s.add_dependency(%q<hirb>, [">= 0.2.9"])
|
108
|
+
s.add_dependency(%q<pony>, [">= 0.5"])
|
102
109
|
end
|
103
110
|
end
|
104
111
|
|
@@ -40,10 +40,35 @@
|
|
40
40
|
#
|
41
41
|
# The combination of these, however, do not matter! So experiment with it.
|
42
42
|
#
|
43
|
+
# You can also let Backup notify you by email on successfully created backups.
|
44
|
+
# - Just uncomment the block of code below (notifier_settings) and fill in your credentials.
|
45
|
+
# - Then for set "notify" to "true" in each (backup) block you wish to be notified of.
|
46
|
+
#
|
43
47
|
# For more information on "Backup", please refer to the wiki on github
|
44
48
|
# http://wiki.github.com/meskyanichi/backup/configuration-file
|
45
49
|
|
46
50
|
|
51
|
+
# Notifier
|
52
|
+
# Uncomment this if you want to enable notification by email on successful backup runs
|
53
|
+
# You will also have to set "notify true" inside each backup block below to enable it for that particular backup
|
54
|
+
# notifier_settings do
|
55
|
+
#
|
56
|
+
# to "example1@gmail.com"
|
57
|
+
# from "example2@gmail.com"
|
58
|
+
#
|
59
|
+
# smtp do
|
60
|
+
# host "smtp.gmail.com"
|
61
|
+
# port "587"
|
62
|
+
# username "example1@gmail.com"
|
63
|
+
# password "example1password"
|
64
|
+
# authentication "plain"
|
65
|
+
# domain "localhost.localdomain"
|
66
|
+
# tls true
|
67
|
+
# end
|
68
|
+
#
|
69
|
+
# end
|
70
|
+
|
71
|
+
|
47
72
|
# Initialize with:
|
48
73
|
# rake backup:run trigger='mysql-backup-s3'
|
49
74
|
backup 'mysql-backup-s3' do
|
@@ -72,6 +97,7 @@ backup 'mysql-backup-s3' do
|
|
72
97
|
|
73
98
|
keep_backups 25
|
74
99
|
encrypt_with_password 'password'
|
100
|
+
notify false
|
75
101
|
|
76
102
|
end
|
77
103
|
|
@@ -103,7 +129,8 @@ backup 'postgresql-backup-scp' do
|
|
103
129
|
|
104
130
|
keep_backups :all
|
105
131
|
encrypt_with_password false
|
106
|
-
|
132
|
+
notify false
|
133
|
+
|
107
134
|
end
|
108
135
|
|
109
136
|
|
@@ -125,7 +152,8 @@ backup 'archive-backup-ftp' do
|
|
125
152
|
|
126
153
|
keep_backups 10
|
127
154
|
encrypt_with_password false
|
128
|
-
|
155
|
+
notify false
|
156
|
+
|
129
157
|
end
|
130
158
|
|
131
159
|
|
@@ -149,5 +177,6 @@ backup 'custom-backup-sftp' do
|
|
149
177
|
|
150
178
|
keep_backups :all
|
151
179
|
encrypt_with_password 'password'
|
180
|
+
notify false
|
152
181
|
|
153
182
|
end
|
data/lib/backup.rb
CHANGED
@@ -1,27 +1,24 @@
|
|
1
|
-
#
|
2
1
|
# Load Gems
|
3
|
-
#
|
4
2
|
require 'net/ssh'
|
5
3
|
require 'net/scp'
|
6
4
|
require 'net/ftp'
|
7
5
|
require 'net/sftp'
|
8
6
|
require 'aws/s3'
|
7
|
+
require 'pony'
|
9
8
|
require 'hirb'
|
10
9
|
|
11
|
-
#
|
12
10
|
# Load Environments
|
13
|
-
#
|
14
11
|
require 'backup/environment/base'
|
15
12
|
require 'backup/environment/unix'
|
16
13
|
require 'backup/environment/rails'
|
17
14
|
|
18
|
-
#
|
19
15
|
# Load Configuration
|
20
|
-
#
|
21
16
|
require 'backup/configuration/base'
|
22
17
|
require 'backup/configuration/adapter'
|
23
18
|
require 'backup/configuration/adapter_options'
|
24
19
|
require 'backup/configuration/storage'
|
20
|
+
require 'backup/configuration/mail'
|
21
|
+
require 'backup/configuration/smtp'
|
25
22
|
require 'backup/configuration/helpers'
|
26
23
|
|
27
24
|
# Include the Configuration adn Environment Helpers
|
@@ -39,31 +36,29 @@ if File.exist?(File.join(BACKUP_PATH, 'config', 'backup.rb'))
|
|
39
36
|
require File.join(BACKUP_PATH, 'config', 'backup.rb')
|
40
37
|
end
|
41
38
|
|
42
|
-
#
|
39
|
+
# Load Mail Notifier
|
40
|
+
require 'backup/mail/base'
|
41
|
+
|
42
|
+
# Set Mail Configuration (extracted from the backup.rb configuration file) inside the Mail Class
|
43
|
+
Backup::Mail::Base.setup(@mail_configuration)
|
44
|
+
|
43
45
|
# Load Adapters
|
44
|
-
#
|
45
46
|
require 'backup/adapters/base'
|
46
47
|
require 'backup/adapters/mysql'
|
47
48
|
require 'backup/adapters/postgresql'
|
48
49
|
require 'backup/adapters/archive'
|
49
50
|
require 'backup/adapters/custom'
|
50
51
|
|
51
|
-
#
|
52
52
|
# Load Connectors
|
53
|
-
#
|
54
53
|
require 'backup/connection/s3'
|
55
54
|
|
56
|
-
#
|
57
55
|
# Load Storage
|
58
|
-
#
|
59
56
|
require 'backup/storage/s3'
|
60
57
|
require 'backup/storage/scp'
|
61
58
|
require 'backup/storage/ftp'
|
62
59
|
require 'backup/storage/sftp'
|
63
60
|
|
64
|
-
#
|
65
61
|
# Backup Recorders
|
66
|
-
#
|
67
62
|
require 'backup/record/s3'
|
68
63
|
require 'backup/record/scp'
|
69
64
|
require 'backup/record/ftp'
|
@@ -25,6 +25,7 @@ module Backup
|
|
25
25
|
encrypt
|
26
26
|
store
|
27
27
|
record
|
28
|
+
notify
|
28
29
|
ensure
|
29
30
|
remove_tmp_files
|
30
31
|
end
|
@@ -36,8 +37,10 @@ module Backup
|
|
36
37
|
def targz
|
37
38
|
files = procedure.get_adapter_configuration.attributes['files']
|
38
39
|
if files.is_a?(Array)
|
40
|
+
puts system_messages[:archiving]; puts system_messages[:compressing]
|
39
41
|
%x{ tar -czf #{File.join(tmp_path, compressed_file)} #{files.map{|f| f.gsub(' ', '\ ')}.join(' ')} }
|
40
42
|
elsif files.is_a?(String)
|
43
|
+
puts system_messages[:archiving]; puts system_messages[:compressing]
|
41
44
|
%x{ tar -czf #{File.join(tmp_path, compressed_file)} #{files.gsub(' ', '\ ')} }
|
42
45
|
end
|
43
46
|
end
|
@@ -45,6 +48,7 @@ module Backup
|
|
45
48
|
# Encrypts the Archive
|
46
49
|
def encrypt
|
47
50
|
if encrypt_with_password.is_a?(String)
|
51
|
+
puts system_messages[:encrypting]
|
48
52
|
%x{ openssl enc -des-cbc -in #{File.join(tmp_path, compressed_file)} -out #{File.join(tmp_path, encrypted_file)} -k #{encrypt_with_password} }
|
49
53
|
self.final_file = encrypted_file
|
50
54
|
end
|
data/lib/backup/adapters/base.rb
CHANGED
@@ -43,10 +43,10 @@ module Backup
|
|
43
43
|
# Remote Server (SFTP)
|
44
44
|
def store
|
45
45
|
case procedure.storage_name.to_sym
|
46
|
-
when :s3
|
47
|
-
when :scp
|
48
|
-
when :ftp
|
49
|
-
when :sftp
|
46
|
+
when :s3 then Backup::Storage::S3.new(self)
|
47
|
+
when :scp then Backup::Storage::SCP.new(self)
|
48
|
+
when :ftp then Backup::Storage::FTP.new(self)
|
49
|
+
when :sftp then Backup::Storage::SFTP.new(self)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -72,6 +72,22 @@ module Backup
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
# Delivers a notification by email regarding the successfully stored backup
|
76
|
+
def notify
|
77
|
+
if Backup::Mail::Base.setup?
|
78
|
+
Backup::Mail::Base.notify!(self)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def system_messages
|
83
|
+
{ :compressing => "Compressing backup..",
|
84
|
+
:archiving => "Archiving backup..",
|
85
|
+
:encrypting => "Encrypting backup..",
|
86
|
+
:mysqldump => "Creating MySQL dump..",
|
87
|
+
:pgdump => "Creating PostgreSQL dump..",
|
88
|
+
:commands => "Executing commands.." }
|
89
|
+
end
|
90
|
+
|
75
91
|
end
|
76
92
|
end
|
77
93
|
end
|
@@ -27,6 +27,7 @@ module Backup
|
|
27
27
|
encrypt
|
28
28
|
store
|
29
29
|
record
|
30
|
+
notify
|
30
31
|
ensure
|
31
32
|
remove_tmp_files
|
32
33
|
end
|
@@ -37,22 +38,26 @@ module Backup
|
|
37
38
|
# Executes the commands
|
38
39
|
def execute_commands
|
39
40
|
if commands.is_a?(Array)
|
41
|
+
puts system_messages[:commands]
|
40
42
|
commands.each do |command|
|
41
43
|
%x{ #{command.gsub(':tmp_path', tmp_path)} }
|
42
44
|
end
|
43
45
|
elsif commands.is_a?(String)
|
46
|
+
puts system_messages[:commands]
|
44
47
|
%x{ #{commands.gsub(':tmp_path', tmp_path)} }
|
45
48
|
end
|
46
49
|
end
|
47
50
|
|
48
51
|
# Archives and Compresses
|
49
52
|
def targz
|
53
|
+
puts system_messages[:archiving]; puts system_messages[:compressing]
|
50
54
|
%x{ tar -czf #{File.join(tmp_path, compressed_file)} #{File.join(tmp_path, '*')} }
|
51
55
|
end
|
52
56
|
|
53
57
|
# Encrypts the archive file
|
54
58
|
def encrypt
|
55
59
|
if encrypt_with_password.is_a?(String)
|
60
|
+
puts system_messages[:encrypting]
|
56
61
|
%x{ openssl enc -des-cbc -in #{File.join(tmp_path, compressed_file)} -out #{File.join(tmp_path, encrypted_file)} -k #{encrypt_with_password} }
|
57
62
|
self.final_file = encrypted_file
|
58
63
|
end
|
@@ -25,6 +25,7 @@ module Backup
|
|
25
25
|
encrypt
|
26
26
|
store
|
27
27
|
record
|
28
|
+
notify
|
28
29
|
ensure
|
29
30
|
remove_tmp_files
|
30
31
|
end
|
@@ -34,12 +35,14 @@ module Backup
|
|
34
35
|
|
35
36
|
# Dumps and Compresses the MySQL file
|
36
37
|
def mysqldump
|
38
|
+
puts system_messages[:mysqldump]; puts system_messages[:compressing]
|
37
39
|
%x{ mysqldump -u #{user} --password='#{password}' #{options} #{additional_options} #{database} #{tables_to_skip} | gzip -f --best > #{File.join(tmp_path, compressed_file)} }
|
38
40
|
end
|
39
41
|
|
40
42
|
# Encrypts the MySQL file
|
41
43
|
def encrypt
|
42
44
|
if encrypt_with_password.is_a?(String)
|
45
|
+
puts system_messages[:encrypting]
|
43
46
|
%x{ openssl enc -des-cbc -in #{File.join(tmp_path, compressed_file)} -out #{File.join(tmp_path, encrypted_file)} -k #{encrypt_with_password} }
|
44
47
|
self.final_file = encrypted_file
|
45
48
|
end
|
@@ -25,6 +25,7 @@ module Backup
|
|
25
25
|
encrypt
|
26
26
|
store
|
27
27
|
record
|
28
|
+
notify
|
28
29
|
ensure
|
29
30
|
remove_tmp_files
|
30
31
|
end
|
@@ -34,12 +35,14 @@ module Backup
|
|
34
35
|
|
35
36
|
# Dumps and Compresses the PostgreSQL file
|
36
37
|
def pg_dump
|
38
|
+
puts system_messages[:pgdump]; puts system_messages[:compressing]
|
37
39
|
%x{ pg_dump -U #{user} #{options} #{additional_options} #{tables_to_skip} #{database} | gzip -f --best > #{File.join(tmp_path, compressed_file)} }
|
38
40
|
end
|
39
41
|
|
40
42
|
# Encrypts the PostgreSQL file
|
41
43
|
def encrypt
|
42
44
|
if encrypt_with_password.is_a?(String)
|
45
|
+
puts system_messages[:encrypting]
|
43
46
|
%x{ openssl enc -des-cbc -in #{File.join(tmp_path, compressed_file)} -out #{File.join(tmp_path, encrypted_file)} -k #{encrypt_with_password} }
|
44
47
|
self.final_file = encrypted_file
|
45
48
|
end
|
@@ -3,7 +3,7 @@ module Backup
|
|
3
3
|
class Base
|
4
4
|
attr_accessor :attributes, :trigger, :storage_name, :adapter_name
|
5
5
|
|
6
|
-
%w(encrypt_with_password keep_backups).each do |method|
|
6
|
+
%w(encrypt_with_password keep_backups notify).each do |method|
|
7
7
|
define_method method do |value|
|
8
8
|
attributes[method] = value
|
9
9
|
end
|
@@ -12,6 +12,13 @@ module Backup
|
|
12
12
|
@backup_procedures << backup
|
13
13
|
end
|
14
14
|
|
15
|
+
# A helper method for the config/mail.rb configuration file
|
16
|
+
# Takes a block containing the mail options
|
17
|
+
def notifier_settings(&block)
|
18
|
+
@mail_configuration = Backup::Configuration::Mail.new
|
19
|
+
@mail_configuration.instance_eval &block
|
20
|
+
end
|
21
|
+
|
15
22
|
end
|
16
23
|
end
|
17
24
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Backup
|
2
|
+
module Configuration
|
3
|
+
class Mail
|
4
|
+
attr_accessor :attributes
|
5
|
+
|
6
|
+
%w(from to smtp).each do |method|
|
7
|
+
define_method method do |value|
|
8
|
+
attributes[method.to_sym] = value
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@attributes = {}
|
14
|
+
@smtp_configuration = Backup::Configuration::SMTP.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def smtp(&block)
|
18
|
+
@smtp_configuration.instance_eval &block
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_smtp_configuration
|
22
|
+
@smtp_configuration
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Backup
|
2
|
+
module Configuration
|
3
|
+
class SMTP
|
4
|
+
|
5
|
+
attr_accessor :attributes
|
6
|
+
|
7
|
+
%w(host port username password authentication domain tls).each do |method|
|
8
|
+
define_method method do |value|
|
9
|
+
attributes[method.to_sym] = value
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@attributes = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Backup
|
2
|
+
module Mail
|
3
|
+
class Base
|
4
|
+
|
5
|
+
# Sets up the Mail Configuration for the Backup::Mail::Base class.
|
6
|
+
# This must be set in order to send emails
|
7
|
+
# It will dynamically add class methods (configuration) for each email that will be sent
|
8
|
+
def self.setup(config)
|
9
|
+
if config
|
10
|
+
(class << self; self; end).instance_eval do
|
11
|
+
config.attributes.each do |method, value|
|
12
|
+
define_method method do
|
13
|
+
value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
config.get_smtp_configuration.attributes.each do |method, value|
|
17
|
+
define_method method do
|
18
|
+
value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns true if the "to" and "from" attributes are set
|
26
|
+
def self.setup?
|
27
|
+
return true if defined?(from) and defined?(to)
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
31
|
+
# Delivers the backup details by email to the recipient
|
32
|
+
# Requires the Backup Object
|
33
|
+
def self.notify!(backup)
|
34
|
+
if self.setup? and backup.procedure.attributes['notify'].eql?(true)
|
35
|
+
@backup = backup
|
36
|
+
self.parse_body
|
37
|
+
Pony.mail({
|
38
|
+
:subject => "Backup for \"#{@backup.trigger}\" was successfully created!",
|
39
|
+
:body => @content
|
40
|
+
}.merge(self.smtp_configuration))
|
41
|
+
puts "Sending notification to #{self.to}."
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Retrieves SMTP configuration
|
46
|
+
def self.smtp_configuration
|
47
|
+
{ :to => self.to,
|
48
|
+
:from => self.from,
|
49
|
+
:via => :smtp,
|
50
|
+
:smtp => {
|
51
|
+
:host => self.host,
|
52
|
+
:port => self.port,
|
53
|
+
:user => self.username,
|
54
|
+
:password => self.password,
|
55
|
+
:auth => self.authentication,
|
56
|
+
:domain => self.domain,
|
57
|
+
:tls => self.tls
|
58
|
+
}}
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.parse_body
|
62
|
+
File.open(File.join(File.dirname(__FILE__), 'mail.txt'), 'r') do |file|
|
63
|
+
self.gsub_content(file.readlines)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.gsub_content(lines)
|
68
|
+
bucket = @backup.procedure.get_storage_configuration.attributes['bucket']
|
69
|
+
path = @backup.procedure.get_storage_configuration.attributes['path']
|
70
|
+
ip = @backup.procedure.get_storage_configuration.attributes['ip']
|
71
|
+
|
72
|
+
lines.each do |line|
|
73
|
+
line.gsub!(':trigger', @backup.trigger)
|
74
|
+
line.gsub!(':day', Time.now.strftime("%A (%d)"))
|
75
|
+
line.gsub!(':month', Time.now.strftime("%B"))
|
76
|
+
line.gsub!(':year', Time.now.strftime("%Y"))
|
77
|
+
line.gsub!(':time', Time.now.strftime("%r"))
|
78
|
+
line.gsub!(':adapter', @backup.procedure.adapter_name.to_s)
|
79
|
+
line.gsub!(':location', bucket || path)
|
80
|
+
line.gsub!(':remote', bucket ? "Amazon S3" : "the remote server (#{ip})")
|
81
|
+
line.gsub!(':backup', @backup.final_file)
|
82
|
+
@content ||= String.new
|
83
|
+
@content << line
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/setup/backup.rb
CHANGED
@@ -39,10 +39,35 @@
|
|
39
39
|
#
|
40
40
|
# The combination of these, however, do not matter! So experiment with it.
|
41
41
|
#
|
42
|
+
# You can also let Backup notify you by email on successfully created backups.
|
43
|
+
# - Just uncomment the block of code below (notifier_settings) and fill in your credentials.
|
44
|
+
# - Then for set "notify" to "true" in each (backup) block you wish to be notified of.
|
45
|
+
#
|
42
46
|
# For more information on "Backup", please refer to the wiki on github
|
43
47
|
# http://wiki.github.com/meskyanichi/backup/configuration-file
|
44
48
|
|
45
49
|
|
50
|
+
# Notifier
|
51
|
+
# Uncomment this if you want to enable notification by email on successful backup runs
|
52
|
+
# You will also have to set "notify true" inside each backup block below to enable it for that particular backup
|
53
|
+
# notifier_settings do
|
54
|
+
#
|
55
|
+
# to "example1@gmail.com"
|
56
|
+
# from "example2@gmail.com"
|
57
|
+
#
|
58
|
+
# smtp do
|
59
|
+
# host "smtp.gmail.com"
|
60
|
+
# port "587"
|
61
|
+
# username "example1@gmail.com"
|
62
|
+
# password "example1password"
|
63
|
+
# authentication "plain"
|
64
|
+
# domain "localhost.localdomain"
|
65
|
+
# tls true
|
66
|
+
# end
|
67
|
+
#
|
68
|
+
# end
|
69
|
+
|
70
|
+
|
46
71
|
# Initialize with:
|
47
72
|
# sudo backup --run mysql-backup-s3
|
48
73
|
backup 'mysql-backup-s3' do
|
@@ -71,6 +96,7 @@ backup 'mysql-backup-s3' do
|
|
71
96
|
|
72
97
|
keep_backups 25
|
73
98
|
encrypt_with_password 'password'
|
99
|
+
notify false
|
74
100
|
|
75
101
|
end
|
76
102
|
|
@@ -102,6 +128,7 @@ backup 'postgresql-backup-scp' do
|
|
102
128
|
|
103
129
|
keep_backups :all
|
104
130
|
encrypt_with_password false
|
131
|
+
notify false
|
105
132
|
|
106
133
|
end
|
107
134
|
|
@@ -124,6 +151,7 @@ backup 'archive-backup-ftp' do
|
|
124
151
|
|
125
152
|
keep_backups 10
|
126
153
|
encrypt_with_password false
|
154
|
+
notify false
|
127
155
|
|
128
156
|
end
|
129
157
|
|
@@ -148,5 +176,6 @@ backup 'custom-backup-sftp' do
|
|
148
176
|
|
149
177
|
keep_backups :all
|
150
178
|
encrypt_with_password 'password'
|
151
|
-
|
179
|
+
notify false
|
180
|
+
|
152
181
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael van Rooijen
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-08 00:00:00 +01:00
|
13
13
|
default_executable: backup
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -82,6 +82,16 @@ dependencies:
|
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: 0.2.9
|
84
84
|
version:
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: pony
|
87
|
+
type: :runtime
|
88
|
+
version_requirement:
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: "0.5"
|
94
|
+
version:
|
85
95
|
description: "\n Backup is a Ruby Gem written for Unix and Rails environments. It can be used both with and without the\n Ruby on Rails framework! This gem offers a quick and simple solution to backing up databases such as\n MySQL/PostgreSQL and Files/Folders. All backups can be transferred to Amazon S3 or any remote server you\n have access to, using either SCP, SFTP or regular FTP. Backup handles Compression, Archiving, Encryption\n and Backup Cleaning (Cycling).\n "
|
86
96
|
email: meskyan@gmail.com
|
87
97
|
executables:
|
@@ -115,11 +125,15 @@ files:
|
|
115
125
|
- lib/backup/configuration/adapter_options.rb
|
116
126
|
- lib/backup/configuration/base.rb
|
117
127
|
- lib/backup/configuration/helpers.rb
|
128
|
+
- lib/backup/configuration/mail.rb
|
129
|
+
- lib/backup/configuration/smtp.rb
|
118
130
|
- lib/backup/configuration/storage.rb
|
119
131
|
- lib/backup/connection/s3.rb
|
120
132
|
- lib/backup/environment/base.rb
|
121
133
|
- lib/backup/environment/rails.rb
|
122
134
|
- lib/backup/environment/unix.rb
|
135
|
+
- lib/backup/mail/base.rb
|
136
|
+
- lib/backup/mail/mail.txt
|
123
137
|
- lib/backup/record/ftp.rb
|
124
138
|
- lib/backup/record/s3.rb
|
125
139
|
- lib/backup/record/scp.rb
|