backup 3.0.2 → 3.0.3.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/bin/backup +12 -190
- metadata +7 -191
- data/.gitignore +0 -2
- data/.infinity_test +0 -7
- data/.rspec +0 -3
- data/Gemfile +0 -17
- data/Gemfile.lock +0 -88
- data/LICENSE.md +0 -24
- data/README.md +0 -236
- data/backup.gemspec +0 -41
- data/lib/backup.rb +0 -148
- data/lib/backup/archive.rb +0 -54
- data/lib/backup/cli.rb +0 -50
- data/lib/backup/compressor/base.rb +0 -17
- data/lib/backup/compressor/gzip.rb +0 -61
- data/lib/backup/configuration/base.rb +0 -15
- data/lib/backup/configuration/compressor/base.rb +0 -10
- data/lib/backup/configuration/compressor/gzip.rb +0 -23
- data/lib/backup/configuration/database/base.rb +0 -18
- data/lib/backup/configuration/database/mongodb.rb +0 -37
- data/lib/backup/configuration/database/mysql.rb +0 -37
- data/lib/backup/configuration/database/postgresql.rb +0 -37
- data/lib/backup/configuration/database/redis.rb +0 -35
- data/lib/backup/configuration/encryptor/base.rb +0 -10
- data/lib/backup/configuration/encryptor/gpg.rb +0 -17
- data/lib/backup/configuration/encryptor/open_ssl.rb +0 -26
- data/lib/backup/configuration/helpers.rb +0 -54
- data/lib/backup/configuration/notifier/base.rb +0 -39
- data/lib/backup/configuration/notifier/mail.rb +0 -52
- data/lib/backup/configuration/storage/base.rb +0 -18
- data/lib/backup/configuration/storage/cloudfiles.rb +0 -21
- data/lib/backup/configuration/storage/dropbox.rb +0 -25
- data/lib/backup/configuration/storage/ftp.rb +0 -25
- data/lib/backup/configuration/storage/rsync.rb +0 -25
- data/lib/backup/configuration/storage/s3.rb +0 -25
- data/lib/backup/configuration/storage/scp.rb +0 -25
- data/lib/backup/configuration/storage/sftp.rb +0 -25
- data/lib/backup/database/base.rb +0 -33
- data/lib/backup/database/mongodb.rb +0 -137
- data/lib/backup/database/mysql.rb +0 -104
- data/lib/backup/database/postgresql.rb +0 -111
- data/lib/backup/database/redis.rb +0 -105
- data/lib/backup/encryptor/base.rb +0 -17
- data/lib/backup/encryptor/gpg.rb +0 -78
- data/lib/backup/encryptor/open_ssl.rb +0 -67
- data/lib/backup/finder.rb +0 -39
- data/lib/backup/logger.rb +0 -80
- data/lib/backup/model.rb +0 -249
- data/lib/backup/notifier/base.rb +0 -29
- data/lib/backup/notifier/binder.rb +0 -32
- data/lib/backup/notifier/mail.rb +0 -141
- data/lib/backup/notifier/templates/notify_failure.erb +0 -31
- data/lib/backup/notifier/templates/notify_success.erb +0 -16
- data/lib/backup/storage/base.rb +0 -67
- data/lib/backup/storage/cloudfiles.rb +0 -95
- data/lib/backup/storage/dropbox.rb +0 -82
- data/lib/backup/storage/ftp.rb +0 -114
- data/lib/backup/storage/object.rb +0 -45
- data/lib/backup/storage/rsync.rb +0 -100
- data/lib/backup/storage/s3.rb +0 -108
- data/lib/backup/storage/scp.rb +0 -105
- data/lib/backup/storage/sftp.rb +0 -106
- data/lib/backup/version.rb +0 -72
- data/lib/templates/archive +0 -4
- data/lib/templates/compressor/gzip +0 -4
- data/lib/templates/database/mongodb +0 -10
- data/lib/templates/database/mysql +0 -11
- data/lib/templates/database/postgresql +0 -11
- data/lib/templates/database/redis +0 -10
- data/lib/templates/encryptor/gpg +0 -9
- data/lib/templates/encryptor/openssl +0 -5
- data/lib/templates/notifier/mail +0 -14
- data/lib/templates/readme +0 -15
- data/lib/templates/storage/cloudfiles +0 -7
- data/lib/templates/storage/dropbox +0 -8
- data/lib/templates/storage/ftp +0 -8
- data/lib/templates/storage/rsync +0 -7
- data/lib/templates/storage/s3 +0 -8
- data/lib/templates/storage/scp +0 -8
- data/lib/templates/storage/sftp +0 -8
- data/spec/archive_spec.rb +0 -53
- data/spec/backup_spec.rb +0 -11
- data/spec/compressor/gzip_spec.rb +0 -59
- data/spec/configuration/base_spec.rb +0 -35
- data/spec/configuration/compressor/gzip_spec.rb +0 -28
- data/spec/configuration/database/base_spec.rb +0 -16
- data/spec/configuration/database/mongodb_spec.rb +0 -30
- data/spec/configuration/database/mysql_spec.rb +0 -32
- data/spec/configuration/database/postgresql_spec.rb +0 -32
- data/spec/configuration/database/redis_spec.rb +0 -30
- data/spec/configuration/encryptor/gpg_spec.rb +0 -25
- data/spec/configuration/encryptor/open_ssl_spec.rb +0 -31
- data/spec/configuration/notifier/mail_spec.rb +0 -32
- data/spec/configuration/storage/cloudfiles_spec.rb +0 -34
- data/spec/configuration/storage/dropbox_spec.rb +0 -40
- data/spec/configuration/storage/ftp_spec.rb +0 -40
- data/spec/configuration/storage/rsync_spec.rb +0 -37
- data/spec/configuration/storage/s3_spec.rb +0 -37
- data/spec/configuration/storage/scp_spec.rb +0 -40
- data/spec/configuration/storage/sftp_spec.rb +0 -40
- data/spec/database/base_spec.rb +0 -30
- data/spec/database/mongodb_spec.rb +0 -144
- data/spec/database/mysql_spec.rb +0 -150
- data/spec/database/postgresql_spec.rb +0 -164
- data/spec/database/redis_spec.rb +0 -122
- data/spec/encryptor/gpg_spec.rb +0 -57
- data/spec/encryptor/open_ssl_spec.rb +0 -102
- data/spec/logger_spec.rb +0 -37
- data/spec/model_spec.rb +0 -236
- data/spec/notifier/mail_spec.rb +0 -97
- data/spec/spec_helper.rb +0 -21
- data/spec/storage/base_spec.rb +0 -33
- data/spec/storage/cloudfiles_spec.rb +0 -102
- data/spec/storage/dropbox_spec.rb +0 -89
- data/spec/storage/ftp_spec.rb +0 -133
- data/spec/storage/object_spec.rb +0 -74
- data/spec/storage/rsync_spec.rb +0 -115
- data/spec/storage/s3_spec.rb +0 -110
- data/spec/storage/scp_spec.rb +0 -129
- data/spec/storage/sftp_spec.rb +0 -125
- data/spec/version_spec.rb +0 -32
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Backup
|
|
4
|
-
module Configuration
|
|
5
|
-
module Helpers
|
|
6
|
-
|
|
7
|
-
##
|
|
8
|
-
# Finds all the object's getter methods and checks the global
|
|
9
|
-
# configuration for these methods, if they respond then they will
|
|
10
|
-
# assign the object's attribute(s) to that particular global configuration's attribute
|
|
11
|
-
def load_defaults!
|
|
12
|
-
c = self.class.name.split('::')
|
|
13
|
-
configuration = Backup::Configuration.const_get(c[1]).const_get(c[2])
|
|
14
|
-
|
|
15
|
-
getter_methods.each do |attribute|
|
|
16
|
-
if configuration.respond_to?(attribute)
|
|
17
|
-
unless configuration.send(attribute).nil?
|
|
18
|
-
self.send("#{attribute}=", configuration.send(attribute))
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
##
|
|
25
|
-
# Clears all the defaults that may have been set by the user
|
|
26
|
-
def clear_defaults!
|
|
27
|
-
setter_methods.each do |method|
|
|
28
|
-
self.send(method, nil)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
##
|
|
33
|
-
# Returns an array of the setter methods (as String)
|
|
34
|
-
def setter_methods
|
|
35
|
-
methods.map do |method|
|
|
36
|
-
method = method.to_s
|
|
37
|
-
method if method =~ /^\w(\w|\d|\_)+\=$/ and method != 'taguri='
|
|
38
|
-
end.compact
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
##
|
|
42
|
-
# Returns an array of getter methods (as Array)
|
|
43
|
-
def getter_methods
|
|
44
|
-
methods.map do |method|
|
|
45
|
-
method = method.to_s
|
|
46
|
-
if method =~ /^\w(\w|\d|\_)+\=$/ and method != 'taguri='
|
|
47
|
-
method.sub('=','')
|
|
48
|
-
end
|
|
49
|
-
end.compact
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Backup
|
|
4
|
-
module Configuration
|
|
5
|
-
module Notifier
|
|
6
|
-
class Base < Backup::Configuration::Base
|
|
7
|
-
class << self
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
# When set to true, the user will be notified by email
|
|
11
|
-
# when a backup process ends without raising any exceptions
|
|
12
|
-
attr_writer :on_success
|
|
13
|
-
|
|
14
|
-
##
|
|
15
|
-
# When set to true, the user will be notified by email
|
|
16
|
-
# when a backup process raises an exception before finishing
|
|
17
|
-
attr_writer :on_failure
|
|
18
|
-
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
##
|
|
22
|
-
# When @on_success is nil it means it hasn't been defined
|
|
23
|
-
# and will then default to true
|
|
24
|
-
def self.on_success
|
|
25
|
-
return true if @on_success.nil?
|
|
26
|
-
@on_success
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
##
|
|
30
|
-
# When @on_failure is nil it means it hasn't been defined
|
|
31
|
-
# and will then default to true
|
|
32
|
-
def self.on_failure
|
|
33
|
-
return true if @on_failure.nil?
|
|
34
|
-
@on_failure
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Backup
|
|
4
|
-
module Configuration
|
|
5
|
-
module Notifier
|
|
6
|
-
class Mail < Base
|
|
7
|
-
class << self
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
# Sender and Receiver email addresses
|
|
11
|
-
# Examples:
|
|
12
|
-
# sender - my.email.address@gmail.com
|
|
13
|
-
# receiver - your.email.address@gmail.com
|
|
14
|
-
attr_accessor :from, :to
|
|
15
|
-
|
|
16
|
-
##
|
|
17
|
-
# The address to use
|
|
18
|
-
# Example: smtp.gmail.com
|
|
19
|
-
attr_accessor :address
|
|
20
|
-
|
|
21
|
-
##
|
|
22
|
-
# The port to connect to
|
|
23
|
-
# Example: 587
|
|
24
|
-
attr_accessor :port
|
|
25
|
-
|
|
26
|
-
##
|
|
27
|
-
# Your domain (if applicable)
|
|
28
|
-
# Example: mydomain.com
|
|
29
|
-
attr_accessor :domain
|
|
30
|
-
|
|
31
|
-
##
|
|
32
|
-
# Username and Password (sender email's credentials)
|
|
33
|
-
# Examples:
|
|
34
|
-
# user_name - meskyanichi
|
|
35
|
-
# password - my_secret_password
|
|
36
|
-
attr_accessor :user_name, :password
|
|
37
|
-
|
|
38
|
-
##
|
|
39
|
-
# Authentication type
|
|
40
|
-
# Example: plain
|
|
41
|
-
attr_accessor :authentication
|
|
42
|
-
|
|
43
|
-
##
|
|
44
|
-
# Automatically set TLS
|
|
45
|
-
# Example: true
|
|
46
|
-
attr_accessor :enable_starttls_auto
|
|
47
|
-
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Backup
|
|
4
|
-
module Configuration
|
|
5
|
-
module Storage
|
|
6
|
-
class Base < Backup::Configuration::Base
|
|
7
|
-
class << self
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
# Sets the limit to how many backups to keep in the remote location.
|
|
11
|
-
# If the limit exceeds it will remove the oldest backup to make room for the newest
|
|
12
|
-
attr_accessor :keep
|
|
13
|
-
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Backup
|
|
4
|
-
module Configuration
|
|
5
|
-
module Storage
|
|
6
|
-
class CloudFiles < Base
|
|
7
|
-
class << self
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
# Rackspace Cloud Files Credentials
|
|
11
|
-
attr_accessor :api_key, :username
|
|
12
|
-
|
|
13
|
-
##
|
|
14
|
-
# Rackspace Cloud Files container name and path
|
|
15
|
-
attr_accessor :container, :path
|
|
16
|
-
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Backup
|
|
4
|
-
module Configuration
|
|
5
|
-
module Storage
|
|
6
|
-
class Dropbox < Base
|
|
7
|
-
class << self
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
# Dropbox user credentials
|
|
11
|
-
attr_accessor :email, :password
|
|
12
|
-
|
|
13
|
-
##
|
|
14
|
-
# Dropbox API credentials
|
|
15
|
-
attr_accessor :api_key, :api_secret
|
|
16
|
-
|
|
17
|
-
##
|
|
18
|
-
# Path to where the backups will be stored
|
|
19
|
-
attr_accessor :path
|
|
20
|
-
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Backup
|
|
4
|
-
module Configuration
|
|
5
|
-
module Storage
|
|
6
|
-
class FTP < Base
|
|
7
|
-
class << self
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
# Server credentials
|
|
11
|
-
attr_accessor :username, :password
|
|
12
|
-
|
|
13
|
-
##
|
|
14
|
-
# Server IP Address and FTP port
|
|
15
|
-
attr_accessor :ip, :port
|
|
16
|
-
|
|
17
|
-
##
|
|
18
|
-
# Path to store backups to
|
|
19
|
-
attr_accessor :path
|
|
20
|
-
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Backup
|
|
4
|
-
module Configuration
|
|
5
|
-
module Storage
|
|
6
|
-
class RSync < Base
|
|
7
|
-
class << self
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
# Server credentials
|
|
11
|
-
attr_accessor :username, :password
|
|
12
|
-
|
|
13
|
-
##
|
|
14
|
-
# Server IP Address and SSH port
|
|
15
|
-
attr_accessor :ip, :port
|
|
16
|
-
|
|
17
|
-
##
|
|
18
|
-
# Path to store backups to
|
|
19
|
-
attr_accessor :path
|
|
20
|
-
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Backup
|
|
4
|
-
module Configuration
|
|
5
|
-
module Storage
|
|
6
|
-
class S3 < Base
|
|
7
|
-
class << self
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
# Amazon Simple Storage Service (S3) Credentials
|
|
11
|
-
attr_accessor :access_key_id, :secret_access_key
|
|
12
|
-
|
|
13
|
-
##
|
|
14
|
-
# Amazon S3 bucket name and path
|
|
15
|
-
attr_accessor :bucket, :path
|
|
16
|
-
|
|
17
|
-
##
|
|
18
|
-
# Region of the specified S3 bucket
|
|
19
|
-
attr_accessor :region
|
|
20
|
-
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Backup
|
|
4
|
-
module Configuration
|
|
5
|
-
module Storage
|
|
6
|
-
class SCP < Base
|
|
7
|
-
class << self
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
# Server credentials
|
|
11
|
-
attr_accessor :username, :password
|
|
12
|
-
|
|
13
|
-
##
|
|
14
|
-
# Server IP Address and SCP port
|
|
15
|
-
attr_accessor :ip, :port
|
|
16
|
-
|
|
17
|
-
##
|
|
18
|
-
# Path to store backups to
|
|
19
|
-
attr_accessor :path
|
|
20
|
-
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Backup
|
|
4
|
-
module Configuration
|
|
5
|
-
module Storage
|
|
6
|
-
class SFTP < Base
|
|
7
|
-
class << self
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
# Server credentials
|
|
11
|
-
attr_accessor :username, :password
|
|
12
|
-
|
|
13
|
-
##
|
|
14
|
-
# Server IP Address and SFTP port
|
|
15
|
-
attr_accessor :ip, :port
|
|
16
|
-
|
|
17
|
-
##
|
|
18
|
-
# Path to store backups to
|
|
19
|
-
attr_accessor :path
|
|
20
|
-
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
data/lib/backup/database/base.rb
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Backup
|
|
4
|
-
module Database
|
|
5
|
-
class Base
|
|
6
|
-
include Backup::CLI
|
|
7
|
-
include Backup::Configuration::Helpers
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
# Contains the path to where the database should be dumped
|
|
11
|
-
attr_accessor :dump_path
|
|
12
|
-
|
|
13
|
-
##
|
|
14
|
-
# Allows the user to specify the path to a "dump" utility
|
|
15
|
-
# in case it cannot be auto-detected by Backup
|
|
16
|
-
attr_accessor :utility_path
|
|
17
|
-
|
|
18
|
-
##
|
|
19
|
-
# Defines the @dump_path and ensures it exists by creating it
|
|
20
|
-
def prepare!
|
|
21
|
-
@dump_path = File.join(TMP_PATH, TRIGGER, self.class.name.split('::').last)
|
|
22
|
-
mkdir(dump_path)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
##
|
|
26
|
-
# Logs a message to the console and log file to inform
|
|
27
|
-
# the client that Backup is dumping the database
|
|
28
|
-
def log!
|
|
29
|
-
Logger.message("#{ self.class } started dumping and archiving \"#{ name }\".")
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Backup
|
|
4
|
-
module Database
|
|
5
|
-
class MongoDB < Base
|
|
6
|
-
|
|
7
|
-
##
|
|
8
|
-
# Name of the database that needs to get dumped
|
|
9
|
-
attr_accessor :name
|
|
10
|
-
|
|
11
|
-
##
|
|
12
|
-
# Credentials for the specified database
|
|
13
|
-
attr_accessor :username, :password
|
|
14
|
-
|
|
15
|
-
##
|
|
16
|
-
# Connectivity options
|
|
17
|
-
attr_accessor :host, :port
|
|
18
|
-
|
|
19
|
-
##
|
|
20
|
-
# IPv6 support (disabled by default)
|
|
21
|
-
attr_accessor :ipv6
|
|
22
|
-
|
|
23
|
-
##
|
|
24
|
-
# Collections to dump, collections that aren't specified won't get dumped
|
|
25
|
-
attr_accessor :only_collections
|
|
26
|
-
|
|
27
|
-
##
|
|
28
|
-
# Additional "mongodump" options
|
|
29
|
-
attr_accessor :additional_options
|
|
30
|
-
|
|
31
|
-
##
|
|
32
|
-
# Creates a new instance of the MongoDB database object
|
|
33
|
-
def initialize(&block)
|
|
34
|
-
load_defaults!
|
|
35
|
-
|
|
36
|
-
@only_collections ||= Array.new
|
|
37
|
-
@additional_options ||= Array.new
|
|
38
|
-
@ipv6 ||= false
|
|
39
|
-
|
|
40
|
-
instance_eval(&block)
|
|
41
|
-
prepare!
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
##
|
|
45
|
-
# Builds the MongoDB credentials syntax to authenticate the user
|
|
46
|
-
# to perform the database dumping process
|
|
47
|
-
def credential_options
|
|
48
|
-
%w[username password].map do |option|
|
|
49
|
-
next if send(option).nil? or send(option).empty?
|
|
50
|
-
"--#{option}='#{send(option)}'"
|
|
51
|
-
end.compact.join("\s")
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
##
|
|
55
|
-
# Builds the MongoDB connectivity options syntax to connect the user
|
|
56
|
-
# to perform the database dumping process
|
|
57
|
-
def connectivity_options
|
|
58
|
-
%w[host port].map do |option|
|
|
59
|
-
next if send(option).nil? or (send(option).respond_to?(:empty?) and send(option).empty?)
|
|
60
|
-
"--#{option}='#{send(option)}'"
|
|
61
|
-
end.compact.join("\s")
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
##
|
|
65
|
-
# Builds a MongoDB compatible string for the
|
|
66
|
-
# additional options specified by the user
|
|
67
|
-
def additional_options
|
|
68
|
-
@additional_options.join("\s")
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
##
|
|
72
|
-
# Returns an array of collections to dump
|
|
73
|
-
def collections_to_dump
|
|
74
|
-
@only_collections
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
##
|
|
78
|
-
# Returns the MongoDB database selector syntax
|
|
79
|
-
def database
|
|
80
|
-
"--db='#{ name }'"
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
##
|
|
84
|
-
# Returns the mongodump syntax for enabling ipv6
|
|
85
|
-
def ipv6
|
|
86
|
-
@ipv6.eql?(true) ? '--ipv6' : ''
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
##
|
|
90
|
-
# Returns the MongoDB syntax for determining where to output all the database dumps,
|
|
91
|
-
# e.g. ~/Backup/.tmp/MongoDB/<databases here>/<database collections>
|
|
92
|
-
def dump_directory
|
|
93
|
-
"--out='#{ dump_path }'"
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
##
|
|
97
|
-
# Builds the full mongodump string based on all attributes
|
|
98
|
-
def mongodump
|
|
99
|
-
"#{ utility(:mongodump) } #{ database } #{ credential_options } " +
|
|
100
|
-
"#{ connectivity_options } #{ ipv6 } #{ additional_options } #{ dump_directory }"
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
##
|
|
104
|
-
# Performs the mongodump command and outputs the data to the
|
|
105
|
-
# specified path based on the 'trigger'. If the user hasn't specified any
|
|
106
|
-
# specific collections to dump, it'll dump everything. If the user has specified
|
|
107
|
-
# collections to dump, it'll loop through the array of collections and invoke the
|
|
108
|
-
# 'mongodump' command once per collection
|
|
109
|
-
def perform!
|
|
110
|
-
log!
|
|
111
|
-
|
|
112
|
-
if collections_to_dump.is_a?(Array) and not collections_to_dump.empty?
|
|
113
|
-
specific_collection_dump!
|
|
114
|
-
else
|
|
115
|
-
dump!
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
##
|
|
120
|
-
# Builds and runs the mongodump command
|
|
121
|
-
def dump!
|
|
122
|
-
run(mongodump)
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
##
|
|
126
|
-
# For each collection in the @only_collections array, it'll
|
|
127
|
-
# build the whole 'mongodump' command, append the '--collection' option,
|
|
128
|
-
# and run the command built command
|
|
129
|
-
def specific_collection_dump!
|
|
130
|
-
collections_to_dump.each do |collection|
|
|
131
|
-
run("#{mongodump} --collection='#{collection}'")
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
end
|