interu-backup 3.0.16
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/Gemfile +31 -0
- data/Gemfile.lock +117 -0
- data/Guardfile +17 -0
- data/LICENSE.md +24 -0
- data/README.md +332 -0
- data/backup.gemspec +31 -0
- data/bin/backup +267 -0
- data/lib/backup.rb +181 -0
- data/lib/backup/archive.rb +73 -0
- data/lib/backup/cli.rb +82 -0
- data/lib/backup/compressor/base.rb +17 -0
- data/lib/backup/compressor/bzip2.rb +64 -0
- data/lib/backup/compressor/gzip.rb +61 -0
- data/lib/backup/configuration/base.rb +15 -0
- data/lib/backup/configuration/compressor/base.rb +10 -0
- data/lib/backup/configuration/compressor/bzip2.rb +23 -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 +41 -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 +54 -0
- data/lib/backup/configuration/notifier/base.rb +39 -0
- data/lib/backup/configuration/notifier/campfire.rb +25 -0
- data/lib/backup/configuration/notifier/mail.rb +52 -0
- data/lib/backup/configuration/notifier/presently.rb +25 -0
- data/lib/backup/configuration/notifier/twitter.rb +21 -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 +29 -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/configuration/syncer/rsync.rb +45 -0
- data/lib/backup/configuration/syncer/s3.rb +33 -0
- data/lib/backup/database/base.rb +33 -0
- data/lib/backup/database/mongodb.rb +179 -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/dependency.rb +96 -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/exception/command_not_found.rb +8 -0
- data/lib/backup/finder.rb +39 -0
- data/lib/backup/logger.rb +102 -0
- data/lib/backup/model.rb +272 -0
- data/lib/backup/notifier/base.rb +29 -0
- data/lib/backup/notifier/binder.rb +32 -0
- data/lib/backup/notifier/campfire.rb +194 -0
- data/lib/backup/notifier/mail.rb +141 -0
- data/lib/backup/notifier/presently.rb +105 -0
- data/lib/backup/notifier/templates/notify_failure.erb +33 -0
- data/lib/backup/notifier/templates/notify_success.erb +16 -0
- data/lib/backup/notifier/twitter.rb +87 -0
- data/lib/backup/storage/base.rb +67 -0
- data/lib/backup/storage/cloudfiles.rb +95 -0
- data/lib/backup/storage/dropbox.rb +91 -0
- data/lib/backup/storage/ftp.rb +114 -0
- data/lib/backup/storage/object.rb +45 -0
- data/lib/backup/storage/rsync.rb +129 -0
- data/lib/backup/storage/s3.rb +180 -0
- data/lib/backup/storage/scp.rb +106 -0
- data/lib/backup/storage/sftp.rb +106 -0
- data/lib/backup/syncer/base.rb +10 -0
- data/lib/backup/syncer/rsync.rb +152 -0
- data/lib/backup/syncer/s3.rb +118 -0
- data/lib/backup/version.rb +43 -0
- data/lib/templates/archive +7 -0
- data/lib/templates/compressor/bzip2 +7 -0
- data/lib/templates/compressor/gzip +7 -0
- data/lib/templates/database/mongodb +14 -0
- data/lib/templates/database/mysql +14 -0
- data/lib/templates/database/postgresql +14 -0
- data/lib/templates/database/redis +13 -0
- data/lib/templates/encryptor/gpg +12 -0
- data/lib/templates/encryptor/openssl +8 -0
- data/lib/templates/notifier/campfire +11 -0
- data/lib/templates/notifier/mail +17 -0
- data/lib/templates/notifier/presently +12 -0
- data/lib/templates/notifier/twitter +12 -0
- data/lib/templates/readme +15 -0
- data/lib/templates/storage/cloudfiles +10 -0
- data/lib/templates/storage/dropbox +12 -0
- data/lib/templates/storage/ftp +11 -0
- data/lib/templates/storage/rsync +10 -0
- data/lib/templates/storage/s3 +21 -0
- data/lib/templates/storage/scp +11 -0
- data/lib/templates/storage/sftp +11 -0
- data/lib/templates/syncer/rsync +17 -0
- data/lib/templates/syncer/s3 +15 -0
- data/spec/archive_spec.rb +90 -0
- data/spec/backup_spec.rb +11 -0
- data/spec/compressor/bzip2_spec.rb +59 -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/campfire_spec.rb +20 -0
- data/spec/configuration/notifier/mail_spec.rb +32 -0
- data/spec/configuration/notifier/twitter_spec.rb +22 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +34 -0
- data/spec/configuration/storage/dropbox_spec.rb +43 -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/configuration/syncer/rsync_spec.rb +46 -0
- data/spec/configuration/syncer/s3_spec.rb +43 -0
- data/spec/database/base_spec.rb +30 -0
- data/spec/database/mongodb_spec.rb +181 -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 +58 -0
- data/spec/model_spec.rb +236 -0
- data/spec/notifier/campfire_spec.rb +96 -0
- data/spec/notifier/mail_spec.rb +97 -0
- data/spec/notifier/presently_spec.rb +99 -0
- data/spec/notifier/twitter_spec.rb +86 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/storage/base_spec.rb +33 -0
- data/spec/storage/cloudfiles_spec.rb +102 -0
- data/spec/storage/dropbox_spec.rb +105 -0
- data/spec/storage/ftp_spec.rb +133 -0
- data/spec/storage/object_spec.rb +74 -0
- data/spec/storage/rsync_spec.rb +131 -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/syncer/rsync_spec.rb +195 -0
- data/spec/syncer/s3_spec.rb +139 -0
- data/spec/version_spec.rb +21 -0
- metadata +231 -0
data/backup.gemspec
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
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.current
|
|
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, written for Linux and Mac OSX, that allows you to easily perform backup operations on both your remote, as well as your local environment. It provides you with an elegant DSL in Ruby for modeling (configuring) your backups. Backup has built-in support for various databases, storage protocols/services, syncers, compressors, encryptors and notifiers which you can mix and match. It was built with modularity, extensibility and simplicity in mind.'
|
|
16
|
+
|
|
17
|
+
##
|
|
18
|
+
# Files and folder that need to be compiled in to the Ruby Gem
|
|
19
|
+
gem.files = %x[git ls-files].split("\n")
|
|
20
|
+
gem.test_files = %x[git ls-files -- {spec}/*].split("\n")
|
|
21
|
+
gem.require_path = 'lib'
|
|
22
|
+
|
|
23
|
+
##
|
|
24
|
+
# The Backup CLI executable
|
|
25
|
+
gem.executables = ['backup']
|
|
26
|
+
|
|
27
|
+
##
|
|
28
|
+
# Production gem dependencies
|
|
29
|
+
gem.add_dependency 'thor', ['~> 0.14.6']
|
|
30
|
+
|
|
31
|
+
end
|
data/bin/backup
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
#! /usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
##
|
|
4
|
+
# Load RubyGems for Ruby <= 1.8.7
|
|
5
|
+
require 'rubygems'
|
|
6
|
+
require 'tempfile'
|
|
7
|
+
require 'fileutils'
|
|
8
|
+
|
|
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
|
+
include Thor::Actions
|
|
26
|
+
|
|
27
|
+
TEMPLATE_DIR = File.expand_path("../../lib/templates", __FILE__)
|
|
28
|
+
|
|
29
|
+
##
|
|
30
|
+
# [Perform]
|
|
31
|
+
# Performs the backup process. The only required option is the --trigger [-t].
|
|
32
|
+
# If the other options (--config_file, --data_path, --tmp_path) aren't specified
|
|
33
|
+
# it'll fallback to the (good) defaults
|
|
34
|
+
method_option :trigger, :type => :string, :aliases => ['-t', '--triggers'], :required => true
|
|
35
|
+
method_option :config_file, :type => :string, :aliases => '-c'
|
|
36
|
+
method_option :data_path, :type => :string, :aliases => '-d'
|
|
37
|
+
method_option :log_path, :type => :string, :aliases => '-l'
|
|
38
|
+
method_option :tmp_path, :type => :string
|
|
39
|
+
method_option :quiet, :type => :boolean, :aliases => '-q'
|
|
40
|
+
desc 'perform', "Performs the backup for the specified trigger.\n" +
|
|
41
|
+
"You may perform multiple backups by providing multiple triggers, separated by commas.\n\n" +
|
|
42
|
+
"Example:\n\s\s$ backup perform --triggers backup1,backup2,backup3,backup4\n\n" +
|
|
43
|
+
"This will invoke 4 backups, and they will run in the order specified (not asynchronous)."
|
|
44
|
+
def perform
|
|
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
|
|
52
|
+
|
|
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
|
|
59
|
+
|
|
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
|
|
66
|
+
|
|
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 and LOG_PATH are created if they do not yet exist
|
|
76
|
+
Array.new([Backup::TMP_PATH, Backup::LOG_PATH]).each do |path|
|
|
77
|
+
FileUtils.mkdir_p(path)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
##
|
|
81
|
+
# Silence Backup::Logger from printing to STDOUT, if --quiet was specified
|
|
82
|
+
if options[:quiet]
|
|
83
|
+
Backup::Logger.send(:const_set, :QUIET, options[:quiet])
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
##
|
|
87
|
+
# Process each trigger
|
|
88
|
+
options[:trigger].split(",").map(&:strip).each do |trigger|
|
|
89
|
+
|
|
90
|
+
##
|
|
91
|
+
# Defines the TRIGGER constant
|
|
92
|
+
Backup.send(:const_set, :TRIGGER, trigger)
|
|
93
|
+
|
|
94
|
+
##
|
|
95
|
+
# Define the TIME constants
|
|
96
|
+
Backup.send(:const_set, :TIME, Time.now.strftime("%Y.%m.%d.%H.%M.%S"))
|
|
97
|
+
|
|
98
|
+
##
|
|
99
|
+
# Ensure DATA_PATH and DATA_PATH/TRIGGER are created if they do not yet exist
|
|
100
|
+
FileUtils.mkdir_p(File.join(Backup::DATA_PATH, Backup::TRIGGER))
|
|
101
|
+
|
|
102
|
+
##
|
|
103
|
+
# Parses the backup configuration file and returns the model instance by trigger
|
|
104
|
+
model = Backup::Finder.new(trigger, Backup::CONFIG_FILE).find
|
|
105
|
+
|
|
106
|
+
##
|
|
107
|
+
# Runs the returned model
|
|
108
|
+
Backup::Logger.message "Performing backup for #{model.label}!"
|
|
109
|
+
model.perform!
|
|
110
|
+
|
|
111
|
+
##
|
|
112
|
+
# Removes the TRIGGER constant
|
|
113
|
+
Backup.send(:remove_const, :TRIGGER) if defined? Backup::TRIGGER
|
|
114
|
+
|
|
115
|
+
##
|
|
116
|
+
# Removes the TIME constant
|
|
117
|
+
Backup.send(:remove_const, :TIME) if defined? Backup::TIME
|
|
118
|
+
|
|
119
|
+
##
|
|
120
|
+
# Reset the Backup::Model.current to nil for the next potential run
|
|
121
|
+
Backup::Model.current = nil
|
|
122
|
+
|
|
123
|
+
##
|
|
124
|
+
# Reset the Backup::Model.all to an empty array since this will be
|
|
125
|
+
# re-filled during the next Backup::Finder.new(arg1, arg2).find
|
|
126
|
+
Backup::Model.all = Array.new
|
|
127
|
+
|
|
128
|
+
##
|
|
129
|
+
# Reset the Backup::Model.extension to 'tar' so it's at it's
|
|
130
|
+
# initial state when the next Backup::Model initializes
|
|
131
|
+
Backup::Model.extension = 'tar'
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
##
|
|
136
|
+
# [Generate]
|
|
137
|
+
# Generates a configuration file based on the arguments passed in.
|
|
138
|
+
# For example, running $ backup generate --databases='mongodb' will generate a pre-populated
|
|
139
|
+
# configuration file with a base MongoDB setup
|
|
140
|
+
desc 'generate', 'Generates configuration blocks based on the arguments you pass in'
|
|
141
|
+
method_option :path, :type => :string
|
|
142
|
+
method_option :databases, :type => :string
|
|
143
|
+
method_option :storages, :type => :string
|
|
144
|
+
method_option :syncers, :type => :string
|
|
145
|
+
method_option :encryptors, :type => :string
|
|
146
|
+
method_option :compressors, :type => :string
|
|
147
|
+
method_option :notifiers, :type => :string
|
|
148
|
+
method_option :archives, :type => :boolean
|
|
149
|
+
def generate
|
|
150
|
+
temp_file = Tempfile.new('backup.rb')
|
|
151
|
+
temp_file << File.read( File.join(TEMPLATE_DIR, 'readme') )
|
|
152
|
+
temp_file << "Backup::Model.new(:my_backup, 'My Backup') do\n\n"
|
|
153
|
+
|
|
154
|
+
if options[:archives]
|
|
155
|
+
temp_file << File.read( File.join(TEMPLATE_DIR, 'archive') ) + "\n\n"
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
[:databases, :storages, :syncers, :encryptors, :compressors, :notifiers].each do |item|
|
|
159
|
+
if options[item]
|
|
160
|
+
options[item].split(',').map(&:strip).uniq.each do |entry|
|
|
161
|
+
if File.exist?( File.join(TEMPLATE_DIR, item.to_s[0..-2], entry) )
|
|
162
|
+
temp_file << File.read( File.join(TEMPLATE_DIR, item.to_s[0..-2], entry) ) + "\n\n"
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
temp_file << "end\n\n"
|
|
169
|
+
temp_file.close
|
|
170
|
+
|
|
171
|
+
path = options[:path] || Backup::PATH
|
|
172
|
+
config = File.join(path, 'config.rb')
|
|
173
|
+
|
|
174
|
+
if overwrite?(config)
|
|
175
|
+
FileUtils.mkdir_p(path)
|
|
176
|
+
File.open(config, 'w') do |file|
|
|
177
|
+
file.write( File.read(temp_file.path) )
|
|
178
|
+
puts "Generated configuration file in '#{ config }'"
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
temp_file.unlink
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
##
|
|
185
|
+
# [Decrypt]
|
|
186
|
+
# Shorthand for decrypting encrypted files
|
|
187
|
+
desc 'decrypt', 'Decrypts encrypted files'
|
|
188
|
+
method_option :encryptor, :type => :string, :required => true
|
|
189
|
+
method_option :in, :type => :string, :required => true
|
|
190
|
+
method_option :out, :type => :string, :required => true
|
|
191
|
+
method_option :base64, :type => :boolean, :default => false
|
|
192
|
+
def decrypt
|
|
193
|
+
case options[:encryptor].downcase
|
|
194
|
+
when 'openssl'
|
|
195
|
+
base64 = options[:base64] ? '-base64' : ''
|
|
196
|
+
%x[openssl aes-256-cbc -d #{base64} -in '#{options[:in]}' -out '#{options[:out]}']
|
|
197
|
+
when 'gpg'
|
|
198
|
+
%x[gpg -o '#{options[:out]}' -d '#{options[:in]}']
|
|
199
|
+
else
|
|
200
|
+
puts "Unknown encryptor: #{options[:encryptor]}"
|
|
201
|
+
puts "Use either 'openssl' or 'gpg'"
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
##
|
|
206
|
+
# [Dependencies]
|
|
207
|
+
# Returns a list of Backup's dependencies
|
|
208
|
+
desc 'dependencies', 'Display the list of dependencies for Backup, or install them through Backup.'
|
|
209
|
+
method_option :install, :type => :string
|
|
210
|
+
method_option :list, :type => :boolean
|
|
211
|
+
def dependencies
|
|
212
|
+
unless options.any?
|
|
213
|
+
puts
|
|
214
|
+
puts "To display a list of available dependencies, run:\n\n"
|
|
215
|
+
puts " backup dependencies --list"
|
|
216
|
+
puts
|
|
217
|
+
puts "To install one of these dependencies (with the correct version), run:\n\n"
|
|
218
|
+
puts " backup dependencies --install <name>"
|
|
219
|
+
exit
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
if options[:list]
|
|
223
|
+
Backup::Dependency.all.each do |name, gemspec|
|
|
224
|
+
puts
|
|
225
|
+
puts name
|
|
226
|
+
puts "--------------------------------------------------"
|
|
227
|
+
puts "version: #{gemspec[:version]}"
|
|
228
|
+
puts "lib required: #{gemspec[:require]}"
|
|
229
|
+
puts "used for: #{gemspec[:for]}"
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
if options[:install]
|
|
234
|
+
puts
|
|
235
|
+
puts "Installing \"#{options[:install]}\" version \"#{Backup::Dependency.all[options[:install]][:version]}\".."
|
|
236
|
+
puts "If this doesn't work, please issue the following command yourself:\n\n"
|
|
237
|
+
puts " gem install #{options[:install]} -v '#{Backup::Dependency.all[options[:install]][:version]}'\n\n"
|
|
238
|
+
puts "Please wait..\n\n"
|
|
239
|
+
puts %x[gem install #{options[:install]} -v '#{Backup::Dependency.all[options[:install]][:version]}']
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
##
|
|
244
|
+
# [Version]
|
|
245
|
+
# Returns the current version of the Backup gem
|
|
246
|
+
map '-v' => :version
|
|
247
|
+
desc 'version', 'Display installed Backup version'
|
|
248
|
+
def version
|
|
249
|
+
puts "Backup #{Backup::Version.current}"
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
private
|
|
253
|
+
|
|
254
|
+
##
|
|
255
|
+
# Helper method for asking the user if he/she wants to overwrite the file
|
|
256
|
+
def overwrite?(path)
|
|
257
|
+
if File.exist?(path)
|
|
258
|
+
return yes? "A configuration file already exists in #{ path }. Do you want to overwrite? [y/n]"
|
|
259
|
+
end
|
|
260
|
+
true
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
##
|
|
266
|
+
# Enable the CLI for the Backup binary
|
|
267
|
+
BackupCLI.start
|
data/lib/backup.rb
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
require 'yaml'
|
|
5
|
+
|
|
6
|
+
##
|
|
7
|
+
# The Backup Ruby Gem
|
|
8
|
+
module Backup
|
|
9
|
+
|
|
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', 'Bzip2']
|
|
22
|
+
ENCRYPTORS = ['OpenSSL', 'GPG']
|
|
23
|
+
SYNCERS = ['RSync', 'S3']
|
|
24
|
+
NOTIFIERS = ['Mail', 'Twitter', 'Campfire', 'Presently']
|
|
25
|
+
|
|
26
|
+
##
|
|
27
|
+
# Backup's internal paths
|
|
28
|
+
LIBRARY_PATH = File.join(File.dirname(__FILE__), 'backup')
|
|
29
|
+
CONFIGURATION_PATH = File.join(LIBRARY_PATH, 'configuration')
|
|
30
|
+
STORAGE_PATH = File.join(LIBRARY_PATH, 'storage')
|
|
31
|
+
DATABASE_PATH = File.join(LIBRARY_PATH, 'database')
|
|
32
|
+
COMPRESSOR_PATH = File.join(LIBRARY_PATH, 'compressor')
|
|
33
|
+
ENCRYPTOR_PATH = File.join(LIBRARY_PATH, 'encryptor')
|
|
34
|
+
NOTIFIER_PATH = File.join(LIBRARY_PATH, 'notifier')
|
|
35
|
+
SYNCER_PATH = File.join(LIBRARY_PATH, 'syncer')
|
|
36
|
+
EXCEPTION_PATH = File.join(LIBRARY_PATH, 'exception')
|
|
37
|
+
|
|
38
|
+
##
|
|
39
|
+
# Backup's Environment paths
|
|
40
|
+
PATH = File.join(ENV['HOME'], 'Backup')
|
|
41
|
+
DATA_PATH = File.join(ENV['HOME'], 'Backup', 'data')
|
|
42
|
+
CONFIG_FILE = File.join(ENV['HOME'], 'Backup', 'config.rb')
|
|
43
|
+
LOG_PATH = File.join(ENV['HOME'], 'Backup', 'log')
|
|
44
|
+
TMP_PATH = File.join(ENV['HOME'], 'Backup', '.tmp')
|
|
45
|
+
|
|
46
|
+
##
|
|
47
|
+
# Autoload Backup base files
|
|
48
|
+
autoload :Model, File.join(LIBRARY_PATH, 'model')
|
|
49
|
+
autoload :Archive, File.join(LIBRARY_PATH, 'archive')
|
|
50
|
+
autoload :CLI, File.join(LIBRARY_PATH, 'cli')
|
|
51
|
+
autoload :Finder, File.join(LIBRARY_PATH, 'finder')
|
|
52
|
+
autoload :Dependency, File.join(LIBRARY_PATH, 'dependency')
|
|
53
|
+
autoload :Logger, File.join(LIBRARY_PATH, 'logger')
|
|
54
|
+
autoload :Version, File.join(LIBRARY_PATH, 'version')
|
|
55
|
+
|
|
56
|
+
##
|
|
57
|
+
# Autoload Backup configuration files
|
|
58
|
+
module Configuration
|
|
59
|
+
autoload :Base, File.join(CONFIGURATION_PATH, 'base')
|
|
60
|
+
autoload :Helpers, File.join(CONFIGURATION_PATH, 'helpers')
|
|
61
|
+
|
|
62
|
+
module Notifier
|
|
63
|
+
autoload :Base, File.join(CONFIGURATION_PATH, 'notifier', 'base')
|
|
64
|
+
autoload :Mail, File.join(CONFIGURATION_PATH, 'notifier', 'mail')
|
|
65
|
+
autoload :Twitter, File.join(CONFIGURATION_PATH, 'notifier', 'twitter')
|
|
66
|
+
autoload :Campfire, File.join(CONFIGURATION_PATH, 'notifier', 'campfire')
|
|
67
|
+
autoload :Presently, File.join(CONFIGURATION_PATH, 'notifier', 'presently')
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
module Encryptor
|
|
71
|
+
autoload :Base, File.join(CONFIGURATION_PATH, 'encryptor', 'base')
|
|
72
|
+
autoload :OpenSSL, File.join(CONFIGURATION_PATH, 'encryptor', 'open_ssl')
|
|
73
|
+
autoload :GPG, File.join(CONFIGURATION_PATH, 'encryptor', 'gpg')
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
module Compressor
|
|
77
|
+
autoload :Base, File.join(CONFIGURATION_PATH, 'compressor', 'base')
|
|
78
|
+
autoload :Gzip, File.join(CONFIGURATION_PATH, 'compressor', 'gzip')
|
|
79
|
+
autoload :Bzip2, File.join(CONFIGURATION_PATH, 'compressor', 'bzip2')
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
module Storage
|
|
83
|
+
autoload :Base, File.join(CONFIGURATION_PATH, 'storage', 'base')
|
|
84
|
+
autoload :S3, File.join(CONFIGURATION_PATH, 'storage', 's3')
|
|
85
|
+
autoload :CloudFiles, File.join(CONFIGURATION_PATH, 'storage', 'cloudfiles')
|
|
86
|
+
autoload :Dropbox, File.join(CONFIGURATION_PATH, 'storage', 'dropbox')
|
|
87
|
+
autoload :FTP, File.join(CONFIGURATION_PATH, 'storage', 'ftp')
|
|
88
|
+
autoload :SFTP, File.join(CONFIGURATION_PATH, 'storage', 'sftp')
|
|
89
|
+
autoload :SCP, File.join(CONFIGURATION_PATH, 'storage', 'scp')
|
|
90
|
+
autoload :RSync, File.join(CONFIGURATION_PATH, 'storage', 'rsync')
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
module Syncer
|
|
94
|
+
autoload :RSync, File.join(CONFIGURATION_PATH, 'syncer', 'rsync')
|
|
95
|
+
autoload :S3, File.join(CONFIGURATION_PATH, 'syncer', 's3')
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
module Database
|
|
99
|
+
autoload :Base, File.join(CONFIGURATION_PATH, 'database', 'base')
|
|
100
|
+
autoload :MySQL, File.join(CONFIGURATION_PATH, 'database', 'mysql')
|
|
101
|
+
autoload :PostgreSQL, File.join(CONFIGURATION_PATH, 'database', 'postgresql')
|
|
102
|
+
autoload :MongoDB, File.join(CONFIGURATION_PATH, 'database', 'mongodb')
|
|
103
|
+
autoload :Redis, File.join(CONFIGURATION_PATH, 'database', 'redis')
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
##
|
|
108
|
+
# Autoload Backup storage files
|
|
109
|
+
module Storage
|
|
110
|
+
autoload :Base, File.join(STORAGE_PATH, 'base')
|
|
111
|
+
autoload :Object, File.join(STORAGE_PATH, 'object')
|
|
112
|
+
autoload :S3, File.join(STORAGE_PATH, 's3')
|
|
113
|
+
autoload :CloudFiles, File.join(STORAGE_PATH, 'cloudfiles')
|
|
114
|
+
autoload :Dropbox, File.join(STORAGE_PATH, 'dropbox')
|
|
115
|
+
autoload :FTP, File.join(STORAGE_PATH, 'ftp')
|
|
116
|
+
autoload :SFTP, File.join(STORAGE_PATH, 'sftp')
|
|
117
|
+
autoload :SCP, File.join(STORAGE_PATH, 'scp')
|
|
118
|
+
autoload :RSync, File.join(STORAGE_PATH, 'rsync')
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
##
|
|
122
|
+
# Autoload Backup syncer files
|
|
123
|
+
module Syncer
|
|
124
|
+
autoload :Base, File.join(SYNCER_PATH, 'base')
|
|
125
|
+
autoload :RSync, File.join(SYNCER_PATH, 'rsync')
|
|
126
|
+
autoload :S3, File.join(SYNCER_PATH, 's3')
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
##
|
|
130
|
+
# Autoload Backup database files
|
|
131
|
+
module Database
|
|
132
|
+
autoload :Base, File.join(DATABASE_PATH, 'base')
|
|
133
|
+
autoload :MySQL, File.join(DATABASE_PATH, 'mysql')
|
|
134
|
+
autoload :PostgreSQL, File.join(DATABASE_PATH, 'postgresql')
|
|
135
|
+
autoload :MongoDB, File.join(DATABASE_PATH, 'mongodb')
|
|
136
|
+
autoload :Redis, File.join(DATABASE_PATH, 'redis')
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
##
|
|
140
|
+
# Autoload compressor files
|
|
141
|
+
module Compressor
|
|
142
|
+
autoload :Base, File.join(COMPRESSOR_PATH, 'base')
|
|
143
|
+
autoload :Gzip, File.join(COMPRESSOR_PATH, 'gzip')
|
|
144
|
+
autoload :Bzip2, File.join(COMPRESSOR_PATH, 'bzip2')
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
##
|
|
148
|
+
# Autoload encryptor files
|
|
149
|
+
module Encryptor
|
|
150
|
+
autoload :Base, File.join(ENCRYPTOR_PATH, 'base')
|
|
151
|
+
autoload :OpenSSL, File.join(ENCRYPTOR_PATH, 'open_ssl')
|
|
152
|
+
autoload :GPG, File.join(ENCRYPTOR_PATH, 'gpg')
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
##
|
|
156
|
+
# Autoload notification files
|
|
157
|
+
module Notifier
|
|
158
|
+
autoload :Base, File.join(NOTIFIER_PATH, 'base')
|
|
159
|
+
autoload :Binder, File.join(NOTIFIER_PATH, 'binder')
|
|
160
|
+
autoload :Mail, File.join(NOTIFIER_PATH, 'mail')
|
|
161
|
+
autoload :Twitter, File.join(NOTIFIER_PATH, 'twitter')
|
|
162
|
+
autoload :Campfire, File.join(NOTIFIER_PATH, 'campfire')
|
|
163
|
+
autoload :Presently, File.join(NOTIFIER_PATH, 'presently')
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
##
|
|
167
|
+
# Autoload exception classes
|
|
168
|
+
module Exception
|
|
169
|
+
autoload :CommandNotFound, File.join(EXCEPTION_PATH, 'command_not_found')
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
##
|
|
173
|
+
# Dynamically defines all the available database, storage, compressor, encryptor and notifier
|
|
174
|
+
# classes inside Backup::Finder to improve the DSL for the configuration file
|
|
175
|
+
(DATABASES + STORAGES + COMPRESSORS + ENCRYPTORS + NOTIFIERS + SYNCERS).each do |constant|
|
|
176
|
+
unless Backup::Finder.const_defined?(constant)
|
|
177
|
+
Backup::Finder.const_set(constant, Class.new)
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
end
|