backup 2.4.5.1 → 3.0.0.build.0
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 +2 -0
- data/.infinity_test +7 -0
- data/.rspec +3 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +88 -0
- data/LICENSE.md +24 -0
- data/README.md +189 -75
- data/backup.gemspec +41 -0
- data/bin/backup +161 -90
- data/lib/backup.rb +133 -117
- data/lib/backup/archive.rb +54 -0
- data/lib/backup/cli.rb +50 -0
- data/lib/backup/compressor/base.rb +17 -0
- data/lib/backup/compressor/gzip.rb +61 -0
- data/lib/backup/configuration/base.rb +7 -67
- data/lib/backup/configuration/compressor/base.rb +10 -0
- data/lib/backup/configuration/compressor/gzip.rb +23 -0
- data/lib/backup/configuration/database/base.rb +18 -0
- data/lib/backup/configuration/database/mongodb.rb +37 -0
- data/lib/backup/configuration/database/mysql.rb +37 -0
- data/lib/backup/configuration/database/postgresql.rb +37 -0
- data/lib/backup/configuration/database/redis.rb +35 -0
- data/lib/backup/configuration/encryptor/base.rb +10 -0
- data/lib/backup/configuration/encryptor/gpg.rb +17 -0
- data/lib/backup/configuration/encryptor/open_ssl.rb +26 -0
- data/lib/backup/configuration/helpers.rb +47 -17
- data/lib/backup/configuration/notifier/base.rb +39 -0
- data/lib/backup/configuration/notifier/mail.rb +52 -0
- data/lib/backup/configuration/storage/base.rb +18 -0
- data/lib/backup/configuration/storage/cloudfiles.rb +21 -0
- data/lib/backup/configuration/storage/dropbox.rb +25 -0
- data/lib/backup/configuration/storage/ftp.rb +25 -0
- data/lib/backup/configuration/storage/rsync.rb +25 -0
- data/lib/backup/configuration/storage/s3.rb +25 -0
- data/lib/backup/configuration/storage/scp.rb +25 -0
- data/lib/backup/configuration/storage/sftp.rb +25 -0
- data/lib/backup/database/base.rb +33 -0
- data/lib/backup/database/mongodb.rb +137 -0
- data/lib/backup/database/mysql.rb +104 -0
- data/lib/backup/database/postgresql.rb +111 -0
- data/lib/backup/database/redis.rb +105 -0
- data/lib/backup/encryptor/base.rb +17 -0
- data/lib/backup/encryptor/gpg.rb +78 -0
- data/lib/backup/encryptor/open_ssl.rb +67 -0
- data/lib/backup/finder.rb +39 -0
- data/lib/backup/logger.rb +80 -0
- data/lib/backup/model.rb +249 -0
- data/lib/backup/notifier/base.rb +29 -0
- data/lib/backup/notifier/binder.rb +32 -0
- data/lib/backup/notifier/mail.rb +141 -0
- data/lib/backup/notifier/templates/notify_failure.erb +31 -0
- data/lib/backup/notifier/templates/notify_success.erb +16 -0
- data/lib/backup/storage/base.rb +60 -3
- data/lib/backup/storage/cloudfiles.rb +85 -6
- data/lib/backup/storage/dropbox.rb +74 -4
- data/lib/backup/storage/ftp.rb +103 -27
- data/lib/backup/storage/object.rb +45 -0
- data/lib/backup/storage/rsync.rb +100 -0
- data/lib/backup/storage/s3.rb +100 -7
- data/lib/backup/storage/scp.rb +94 -19
- data/lib/backup/storage/sftp.rb +94 -19
- data/lib/backup/version.rb +70 -1
- data/lib/templates/archive +4 -0
- data/lib/templates/compressor/gzip +4 -0
- data/lib/templates/database/mongodb +10 -0
- data/lib/templates/database/mysql +11 -0
- data/lib/templates/database/postgresql +11 -0
- data/lib/templates/database/redis +10 -0
- data/lib/templates/encryptor/gpg +9 -0
- data/lib/templates/encryptor/openssl +5 -0
- data/lib/templates/notifier/mail +14 -0
- data/lib/templates/readme +15 -0
- data/lib/templates/storage/cloudfiles +7 -0
- data/lib/templates/storage/dropbox +8 -0
- data/lib/templates/storage/ftp +8 -0
- data/lib/templates/storage/rsync +7 -0
- data/lib/templates/storage/s3 +8 -0
- data/lib/templates/storage/scp +8 -0
- data/lib/templates/storage/sftp +8 -0
- data/spec/archive_spec.rb +53 -0
- data/spec/backup_spec.rb +11 -0
- data/spec/compressor/gzip_spec.rb +59 -0
- data/spec/configuration/base_spec.rb +35 -0
- data/spec/configuration/compressor/gzip_spec.rb +28 -0
- data/spec/configuration/database/base_spec.rb +16 -0
- data/spec/configuration/database/mongodb_spec.rb +30 -0
- data/spec/configuration/database/mysql_spec.rb +32 -0
- data/spec/configuration/database/postgresql_spec.rb +32 -0
- data/spec/configuration/database/redis_spec.rb +30 -0
- data/spec/configuration/encryptor/gpg_spec.rb +25 -0
- data/spec/configuration/encryptor/open_ssl_spec.rb +31 -0
- data/spec/configuration/notifier/mail_spec.rb +32 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +34 -0
- data/spec/configuration/storage/dropbox_spec.rb +40 -0
- data/spec/configuration/storage/ftp_spec.rb +40 -0
- data/spec/configuration/storage/rsync_spec.rb +37 -0
- data/spec/configuration/storage/s3_spec.rb +37 -0
- data/spec/configuration/storage/scp_spec.rb +40 -0
- data/spec/configuration/storage/sftp_spec.rb +40 -0
- data/spec/database/base_spec.rb +30 -0
- data/spec/database/mongodb_spec.rb +144 -0
- data/spec/database/mysql_spec.rb +150 -0
- data/spec/database/postgresql_spec.rb +164 -0
- data/spec/database/redis_spec.rb +122 -0
- data/spec/encryptor/gpg_spec.rb +57 -0
- data/spec/encryptor/open_ssl_spec.rb +102 -0
- data/spec/logger_spec.rb +37 -0
- data/spec/model_spec.rb +236 -0
- data/spec/notifier/mail_spec.rb +97 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/storage/base_spec.rb +33 -0
- data/spec/storage/cloudfiles_spec.rb +102 -0
- data/spec/storage/dropbox_spec.rb +89 -0
- data/spec/storage/ftp_spec.rb +133 -0
- data/spec/storage/object_spec.rb +74 -0
- data/spec/storage/rsync_spec.rb +115 -0
- data/spec/storage/s3_spec.rb +110 -0
- data/spec/storage/scp_spec.rb +129 -0
- data/spec/storage/sftp_spec.rb +125 -0
- data/spec/version_spec.rb +32 -0
- metadata +139 -123
- data/CHANGELOG +0 -131
- data/LICENSE +0 -20
- data/generators/backup/backup_generator.rb +0 -69
- data/generators/backup/templates/backup.rake +0 -56
- data/generators/backup/templates/backup.rb +0 -253
- data/generators/backup/templates/create_backup_tables.rb +0 -18
- data/generators/backup_update/backup_update_generator.rb +0 -50
- data/generators/backup_update/templates/migrations/update_backup_tables.rb +0 -27
- data/lib/backup/adapters/archive.rb +0 -34
- data/lib/backup/adapters/base.rb +0 -167
- data/lib/backup/adapters/custom.rb +0 -41
- data/lib/backup/adapters/mongo_db.rb +0 -139
- data/lib/backup/adapters/mysql.rb +0 -60
- data/lib/backup/adapters/postgresql.rb +0 -60
- data/lib/backup/adapters/sqlite.rb +0 -25
- data/lib/backup/command_helper.rb +0 -14
- data/lib/backup/configuration/adapter.rb +0 -21
- data/lib/backup/configuration/adapter_options.rb +0 -8
- data/lib/backup/configuration/attributes.rb +0 -19
- data/lib/backup/configuration/mail.rb +0 -20
- data/lib/backup/configuration/smtp.rb +0 -8
- data/lib/backup/configuration/storage.rb +0 -8
- data/lib/backup/connection/cloudfiles.rb +0 -75
- data/lib/backup/connection/dropbox.rb +0 -63
- data/lib/backup/connection/s3.rb +0 -88
- data/lib/backup/core_ext/object.rb +0 -5
- data/lib/backup/environment/base.rb +0 -12
- data/lib/backup/environment/rails_configuration.rb +0 -15
- data/lib/backup/environment/unix_configuration.rb +0 -109
- data/lib/backup/mail/base.rb +0 -97
- data/lib/backup/mail/mail.txt +0 -7
- data/lib/backup/record/base.rb +0 -65
- data/lib/backup/record/cloudfiles.rb +0 -28
- data/lib/backup/record/dropbox.rb +0 -27
- data/lib/backup/record/ftp.rb +0 -39
- data/lib/backup/record/local.rb +0 -26
- data/lib/backup/record/s3.rb +0 -25
- data/lib/backup/record/scp.rb +0 -33
- data/lib/backup/record/sftp.rb +0 -38
- data/lib/backup/storage/local.rb +0 -22
- data/lib/generators/backup/USAGE +0 -10
- data/lib/generators/backup/backup_generator.rb +0 -47
- data/lib/generators/backup/templates/backup.rake +0 -56
- data/lib/generators/backup/templates/backup.rb +0 -236
- data/lib/generators/backup/templates/create_backup_tables.rb +0 -18
- data/setup/backup.rb +0 -257
- data/setup/backup.sqlite3 +0 -0
data/backup.gemspec
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/lib/backup')
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |gem|
|
|
6
|
+
|
|
7
|
+
##
|
|
8
|
+
# General configuration / information
|
|
9
|
+
gem.name = 'backup'
|
|
10
|
+
gem.version = Backup::Version.gemspec
|
|
11
|
+
gem.platform = Gem::Platform::RUBY
|
|
12
|
+
gem.authors = 'Michael van Rooijen'
|
|
13
|
+
gem.email = 'meskyanichi@gmail.com'
|
|
14
|
+
gem.homepage = 'http://rubygems.org/gems/backup'
|
|
15
|
+
gem.summary = 'Backup is a RubyGem (for UNIX-like operating systems: Linux, Mac OSX) that allows you to configure and perform backups in a simple manner using an elegant Ruby DSL.'
|
|
16
|
+
gem.description = 'Backup is a RubyGem (for UNIX-like operating systems: Linux, Mac OSX) that allows you to configure and perform backups in a simple manner using an elegant Ruby DSL.
|
|
17
|
+
It supports various various databases (MySQL, PostgreSQL, MongoDB and Redis), it supports various storage locations
|
|
18
|
+
(Amazon S3, Rackspace Cloud Files, Dropbox, any remote server through FTP, SFTP, SCP and RSync), it can archive files and folders,
|
|
19
|
+
it can cycle backups, it can do incremental backups, it can compress backups, it can encrypt backups (OpenSSL or GPG),
|
|
20
|
+
it can notify you about successful and/or failed backups. It is very extensible and easy to add new functionality to. It\'s easy to use.'
|
|
21
|
+
|
|
22
|
+
##
|
|
23
|
+
# Files and folder that need to be compiled in to the Ruby Gem
|
|
24
|
+
gem.files = %x[git ls-files].split("\n")
|
|
25
|
+
gem.test_files = %x[git ls-files -- {spec}/*].split("\n")
|
|
26
|
+
gem.require_path = 'lib'
|
|
27
|
+
|
|
28
|
+
##
|
|
29
|
+
# The Backup CLI executable
|
|
30
|
+
gem.executables = ['backup']
|
|
31
|
+
|
|
32
|
+
##
|
|
33
|
+
# Production gem dependencies
|
|
34
|
+
gem.add_dependency 'thor', ['~> 0.14.6'] # CLI
|
|
35
|
+
gem.add_dependency 'fog', ['~> 0.5.3' ] # Amazon S3, Rackspace Cloud Files
|
|
36
|
+
gem.add_dependency 'dropbox', ['~> 1.2.3' ] # Dropbox
|
|
37
|
+
gem.add_dependency 'mail', ['~> 2.2.15'] # Mail
|
|
38
|
+
gem.add_dependency 'net-sftp', ['~> 2.0.5' ] # SFTP Protocol
|
|
39
|
+
gem.add_dependency 'net-scp', ['~> 1.0.4' ] # SCP Protocol
|
|
40
|
+
|
|
41
|
+
end
|
data/bin/backup
CHANGED
|
@@ -1,108 +1,179 @@
|
|
|
1
|
-
|
|
1
|
+
#! /usr/bin/env ruby
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
##
|
|
4
|
+
# Load RubyGems for Ruby <= 1.8.7
|
|
5
|
+
require 'rubygems'
|
|
6
|
+
require 'tempfile'
|
|
7
|
+
require 'fileutils'
|
|
5
8
|
|
|
6
|
-
|
|
9
|
+
##
|
|
10
|
+
# Load Thor for the Command Line Interface
|
|
11
|
+
begin
|
|
12
|
+
require 'thor'
|
|
13
|
+
rescue LoadError
|
|
14
|
+
puts 'Backup uses Thor as CLI (Command Line Interface).'
|
|
15
|
+
puts 'Please install Thor first: `gem install thor`'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
##
|
|
19
|
+
# Load the Backup source
|
|
20
|
+
require File.expand_path("../../lib/backup", __FILE__)
|
|
21
|
+
|
|
22
|
+
##
|
|
23
|
+
# Build the Backup Command Line Interface using Thor
|
|
24
|
+
class BackupCLI < Thor
|
|
25
|
+
|
|
26
|
+
TEMPLATE_DIR = File.expand_path("../../lib/templates", __FILE__)
|
|
27
|
+
|
|
28
|
+
##
|
|
29
|
+
# [Perform]
|
|
30
|
+
# Performs the backup process. The only required option is the --trigger [-t].
|
|
31
|
+
# If the other options (--config_file, --data_path, --tmp_path) aren't specified
|
|
32
|
+
# it'll fallback to the (good) defaults
|
|
33
|
+
method_option :trigger, :type => :string, :aliases => '-t', :required => true
|
|
34
|
+
method_option :config_file, :type => :string, :aliases => '-c'
|
|
35
|
+
method_option :data_path, :type => :string, :aliases => '-d'
|
|
36
|
+
method_option :log_path, :type => :string, :aliases => '-l'
|
|
37
|
+
method_option :tmp_path, :type => :string
|
|
38
|
+
desc 'perform', 'Performs the backup for the specified trigger'
|
|
39
|
+
def perform
|
|
40
|
+
|
|
41
|
+
##
|
|
42
|
+
# Defines the TRIGGER and TIME constants
|
|
43
|
+
Backup.send(:const_set, :TRIGGER, options[:trigger])
|
|
44
|
+
Backup.send(:const_set, :TIME, Time.now.strftime("%Y.%m.%d.%H.%M.%S"))
|
|
45
|
+
|
|
46
|
+
##
|
|
47
|
+
# Overwrites the CONFIG_FILE location, if --config-file was specified
|
|
48
|
+
if options[:config_file]
|
|
49
|
+
Backup.send(:remove_const, :CONFIG_FILE)
|
|
50
|
+
Backup.send(:const_set, :CONFIG_FILE, options[:config_file])
|
|
51
|
+
end
|
|
7
52
|
|
|
8
|
-
|
|
9
|
-
|
|
53
|
+
##
|
|
54
|
+
# Overwrites the DATA_PATH location, if --data-path was specified
|
|
55
|
+
if options[:data_path]
|
|
56
|
+
Backup.send(:remove_const, :DATA_PATH)
|
|
57
|
+
Backup.send(:const_set, :DATA_PATH, options[:data_path])
|
|
58
|
+
end
|
|
10
59
|
|
|
11
|
-
|
|
60
|
+
##
|
|
61
|
+
# Overwrites the LOG_PATH location, if --log-path was specified
|
|
62
|
+
if options[:log_path]
|
|
63
|
+
Backup.send(:remove_const, :LOG_PATH)
|
|
64
|
+
Backup.send(:const_set, :LOG_PATH, options[:log_path])
|
|
65
|
+
end
|
|
12
66
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
67
|
+
##
|
|
68
|
+
# Overwrites the TMP_PATH location, if --tmp-path was specified
|
|
69
|
+
if options[:tmp_path]
|
|
70
|
+
Backup.send(:remove_const, :TMP_PATH)
|
|
71
|
+
Backup.send(:const_set, :TMP_PATH, options[:tmp_path])
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
##
|
|
75
|
+
# Ensure the TMP_PATH, LOG_PATH, DATA_PATH and DATA_PATH/TRIGGER
|
|
76
|
+
# are created if they do not yet exist
|
|
77
|
+
Array.new([
|
|
78
|
+
Backup::TMP_PATH,
|
|
79
|
+
Backup::LOG_PATH,
|
|
80
|
+
File.join(Backup::DATA_PATH, Backup::TRIGGER)
|
|
81
|
+
]).each do |path|
|
|
82
|
+
FileUtils.mkdir_p(path)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
##
|
|
86
|
+
# Parses the backup configuration file and returns the model instance by trigger
|
|
87
|
+
model = Backup::Finder.new(Backup::TRIGGER, Backup::CONFIG_FILE).find
|
|
88
|
+
|
|
89
|
+
##
|
|
90
|
+
# Runs the returned model
|
|
91
|
+
Backup::Logger.message "Performing backup for #{model.label}!"
|
|
92
|
+
model.perform!
|
|
21
93
|
end
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
94
|
+
|
|
95
|
+
##
|
|
96
|
+
# [Generate]
|
|
97
|
+
# Generates a configuration file based on the arguments passed in.
|
|
98
|
+
# For example, running $ backup generate --databases='mongodb' will generate a pre-populated
|
|
99
|
+
# configuration file with a base MongoDB setup
|
|
100
|
+
desc 'generate', 'Generates configuration blocks based on the arguments you pass in'
|
|
101
|
+
method_option :path, :type => :string
|
|
102
|
+
method_option :databases, :type => :string
|
|
103
|
+
method_option :storages, :type => :string
|
|
104
|
+
method_option :encryptors, :type => :string
|
|
105
|
+
method_option :compressors, :type => :string
|
|
106
|
+
method_option :notifiers, :type => :string
|
|
107
|
+
method_option :archives, :type => :boolean
|
|
108
|
+
def generate
|
|
109
|
+
temp_file = Tempfile.new('backup.rb')
|
|
110
|
+
temp_file << File.read( File.join(TEMPLATE_DIR, 'readme') )
|
|
111
|
+
temp_file << "Backup::Model.new(:my_backup, 'My Backup') do\n\n"
|
|
112
|
+
|
|
113
|
+
if options[:archives]
|
|
114
|
+
temp_file << File.read( File.join(TEMPLATE_DIR, 'archive') ) + "\n\n"
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
[:databases, :storages, :encryptors, :compressors, :notifiers].each do |item|
|
|
118
|
+
if options[item]
|
|
119
|
+
options[item].split(',').map(&:strip).uniq.each do |entry|
|
|
120
|
+
if File.exist?( File.join(TEMPLATE_DIR, item.to_s[0..-2], entry) )
|
|
121
|
+
temp_file << File.read( File.join(TEMPLATE_DIR, item.to_s[0..-2], entry) ) + "\n\n"
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
temp_file << "end\n\n"
|
|
128
|
+
temp_file.close
|
|
129
|
+
if options[:path]
|
|
130
|
+
FileUtils.mkdir_p(options[:path])
|
|
131
|
+
File.open(File.join(options[:path], 'config.rb'), 'w') do |file|
|
|
132
|
+
file.write( File.read(temp_file.path) )
|
|
133
|
+
puts "Generated configuration file in '#{File.join(options[:path], 'config.rb')}'"
|
|
134
|
+
end
|
|
31
135
|
else
|
|
32
|
-
|
|
33
|
-
|
|
136
|
+
FileUtils.mkdir_p(Backup::PATH)
|
|
137
|
+
File.open(File.join(Backup::PATH, 'config.rb'), 'w') do |file|
|
|
138
|
+
file.write( File.read(temp_file.path) )
|
|
139
|
+
puts "Generated configuration file in '#{File.join(Backup::PATH, 'config.rb')}'"
|
|
34
140
|
end
|
|
35
141
|
end
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
opts.on('-t', '--truncate [trigger]', "Truncates backup records for specified trigger") do |trigger|
|
|
39
|
-
puts "Truncating backup records with trigger: #{trigger}."
|
|
40
|
-
Backup::Record::Base.destroy_all :trigger => trigger
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
opts.on('-d', '--destroy [trigger]', "Destroys backup records and files for specified trigger") do |trigger|
|
|
44
|
-
confirm_configuration_file_existence
|
|
45
|
-
puts "Destroying backup records with trigger: #{trigger}."
|
|
46
|
-
backup = Backup::Setup.new(trigger, @backup_procedures)
|
|
47
|
-
backup.procedure.record_class.destroy_all_backups( backup.procedure, trigger )
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
opts.on('--truncate-all', "Truncates all backup records") do
|
|
51
|
-
puts "Truncating all backup records."
|
|
52
|
-
Backup::Record::Base.destroy_all
|
|
142
|
+
temp_file.unlink
|
|
53
143
|
end
|
|
54
144
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
145
|
+
##
|
|
146
|
+
# [Decrypt]
|
|
147
|
+
# Shorthand for decrypting encrypted files
|
|
148
|
+
desc 'decrypt', 'Decrypts encrypted files'
|
|
149
|
+
method_option :encryptor, :type => :string, :required => true
|
|
150
|
+
method_option :in, :type => :string, :required => true
|
|
151
|
+
method_option :out, :type => :string, :required => true
|
|
152
|
+
method_option :base64, :type => :boolean, :default => false
|
|
153
|
+
def decrypt
|
|
154
|
+
case options[:encryptor].downcase
|
|
155
|
+
when 'openssl'
|
|
156
|
+
base64 = options[:base64] ? '-base64' : ''
|
|
157
|
+
%x[openssl aes-256-cbc -d #{base64} -in '#{options[:in]}' -out '#{options[:out]}']
|
|
158
|
+
when 'gpg'
|
|
159
|
+
%x[gpg -o '#{options[:out]}' -d '#{options[:in]}']
|
|
160
|
+
else
|
|
161
|
+
puts "Unknown encryptor: #{options[:encryptor]}"
|
|
162
|
+
puts "Use either 'openssl' or 'gpg'"
|
|
61
163
|
end
|
|
62
164
|
end
|
|
63
165
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
options[:table] = true
|
|
166
|
+
##
|
|
167
|
+
# [Version]
|
|
168
|
+
# Returns the current version of the Backup gem
|
|
169
|
+
map '-v' => :version
|
|
170
|
+
desc 'version', 'Display installed Backup version'
|
|
171
|
+
def version
|
|
172
|
+
puts "Backup #{Backup::Version.current}"
|
|
72
173
|
end
|
|
73
174
|
|
|
74
|
-
opts.on('--setup', "Sets up Backup") do
|
|
75
|
-
setup
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
opts.on('--reset', "Reinstalls Backup (This will remove ALL current settings!)") do
|
|
79
|
-
reset
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
opts.on('--remove', "Removes Backup (This will remove ALL current settings!)") do
|
|
83
|
-
remove
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
opts.on('-v', '--version', 'Displays installed Backup version') do
|
|
87
|
-
File.open(File.join(File.dirname(__FILE__), '..', 'VERSION')) do |file|
|
|
88
|
-
puts "Backup version #{file.read}"
|
|
89
|
-
end
|
|
90
|
-
exit
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
opts.on('-h', '--help', 'Display help screen') do
|
|
94
|
-
puts opts
|
|
95
|
-
puts "\n "
|
|
96
|
-
exit
|
|
97
|
-
end
|
|
98
|
-
|
|
99
175
|
end
|
|
100
176
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
puts "\nInvalid Option. See the list of available options below.\n"
|
|
105
|
-
puts optparse
|
|
106
|
-
puts "\n "
|
|
107
|
-
exit
|
|
108
|
-
end
|
|
177
|
+
##
|
|
178
|
+
# Enable the CLI for the Backup binary
|
|
179
|
+
BackupCLI.start
|
data/lib/backup.rb
CHANGED
|
@@ -1,132 +1,148 @@
|
|
|
1
|
-
|
|
2
|
-
# Load Gems
|
|
3
|
-
require 'hirb'
|
|
4
|
-
|
|
5
|
-
# Load Extensions
|
|
6
|
-
require 'backup/core_ext/object'
|
|
7
|
-
|
|
8
|
-
# Load Environments
|
|
9
|
-
require 'backup/environment/base'
|
|
10
|
-
require 'backup/environment/unix_configuration'
|
|
11
|
-
require 'backup/environment/rails_configuration'
|
|
12
|
-
|
|
13
|
-
# Load Configuration
|
|
14
|
-
require 'backup/configuration/attributes'
|
|
15
|
-
require 'backup/configuration/base'
|
|
16
|
-
require 'backup/configuration/adapter'
|
|
17
|
-
require 'backup/configuration/adapter_options'
|
|
18
|
-
require 'backup/configuration/storage'
|
|
19
|
-
require 'backup/configuration/mail'
|
|
20
|
-
require 'backup/configuration/smtp'
|
|
21
|
-
require 'backup/configuration/helpers'
|
|
22
|
-
|
|
23
|
-
require 'backup/command_helper'
|
|
24
|
-
|
|
25
|
-
# Include the Configuration and Environment Helpers
|
|
26
|
-
include Backup::Configuration::Helpers
|
|
27
|
-
include Backup::Environment::Base
|
|
28
|
-
|
|
29
|
-
# Load either UNIX or RAILS environment configuration
|
|
30
|
-
case current_environment
|
|
31
|
-
when :unix then include Backup::Environment::UnixConfiguration
|
|
32
|
-
when :rails then include Backup::Environment::RailsConfiguration
|
|
33
|
-
end
|
|
1
|
+
# encoding: utf-8
|
|
34
2
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
require File.join(BACKUP_PATH, 'config', 'backup.rb')
|
|
38
|
-
end
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
require 'yaml'
|
|
39
5
|
|
|
40
|
-
|
|
41
|
-
|
|
6
|
+
##
|
|
7
|
+
# The Backup Ruby Gem
|
|
8
|
+
module Backup
|
|
42
9
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
10
|
+
##
|
|
11
|
+
# List the available database, storage, compressor, encryptor and notifier constants.
|
|
12
|
+
# These are used to dynamically define these constants as classes inside Backup::Finder
|
|
13
|
+
# to provide a nicer configuration file DSL syntax to the users. Adding existing constants
|
|
14
|
+
# to the arrays below will enable the user to use a constant instead of a string.
|
|
15
|
+
# Example, instead of:
|
|
16
|
+
# database "MySQL" do |mysql|
|
|
17
|
+
# You can do:
|
|
18
|
+
# database MySQL do |mysql|
|
|
19
|
+
DATABASES = ['MySQL', 'PostgreSQL', 'MongoDB', 'Redis']
|
|
20
|
+
STORAGES = ['S3', 'CloudFiles', 'Dropbox', 'FTP', 'SFTP', 'SCP', 'RSync']
|
|
21
|
+
COMPRESSORS = ['Gzip']
|
|
22
|
+
ENCRYPTORS = ['OpenSSL', 'GPG']
|
|
23
|
+
NOTIFIERS = ['Mail']
|
|
46
24
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
25
|
+
##
|
|
26
|
+
# Backup's internal paths
|
|
27
|
+
LIBRARY_PATH = File.join(File.dirname(__FILE__), 'backup')
|
|
28
|
+
CONFIGURATION_PATH = File.join(LIBRARY_PATH, 'configuration')
|
|
29
|
+
STORAGE_PATH = File.join(LIBRARY_PATH, 'storage')
|
|
30
|
+
DATABASE_PATH = File.join(LIBRARY_PATH, 'database')
|
|
31
|
+
COMPRESSOR_PATH = File.join(LIBRARY_PATH, 'compressor')
|
|
32
|
+
ENCRYPTOR_PATH = File.join(LIBRARY_PATH, 'encryptor')
|
|
33
|
+
NOTIFIER_PATH = File.join(LIBRARY_PATH, 'notifier')
|
|
34
|
+
|
|
35
|
+
##
|
|
36
|
+
# Backup's Environment paths
|
|
37
|
+
PATH = File.join(ENV['HOME'], 'Backup')
|
|
38
|
+
DATA_PATH = File.join(ENV['HOME'], 'Backup', 'data')
|
|
39
|
+
CONFIG_FILE = File.join(ENV['HOME'], 'Backup', 'config.rb')
|
|
40
|
+
LOG_PATH = File.join(ENV['HOME'], 'Backup', 'log')
|
|
41
|
+
TMP_PATH = File.join(ENV['HOME'], 'Backup', '.tmp')
|
|
42
|
+
|
|
43
|
+
##
|
|
44
|
+
# Autoload Backup base files
|
|
45
|
+
autoload :Model, File.join(LIBRARY_PATH, 'model')
|
|
46
|
+
autoload :Archive, File.join(LIBRARY_PATH, 'archive')
|
|
47
|
+
autoload :CLI, File.join(LIBRARY_PATH, 'cli')
|
|
48
|
+
autoload :Finder, File.join(LIBRARY_PATH, 'finder')
|
|
49
|
+
autoload :Logger, File.join(LIBRARY_PATH, 'logger')
|
|
50
|
+
autoload :Version, File.join(LIBRARY_PATH, 'version')
|
|
51
|
+
|
|
52
|
+
##
|
|
53
|
+
# Autoload Backup configuration files
|
|
54
|
+
module Configuration
|
|
55
|
+
autoload :Base, File.join(CONFIGURATION_PATH, 'base')
|
|
56
|
+
autoload :Helpers, File.join(CONFIGURATION_PATH, 'helpers')
|
|
57
|
+
|
|
58
|
+
module Notifier
|
|
59
|
+
autoload :Base, File.join(CONFIGURATION_PATH, 'notifier', 'base')
|
|
60
|
+
autoload :Mail, File.join(CONFIGURATION_PATH, 'notifier', 'mail')
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
module Encryptor
|
|
64
|
+
autoload :Base, File.join(CONFIGURATION_PATH, 'encryptor', 'base')
|
|
65
|
+
autoload :OpenSSL, File.join(CONFIGURATION_PATH, 'encryptor', 'open_ssl')
|
|
66
|
+
autoload :GPG, File.join(CONFIGURATION_PATH, 'encryptor', 'gpg')
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
module Compressor
|
|
70
|
+
autoload :Base, File.join(CONFIGURATION_PATH, 'compressor', 'base')
|
|
71
|
+
autoload :Gzip, File.join(CONFIGURATION_PATH, 'compressor', 'gzip')
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
module Storage
|
|
75
|
+
autoload :Base, File.join(CONFIGURATION_PATH, 'storage', 'base')
|
|
76
|
+
autoload :S3, File.join(CONFIGURATION_PATH, 'storage', 's3')
|
|
77
|
+
autoload :CloudFiles, File.join(CONFIGURATION_PATH, 'storage', 'cloudfiles')
|
|
78
|
+
autoload :Dropbox, File.join(CONFIGURATION_PATH, 'storage', 'dropbox')
|
|
79
|
+
autoload :FTP, File.join(CONFIGURATION_PATH, 'storage', 'ftp')
|
|
80
|
+
autoload :SFTP, File.join(CONFIGURATION_PATH, 'storage', 'sftp')
|
|
81
|
+
autoload :SCP, File.join(CONFIGURATION_PATH, 'storage', 'scp')
|
|
82
|
+
autoload :RSync, File.join(CONFIGURATION_PATH, 'storage', 'rsync')
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
module Database
|
|
86
|
+
autoload :Base, File.join(CONFIGURATION_PATH, 'database', 'base')
|
|
87
|
+
autoload :MySQL, File.join(CONFIGURATION_PATH, 'database', 'mysql')
|
|
88
|
+
autoload :PostgreSQL, File.join(CONFIGURATION_PATH, 'database', 'postgresql')
|
|
89
|
+
autoload :MongoDB, File.join(CONFIGURATION_PATH, 'database', 'mongodb')
|
|
90
|
+
autoload :Redis, File.join(CONFIGURATION_PATH, 'database', 'redis')
|
|
54
91
|
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
module Adapters
|
|
58
|
-
autoload :Base, 'backup/adapters/base'
|
|
59
|
-
autoload :MySQL, 'backup/adapters/mysql'
|
|
60
|
-
autoload :MongoDB, 'backup/adapters/mongo_db'
|
|
61
|
-
autoload :SQLite, 'backup/adapters/sqlite'
|
|
62
|
-
autoload :PostgreSQL, 'backup/adapters/postgresql'
|
|
63
|
-
autoload :Archive, 'backup/adapters/archive'
|
|
64
|
-
autoload :Custom, 'backup/adapters/custom'
|
|
65
92
|
end
|
|
66
93
|
|
|
94
|
+
##
|
|
95
|
+
# Autoload Backup storage files
|
|
67
96
|
module Storage
|
|
68
|
-
autoload :Base, '
|
|
69
|
-
autoload :
|
|
70
|
-
autoload :S3, '
|
|
71
|
-
autoload :
|
|
72
|
-
autoload :
|
|
73
|
-
autoload :
|
|
74
|
-
autoload :
|
|
75
|
-
autoload :
|
|
97
|
+
autoload :Base, File.join(STORAGE_PATH, 'base')
|
|
98
|
+
autoload :Object, File.join(STORAGE_PATH, 'object')
|
|
99
|
+
autoload :S3, File.join(STORAGE_PATH, 's3')
|
|
100
|
+
autoload :CloudFiles, File.join(STORAGE_PATH, 'cloudfiles')
|
|
101
|
+
autoload :Dropbox, File.join(STORAGE_PATH, 'dropbox')
|
|
102
|
+
autoload :FTP, File.join(STORAGE_PATH, 'ftp')
|
|
103
|
+
autoload :SFTP, File.join(STORAGE_PATH, 'sftp')
|
|
104
|
+
autoload :SCP, File.join(STORAGE_PATH, 'scp')
|
|
105
|
+
autoload :RSync, File.join(STORAGE_PATH, 'rsync')
|
|
76
106
|
end
|
|
77
107
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
autoload :
|
|
82
|
-
autoload :
|
|
83
|
-
autoload :
|
|
84
|
-
autoload :
|
|
85
|
-
autoload :
|
|
86
|
-
autoload :Dropbox, 'backup/record/dropbox'
|
|
108
|
+
##
|
|
109
|
+
# Autoload Backup database files
|
|
110
|
+
module Database
|
|
111
|
+
autoload :Base, File.join(DATABASE_PATH, 'base')
|
|
112
|
+
autoload :MySQL, File.join(DATABASE_PATH, 'mysql')
|
|
113
|
+
autoload :PostgreSQL, File.join(DATABASE_PATH, 'postgresql')
|
|
114
|
+
autoload :MongoDB, File.join(DATABASE_PATH, 'mongodb')
|
|
115
|
+
autoload :Redis, File.join(DATABASE_PATH, 'redis')
|
|
87
116
|
end
|
|
88
117
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
case procedure.adapter_name.to_sym
|
|
104
|
-
when :mongo then Backup::Adapters::MongoDB.new trigger, procedure
|
|
105
|
-
when :mysql then Backup::Adapters::MySQL.new trigger, procedure
|
|
106
|
-
when :sqlite then Backup::Adapters::SQLite.new trigger, procedure
|
|
107
|
-
when :postgresql then Backup::Adapters::PostgreSQL.new trigger, procedure
|
|
108
|
-
when :archive then Backup::Adapters::Archive.new trigger, procedure
|
|
109
|
-
when :custom then Backup::Adapters::Custom.new trigger, procedure
|
|
110
|
-
else
|
|
111
|
-
puts "Unknown Adapter: \"#{procedure.adapter_name}\"."
|
|
112
|
-
exit
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
# Scans through all the backup settings and returns the backup setting
|
|
117
|
-
# that was specified in the "trigger" argument.
|
|
118
|
-
# If an non-existing trigger is specified, it will raise an error and display
|
|
119
|
-
# all the available triggers.
|
|
120
|
-
def find_triggered_procedure
|
|
121
|
-
procedures.each do |procedure|
|
|
122
|
-
if procedure.trigger.eql?(trigger)
|
|
123
|
-
return procedure
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
available_triggers = procedures.map {|procedure| "- #{procedure.trigger}\n" }
|
|
127
|
-
puts "Could not find a backup procedure with the trigger \"#{trigger}\". \nHere's a list of available triggers:\n#{available_triggers}"
|
|
128
|
-
exit
|
|
129
|
-
end
|
|
118
|
+
##
|
|
119
|
+
# Autoload compressor files
|
|
120
|
+
module Compressor
|
|
121
|
+
autoload :Base, File.join(COMPRESSOR_PATH, 'base')
|
|
122
|
+
autoload :Gzip, File.join(COMPRESSOR_PATH, 'gzip')
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
##
|
|
126
|
+
# Autoload encryptor files
|
|
127
|
+
module Encryptor
|
|
128
|
+
autoload :Base, File.join(ENCRYPTOR_PATH, 'base')
|
|
129
|
+
autoload :OpenSSL, File.join(ENCRYPTOR_PATH, 'open_ssl')
|
|
130
|
+
autoload :GPG, File.join(ENCRYPTOR_PATH, 'gpg')
|
|
131
|
+
end
|
|
130
132
|
|
|
133
|
+
##
|
|
134
|
+
# Autoload notification files
|
|
135
|
+
module Notifier
|
|
136
|
+
autoload :Base, File.join(NOTIFIER_PATH, 'base')
|
|
137
|
+
autoload :Binder, File.join(NOTIFIER_PATH, 'binder')
|
|
138
|
+
autoload :Mail, File.join(NOTIFIER_PATH, 'mail')
|
|
131
139
|
end
|
|
140
|
+
|
|
141
|
+
##
|
|
142
|
+
# Dynamically defines all the available database, storage, compressor, encryptor and notifier
|
|
143
|
+
# classes inside Backup::Finder to improve the DSL for the configuration file
|
|
144
|
+
(DATABASES + STORAGES + COMPRESSORS + ENCRYPTORS + NOTIFIERS).each do |constant|
|
|
145
|
+
Backup::Finder.const_set(constant, Class.new)
|
|
146
|
+
end
|
|
147
|
+
|
|
132
148
|
end
|