backup-agoddard 3.0.27
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of backup-agoddard might be problematic. Click here for more details.
- data/.gitignore +8 -0
- data/.travis.yml +10 -0
- data/Gemfile +28 -0
- data/Guardfile +23 -0
- data/LICENSE.md +24 -0
- data/README.md +478 -0
- data/backup.gemspec +32 -0
- data/bin/backup +11 -0
- data/lib/backup.rb +133 -0
- data/lib/backup/archive.rb +117 -0
- data/lib/backup/binder.rb +22 -0
- data/lib/backup/cleaner.rb +121 -0
- data/lib/backup/cli/helpers.rb +93 -0
- data/lib/backup/cli/utility.rb +255 -0
- data/lib/backup/compressor/base.rb +35 -0
- data/lib/backup/compressor/bzip2.rb +50 -0
- data/lib/backup/compressor/custom.rb +53 -0
- data/lib/backup/compressor/gzip.rb +50 -0
- data/lib/backup/compressor/lzma.rb +52 -0
- data/lib/backup/compressor/pbzip2.rb +59 -0
- data/lib/backup/config.rb +174 -0
- data/lib/backup/configuration.rb +33 -0
- data/lib/backup/configuration/helpers.rb +130 -0
- data/lib/backup/configuration/store.rb +24 -0
- data/lib/backup/database/base.rb +53 -0
- data/lib/backup/database/mongodb.rb +230 -0
- data/lib/backup/database/mysql.rb +160 -0
- data/lib/backup/database/postgresql.rb +144 -0
- data/lib/backup/database/redis.rb +136 -0
- data/lib/backup/database/riak.rb +67 -0
- data/lib/backup/dependency.rb +108 -0
- data/lib/backup/encryptor/base.rb +29 -0
- data/lib/backup/encryptor/gpg.rb +760 -0
- data/lib/backup/encryptor/open_ssl.rb +72 -0
- data/lib/backup/errors.rb +124 -0
- data/lib/backup/hooks.rb +68 -0
- data/lib/backup/logger.rb +152 -0
- data/lib/backup/model.rb +409 -0
- data/lib/backup/notifier/base.rb +81 -0
- data/lib/backup/notifier/campfire.rb +155 -0
- data/lib/backup/notifier/hipchat.rb +93 -0
- data/lib/backup/notifier/mail.rb +206 -0
- data/lib/backup/notifier/prowl.rb +65 -0
- data/lib/backup/notifier/pushover.rb +88 -0
- data/lib/backup/notifier/twitter.rb +70 -0
- data/lib/backup/package.rb +47 -0
- data/lib/backup/packager.rb +100 -0
- data/lib/backup/pipeline.rb +110 -0
- data/lib/backup/splitter.rb +75 -0
- data/lib/backup/storage/base.rb +99 -0
- data/lib/backup/storage/cloudfiles.rb +87 -0
- data/lib/backup/storage/cycler.rb +117 -0
- data/lib/backup/storage/dropbox.rb +178 -0
- data/lib/backup/storage/ftp.rb +119 -0
- data/lib/backup/storage/local.rb +82 -0
- data/lib/backup/storage/ninefold.rb +116 -0
- data/lib/backup/storage/rsync.rb +149 -0
- data/lib/backup/storage/s3.rb +94 -0
- data/lib/backup/storage/scp.rb +99 -0
- data/lib/backup/storage/sftp.rb +108 -0
- data/lib/backup/syncer/base.rb +46 -0
- data/lib/backup/syncer/cloud/base.rb +247 -0
- data/lib/backup/syncer/cloud/cloud_files.rb +78 -0
- data/lib/backup/syncer/cloud/s3.rb +68 -0
- data/lib/backup/syncer/rsync/base.rb +49 -0
- data/lib/backup/syncer/rsync/local.rb +55 -0
- data/lib/backup/syncer/rsync/pull.rb +36 -0
- data/lib/backup/syncer/rsync/push.rb +116 -0
- data/lib/backup/template.rb +46 -0
- data/lib/backup/version.rb +43 -0
- data/spec-live/.gitignore +6 -0
- data/spec-live/README +7 -0
- data/spec-live/backups/config.rb +83 -0
- data/spec-live/backups/config.yml.template +46 -0
- data/spec-live/backups/models.rb +184 -0
- data/spec-live/compressor/custom_spec.rb +30 -0
- data/spec-live/compressor/gzip_spec.rb +30 -0
- data/spec-live/encryptor/gpg_keys.rb +239 -0
- data/spec-live/encryptor/gpg_spec.rb +287 -0
- data/spec-live/notifier/mail_spec.rb +121 -0
- data/spec-live/spec_helper.rb +151 -0
- data/spec-live/storage/dropbox_spec.rb +151 -0
- data/spec-live/storage/local_spec.rb +83 -0
- data/spec-live/storage/scp_spec.rb +193 -0
- data/spec-live/syncer/cloud/s3_spec.rb +124 -0
- data/spec/archive_spec.rb +335 -0
- data/spec/cleaner_spec.rb +312 -0
- data/spec/cli/helpers_spec.rb +301 -0
- data/spec/cli/utility_spec.rb +411 -0
- data/spec/compressor/base_spec.rb +52 -0
- data/spec/compressor/bzip2_spec.rb +217 -0
- data/spec/compressor/custom_spec.rb +106 -0
- data/spec/compressor/gzip_spec.rb +217 -0
- data/spec/compressor/lzma_spec.rb +123 -0
- data/spec/compressor/pbzip2_spec.rb +165 -0
- data/spec/config_spec.rb +321 -0
- data/spec/configuration/helpers_spec.rb +247 -0
- data/spec/configuration/store_spec.rb +39 -0
- data/spec/configuration_spec.rb +62 -0
- data/spec/database/base_spec.rb +63 -0
- data/spec/database/mongodb_spec.rb +510 -0
- data/spec/database/mysql_spec.rb +411 -0
- data/spec/database/postgresql_spec.rb +353 -0
- data/spec/database/redis_spec.rb +334 -0
- data/spec/database/riak_spec.rb +176 -0
- data/spec/dependency_spec.rb +51 -0
- data/spec/encryptor/base_spec.rb +40 -0
- data/spec/encryptor/gpg_spec.rb +909 -0
- data/spec/encryptor/open_ssl_spec.rb +148 -0
- data/spec/errors_spec.rb +306 -0
- data/spec/hooks_spec.rb +35 -0
- data/spec/logger_spec.rb +367 -0
- data/spec/model_spec.rb +694 -0
- data/spec/notifier/base_spec.rb +104 -0
- data/spec/notifier/campfire_spec.rb +217 -0
- data/spec/notifier/hipchat_spec.rb +211 -0
- data/spec/notifier/mail_spec.rb +316 -0
- data/spec/notifier/prowl_spec.rb +138 -0
- data/spec/notifier/pushover_spec.rb +123 -0
- data/spec/notifier/twitter_spec.rb +153 -0
- data/spec/package_spec.rb +61 -0
- data/spec/packager_spec.rb +213 -0
- data/spec/pipeline_spec.rb +259 -0
- data/spec/spec_helper.rb +60 -0
- data/spec/splitter_spec.rb +120 -0
- data/spec/storage/base_spec.rb +166 -0
- data/spec/storage/cloudfiles_spec.rb +254 -0
- data/spec/storage/cycler_spec.rb +247 -0
- data/spec/storage/dropbox_spec.rb +480 -0
- data/spec/storage/ftp_spec.rb +271 -0
- data/spec/storage/local_spec.rb +259 -0
- data/spec/storage/ninefold_spec.rb +343 -0
- data/spec/storage/rsync_spec.rb +362 -0
- data/spec/storage/s3_spec.rb +245 -0
- data/spec/storage/scp_spec.rb +233 -0
- data/spec/storage/sftp_spec.rb +244 -0
- data/spec/syncer/base_spec.rb +109 -0
- data/spec/syncer/cloud/base_spec.rb +515 -0
- data/spec/syncer/cloud/cloud_files_spec.rb +181 -0
- data/spec/syncer/cloud/s3_spec.rb +174 -0
- data/spec/syncer/rsync/base_spec.rb +98 -0
- data/spec/syncer/rsync/local_spec.rb +149 -0
- data/spec/syncer/rsync/pull_spec.rb +98 -0
- data/spec/syncer/rsync/push_spec.rb +333 -0
- data/spec/version_spec.rb +21 -0
- data/templates/cli/utility/archive +25 -0
- data/templates/cli/utility/compressor/bzip2 +4 -0
- data/templates/cli/utility/compressor/custom +11 -0
- data/templates/cli/utility/compressor/gzip +4 -0
- data/templates/cli/utility/compressor/lzma +10 -0
- data/templates/cli/utility/compressor/pbzip2 +10 -0
- data/templates/cli/utility/config +32 -0
- data/templates/cli/utility/database/mongodb +18 -0
- data/templates/cli/utility/database/mysql +21 -0
- data/templates/cli/utility/database/postgresql +17 -0
- data/templates/cli/utility/database/redis +16 -0
- data/templates/cli/utility/database/riak +11 -0
- data/templates/cli/utility/encryptor/gpg +27 -0
- data/templates/cli/utility/encryptor/openssl +9 -0
- data/templates/cli/utility/model.erb +23 -0
- data/templates/cli/utility/notifier/campfire +12 -0
- data/templates/cli/utility/notifier/hipchat +15 -0
- data/templates/cli/utility/notifier/mail +22 -0
- data/templates/cli/utility/notifier/prowl +11 -0
- data/templates/cli/utility/notifier/pushover +11 -0
- data/templates/cli/utility/notifier/twitter +13 -0
- data/templates/cli/utility/splitter +7 -0
- data/templates/cli/utility/storage/cloud_files +22 -0
- data/templates/cli/utility/storage/dropbox +20 -0
- data/templates/cli/utility/storage/ftp +12 -0
- data/templates/cli/utility/storage/local +7 -0
- data/templates/cli/utility/storage/ninefold +9 -0
- data/templates/cli/utility/storage/rsync +11 -0
- data/templates/cli/utility/storage/s3 +19 -0
- data/templates/cli/utility/storage/scp +11 -0
- data/templates/cli/utility/storage/sftp +11 -0
- data/templates/cli/utility/syncer/cloud_files +46 -0
- data/templates/cli/utility/syncer/rsync_local +12 -0
- data/templates/cli/utility/syncer/rsync_pull +17 -0
- data/templates/cli/utility/syncer/rsync_push +17 -0
- data/templates/cli/utility/syncer/s3 +43 -0
- data/templates/general/links +11 -0
- data/templates/general/version.erb +2 -0
- data/templates/notifier/mail/failure.erb +9 -0
- data/templates/notifier/mail/success.erb +7 -0
- data/templates/notifier/mail/warning.erb +9 -0
- data/templates/storage/dropbox/authorization_url.erb +6 -0
- data/templates/storage/dropbox/authorized.erb +4 -0
- data/templates/storage/dropbox/cache_file_written.erb +10 -0
- metadata +277 -0
@@ -0,0 +1,78 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Backup
|
4
|
+
module Syncer
|
5
|
+
module Cloud
|
6
|
+
class CloudFiles < Base
|
7
|
+
|
8
|
+
##
|
9
|
+
# Rackspace CloudFiles Credentials
|
10
|
+
attr_accessor :api_key, :username
|
11
|
+
|
12
|
+
##
|
13
|
+
# Rackspace CloudFiles Container
|
14
|
+
attr_accessor :container
|
15
|
+
|
16
|
+
##
|
17
|
+
# Rackspace AuthURL allows you to connect
|
18
|
+
# to a different Rackspace datacenter
|
19
|
+
# - https://auth.api.rackspacecloud.com (Default: US)
|
20
|
+
# - https://lon.auth.api.rackspacecloud.com (UK)
|
21
|
+
attr_accessor :auth_url
|
22
|
+
|
23
|
+
##
|
24
|
+
# Improve performance and avoid data transfer costs
|
25
|
+
# by setting @servicenet to `true`
|
26
|
+
# This only works if Backup runs on a Rackspace server
|
27
|
+
attr_accessor :servicenet
|
28
|
+
|
29
|
+
##
|
30
|
+
# Instantiates a new Cloud::CloudFiles Syncer.
|
31
|
+
#
|
32
|
+
# Pre-configured defaults specified in
|
33
|
+
# Configuration::Syncer::Cloud::CloudFiles
|
34
|
+
# are set via a super() call to Cloud::Base,
|
35
|
+
# which in turn will invoke Syncer::Base.
|
36
|
+
#
|
37
|
+
# Once pre-configured defaults and Cloud specific defaults are set,
|
38
|
+
# the block from the user's configuration file is evaluated.
|
39
|
+
def initialize(&block)
|
40
|
+
super
|
41
|
+
|
42
|
+
instance_eval(&block) if block_given?
|
43
|
+
@path = path.sub(/^\//, '')
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
##
|
49
|
+
# Established and creates a new Fog storage object for CloudFiles.
|
50
|
+
def connection
|
51
|
+
@connection ||= Fog::Storage.new(
|
52
|
+
:provider => provider,
|
53
|
+
:rackspace_username => username,
|
54
|
+
:rackspace_api_key => api_key,
|
55
|
+
:rackspace_auth_url => auth_url,
|
56
|
+
:rackspace_servicenet => servicenet
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
##
|
61
|
+
# Creates a new @repository_object (container).
|
62
|
+
# Fetches it from Cloud Files if it already exists,
|
63
|
+
# otherwise it will create it first and fetch use that instead.
|
64
|
+
def repository_object
|
65
|
+
@repository_object ||= connection.directories.get(container) ||
|
66
|
+
connection.directories.create(:key => container)
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# This is the provider that Fog uses for the Cloud Files
|
71
|
+
def provider
|
72
|
+
"Rackspace"
|
73
|
+
end
|
74
|
+
|
75
|
+
end # class Cloudfiles < Base
|
76
|
+
end # module Cloud
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Backup
|
4
|
+
module Syncer
|
5
|
+
module Cloud
|
6
|
+
class S3 < Base
|
7
|
+
|
8
|
+
##
|
9
|
+
# Amazon Simple Storage Service (S3) Credentials
|
10
|
+
attr_accessor :access_key_id, :secret_access_key
|
11
|
+
|
12
|
+
##
|
13
|
+
# The S3 bucket to store files to
|
14
|
+
attr_accessor :bucket
|
15
|
+
|
16
|
+
##
|
17
|
+
# The AWS region of the specified S3 bucket
|
18
|
+
attr_accessor :region
|
19
|
+
|
20
|
+
##
|
21
|
+
# Instantiates a new Cloud::S3 Syncer.
|
22
|
+
#
|
23
|
+
# Pre-configured defaults specified in
|
24
|
+
# Configuration::Syncer::Cloud::S3
|
25
|
+
# are set via a super() call to Cloud::Base,
|
26
|
+
# which in turn will invoke Syncer::Base.
|
27
|
+
#
|
28
|
+
# Once pre-configured defaults and Cloud specific defaults are set,
|
29
|
+
# the block from the user's configuration file is evaluated.
|
30
|
+
def initialize(&block)
|
31
|
+
super
|
32
|
+
|
33
|
+
instance_eval(&block) if block_given?
|
34
|
+
@path = path.sub(/^\//, '')
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
##
|
40
|
+
# Established and creates a new Fog storage object for S3.
|
41
|
+
def connection
|
42
|
+
@connection ||= Fog::Storage.new(
|
43
|
+
:provider => provider,
|
44
|
+
:aws_access_key_id => access_key_id,
|
45
|
+
:aws_secret_access_key => secret_access_key,
|
46
|
+
:region => region
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Creates a new @repository_object (bucket).
|
52
|
+
# Fetches it from S3 if it already exists,
|
53
|
+
# otherwise it will create it first and fetch use that instead.
|
54
|
+
def repository_object
|
55
|
+
@repository_object ||= connection.directories.get(bucket) ||
|
56
|
+
connection.directories.create(:key => bucket, :location => region)
|
57
|
+
end
|
58
|
+
|
59
|
+
##
|
60
|
+
# This is the provider that Fog uses for the Cloud Files
|
61
|
+
def provider
|
62
|
+
"AWS"
|
63
|
+
end
|
64
|
+
|
65
|
+
end # Class S3 < Base
|
66
|
+
end # module Cloud
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Backup
|
4
|
+
module Syncer
|
5
|
+
module RSync
|
6
|
+
class Base < Syncer::Base
|
7
|
+
##
|
8
|
+
# Additional options for the rsync cli
|
9
|
+
attr_accessor :additional_options
|
10
|
+
|
11
|
+
##
|
12
|
+
# Instantiates a new RSync Syncer object
|
13
|
+
# and sets the default configuration
|
14
|
+
def initialize
|
15
|
+
super
|
16
|
+
|
17
|
+
@additional_options ||= Array.new
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
##
|
23
|
+
# Returns the @directories as a space-delimited string of
|
24
|
+
# single-quoted values for use in the `rsync` command line.
|
25
|
+
# Each path is expanded, since these refer to local paths
|
26
|
+
# for both RSync::Local and RSync::Push.
|
27
|
+
# RSync::Pull does not use this method.
|
28
|
+
def directories_option
|
29
|
+
@directories.map do |directory|
|
30
|
+
"'#{ File.expand_path(directory) }'"
|
31
|
+
end.join(' ')
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Returns Rsync syntax for enabling mirroring
|
36
|
+
def mirror_option
|
37
|
+
'--delete' if @mirror
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Returns Rsync syntax for invoking "archive" mode
|
42
|
+
def archive_option
|
43
|
+
'--archive'
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Backup
|
4
|
+
module Syncer
|
5
|
+
module RSync
|
6
|
+
class Local < Base
|
7
|
+
|
8
|
+
##
|
9
|
+
# Instantiates a new RSync::Local Syncer.
|
10
|
+
#
|
11
|
+
# Pre-configured defaults specified in
|
12
|
+
# Configuration::Syncer::RSync::Local
|
13
|
+
# are set via a super() call to RSync::Base,
|
14
|
+
# which in turn will invoke Syncer::Base.
|
15
|
+
#
|
16
|
+
# Once pre-configured defaults and RSync specific defaults are set,
|
17
|
+
# the block from the user's configuration file is evaluated.
|
18
|
+
def initialize(&block)
|
19
|
+
super
|
20
|
+
|
21
|
+
instance_eval(&block) if block_given?
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Performs the RSync::Local operation
|
26
|
+
# debug options: -vhP
|
27
|
+
def perform!
|
28
|
+
Logger.message(
|
29
|
+
"#{ syncer_name } started syncing the following directories:\n\s\s" +
|
30
|
+
@directories.join("\n\s\s")
|
31
|
+
)
|
32
|
+
run("#{ utility(:rsync) } #{ options } " +
|
33
|
+
"#{ directories_option } '#{ dest_path }'")
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
##
|
39
|
+
# Return expanded @path
|
40
|
+
def dest_path
|
41
|
+
@dest_path ||= File.expand_path(@path)
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Returns all the specified Rsync::Local options,
|
46
|
+
# concatenated, ready for the CLI
|
47
|
+
def options
|
48
|
+
([archive_option, mirror_option] +
|
49
|
+
additional_options).compact.join("\s")
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Backup
|
4
|
+
module Syncer
|
5
|
+
module RSync
|
6
|
+
class Pull < Push
|
7
|
+
|
8
|
+
##
|
9
|
+
# Performs the RSync::Pull operation
|
10
|
+
# debug options: -vhP
|
11
|
+
def perform!
|
12
|
+
write_password_file!
|
13
|
+
|
14
|
+
@directories.each do |directory|
|
15
|
+
Logger.message("#{ syncer_name } started syncing '#{ directory }'.")
|
16
|
+
run("#{ utility(:rsync) } #{ options } " +
|
17
|
+
"'#{ username }@#{ ip }:#{ directory.sub(/^\~\//, '') }' " +
|
18
|
+
"'#{ dest_path }'")
|
19
|
+
end
|
20
|
+
|
21
|
+
ensure
|
22
|
+
remove_password_file!
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
##
|
28
|
+
# Return expanded @path, since this path is local
|
29
|
+
def dest_path
|
30
|
+
@dest_path ||= File.expand_path(@path)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Backup
|
4
|
+
module Syncer
|
5
|
+
module RSync
|
6
|
+
class Push < Base
|
7
|
+
|
8
|
+
##
|
9
|
+
# Server credentials
|
10
|
+
attr_accessor :username, :password
|
11
|
+
|
12
|
+
##
|
13
|
+
# Server IP Address and SSH port
|
14
|
+
attr_accessor :ip
|
15
|
+
|
16
|
+
##
|
17
|
+
# The SSH port to connect to
|
18
|
+
attr_accessor :port
|
19
|
+
|
20
|
+
##
|
21
|
+
# Flag for compressing (only compresses for the transfer)
|
22
|
+
attr_accessor :compress
|
23
|
+
|
24
|
+
##
|
25
|
+
# Instantiates a new RSync::Push or RSync::Pull Syncer.
|
26
|
+
#
|
27
|
+
# Pre-configured defaults specified in
|
28
|
+
# Configuration::Syncer::RSync::Push or
|
29
|
+
# Configuration::Syncer::RSync::Pull
|
30
|
+
# are set via a super() call to RSync::Base,
|
31
|
+
# which in turn will invoke Syncer::Base.
|
32
|
+
#
|
33
|
+
# Once pre-configured defaults and RSync specific defaults are set,
|
34
|
+
# the block from the user's configuration file is evaluated.
|
35
|
+
def initialize(&block)
|
36
|
+
super
|
37
|
+
|
38
|
+
@port ||= 22
|
39
|
+
@compress ||= false
|
40
|
+
|
41
|
+
instance_eval(&block) if block_given?
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Performs the RSync:Push operation
|
46
|
+
# debug options: -vhP
|
47
|
+
def perform!
|
48
|
+
write_password_file!
|
49
|
+
|
50
|
+
Logger.message(
|
51
|
+
"#{ syncer_name } started syncing the following directories:\n\s\s" +
|
52
|
+
@directories.join("\n\s\s")
|
53
|
+
)
|
54
|
+
run("#{ utility(:rsync) } #{ options } #{ directories_option } " +
|
55
|
+
"'#{ username }@#{ ip }:#{ dest_path }'")
|
56
|
+
|
57
|
+
ensure
|
58
|
+
remove_password_file!
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
##
|
64
|
+
# Return @path with any preceeding "~/" removed
|
65
|
+
def dest_path
|
66
|
+
@dest_path ||= @path.sub(/^\~\//, '')
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# Returns all the specified Rsync::[Push/Pull] options,
|
71
|
+
# concatenated, ready for the CLI
|
72
|
+
def options
|
73
|
+
([archive_option, mirror_option, compress_option, port_option,
|
74
|
+
password_option] + additional_options).compact.join("\s")
|
75
|
+
end
|
76
|
+
|
77
|
+
##
|
78
|
+
# Returns Rsync syntax for compressing the file transfers
|
79
|
+
def compress_option
|
80
|
+
'--compress' if @compress
|
81
|
+
end
|
82
|
+
|
83
|
+
##
|
84
|
+
# Returns Rsync syntax for defining a port to connect to
|
85
|
+
def port_option
|
86
|
+
"-e 'ssh -p #{@port}'"
|
87
|
+
end
|
88
|
+
|
89
|
+
##
|
90
|
+
# Returns Rsync syntax for setting a password (via a file)
|
91
|
+
def password_option
|
92
|
+
"--password-file='#{@password_file.path}'" if @password_file
|
93
|
+
end
|
94
|
+
|
95
|
+
##
|
96
|
+
# Writes the provided password to a temporary file so that
|
97
|
+
# the rsync utility can read the password from this file
|
98
|
+
def write_password_file!
|
99
|
+
unless @password.nil?
|
100
|
+
@password_file = Tempfile.new('backup-rsync-password')
|
101
|
+
@password_file.write(@password)
|
102
|
+
@password_file.close
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
##
|
107
|
+
# Removes the previously created @password_file
|
108
|
+
# (temporary file containing the password)
|
109
|
+
def remove_password_file!
|
110
|
+
@password_file.delete if @password_file
|
111
|
+
@password_file = nil
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
module Backup
|
6
|
+
class Template
|
7
|
+
|
8
|
+
# Holds a binding object. Nil if not provided.
|
9
|
+
attr_accessor :binding
|
10
|
+
|
11
|
+
##
|
12
|
+
# Creates a new instance of the Backup::Template class
|
13
|
+
# and optionally takes an argument that can be either a binding object, a Hash or nil
|
14
|
+
def initialize(object = nil)
|
15
|
+
if object.is_a?(Binding)
|
16
|
+
@binding = object
|
17
|
+
elsif object.is_a?(Hash)
|
18
|
+
@binding = Backup::Binder.new(object).get_binding
|
19
|
+
else
|
20
|
+
@binding = nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Renders the provided file (in the context of the binding if any) to the console
|
26
|
+
def render(file)
|
27
|
+
puts result(file)
|
28
|
+
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# Returns a String object containing the contents of the file (in the context of the binding if any)
|
32
|
+
def result(file)
|
33
|
+
ERB.new(file_contents(file), nil, '<>').result(binding)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
##
|
39
|
+
# Reads and returns the contents of the provided file path,
|
40
|
+
# relative from the Backup::TEMPLATE_PATH
|
41
|
+
def file_contents(file)
|
42
|
+
File.read(File.join(Backup::TEMPLATE_PATH, file))
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|