backup_checksum 3.0.23
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 +7 -0
- data/.travis.yml +10 -0
- data/Gemfile +28 -0
- data/Gemfile.lock +130 -0
- data/Guardfile +21 -0
- data/LICENSE.md +24 -0
- data/README.md +476 -0
- data/backup_checksum.gemspec +32 -0
- data/bin/backup +11 -0
- data/lib/backup.rb +217 -0
- data/lib/backup/archive.rb +117 -0
- data/lib/backup/binder.rb +22 -0
- data/lib/backup/checksum/base.rb +44 -0
- data/lib/backup/checksum/shasum.rb +16 -0
- data/lib/backup/cleaner.rb +121 -0
- data/lib/backup/cli/helpers.rb +88 -0
- data/lib/backup/cli/utility.rb +247 -0
- data/lib/backup/compressor/base.rb +29 -0
- data/lib/backup/compressor/bzip2.rb +50 -0
- data/lib/backup/compressor/gzip.rb +47 -0
- data/lib/backup/compressor/lzma.rb +50 -0
- data/lib/backup/compressor/pbzip2.rb +56 -0
- data/lib/backup/config.rb +173 -0
- data/lib/backup/configuration/base.rb +15 -0
- data/lib/backup/configuration/checksum/base.rb +9 -0
- data/lib/backup/configuration/checksum/shasum.rb +9 -0
- data/lib/backup/configuration/compressor/base.rb +9 -0
- data/lib/backup/configuration/compressor/bzip2.rb +23 -0
- data/lib/backup/configuration/compressor/gzip.rb +23 -0
- data/lib/backup/configuration/compressor/lzma.rb +23 -0
- data/lib/backup/configuration/compressor/pbzip2.rb +28 -0
- data/lib/backup/configuration/database/base.rb +19 -0
- data/lib/backup/configuration/database/mongodb.rb +49 -0
- data/lib/backup/configuration/database/mysql.rb +42 -0
- data/lib/backup/configuration/database/postgresql.rb +41 -0
- data/lib/backup/configuration/database/redis.rb +39 -0
- data/lib/backup/configuration/database/riak.rb +29 -0
- data/lib/backup/configuration/encryptor/base.rb +9 -0
- data/lib/backup/configuration/encryptor/gpg.rb +17 -0
- data/lib/backup/configuration/encryptor/open_ssl.rb +32 -0
- data/lib/backup/configuration/helpers.rb +52 -0
- data/lib/backup/configuration/notifier/base.rb +28 -0
- data/lib/backup/configuration/notifier/campfire.rb +25 -0
- data/lib/backup/configuration/notifier/hipchat.rb +41 -0
- data/lib/backup/configuration/notifier/mail.rb +112 -0
- data/lib/backup/configuration/notifier/presently.rb +25 -0
- data/lib/backup/configuration/notifier/prowl.rb +23 -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 +25 -0
- data/lib/backup/configuration/storage/dropbox.rb +58 -0
- data/lib/backup/configuration/storage/ftp.rb +29 -0
- data/lib/backup/configuration/storage/local.rb +17 -0
- data/lib/backup/configuration/storage/ninefold.rb +20 -0
- data/lib/backup/configuration/storage/rsync.rb +29 -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/base.rb +10 -0
- data/lib/backup/configuration/syncer/cloud.rb +23 -0
- data/lib/backup/configuration/syncer/cloud_files.rb +30 -0
- data/lib/backup/configuration/syncer/rsync/base.rb +28 -0
- data/lib/backup/configuration/syncer/rsync/local.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/pull.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/push.rb +31 -0
- data/lib/backup/configuration/syncer/s3.rb +23 -0
- data/lib/backup/database/base.rb +59 -0
- data/lib/backup/database/mongodb.rb +232 -0
- data/lib/backup/database/mysql.rb +163 -0
- data/lib/backup/database/postgresql.rb +146 -0
- data/lib/backup/database/redis.rb +139 -0
- data/lib/backup/database/riak.rb +69 -0
- data/lib/backup/dependency.rb +114 -0
- data/lib/backup/encryptor/base.rb +29 -0
- data/lib/backup/encryptor/gpg.rb +80 -0
- data/lib/backup/encryptor/open_ssl.rb +72 -0
- data/lib/backup/errors.rb +124 -0
- data/lib/backup/logger.rb +152 -0
- data/lib/backup/model.rb +386 -0
- data/lib/backup/notifier/base.rb +81 -0
- data/lib/backup/notifier/campfire.rb +168 -0
- data/lib/backup/notifier/hipchat.rb +99 -0
- data/lib/backup/notifier/mail.rb +206 -0
- data/lib/backup/notifier/presently.rb +88 -0
- data/lib/backup/notifier/prowl.rb +65 -0
- data/lib/backup/notifier/twitter.rb +70 -0
- data/lib/backup/package.rb +51 -0
- data/lib/backup/packager.rb +108 -0
- data/lib/backup/pipeline.rb +107 -0
- data/lib/backup/splitter.rb +75 -0
- data/lib/backup/storage/base.rb +119 -0
- data/lib/backup/storage/cloudfiles.rb +87 -0
- data/lib/backup/storage/cycler.rb +117 -0
- data/lib/backup/storage/dropbox.rb +181 -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 +42 -0
- data/lib/backup/syncer/cloud.rb +190 -0
- data/lib/backup/syncer/cloud_files.rb +56 -0
- data/lib/backup/syncer/rsync/base.rb +52 -0
- data/lib/backup/syncer/rsync/local.rb +53 -0
- data/lib/backup/syncer/rsync/pull.rb +38 -0
- data/lib/backup/syncer/rsync/push.rb +113 -0
- data/lib/backup/syncer/s3.rb +47 -0
- data/lib/backup/template.rb +46 -0
- data/lib/backup/version.rb +43 -0
- data/spec/archive_spec.rb +335 -0
- data/spec/cleaner_spec.rb +304 -0
- data/spec/cli/helpers_spec.rb +176 -0
- data/spec/cli/utility_spec.rb +363 -0
- data/spec/compressor/base_spec.rb +31 -0
- data/spec/compressor/bzip2_spec.rb +83 -0
- data/spec/compressor/gzip_spec.rb +83 -0
- data/spec/compressor/lzma_spec.rb +83 -0
- data/spec/compressor/pbzip2_spec.rb +124 -0
- data/spec/config_spec.rb +321 -0
- data/spec/configuration/base_spec.rb +35 -0
- data/spec/configuration/compressor/bzip2_spec.rb +29 -0
- data/spec/configuration/compressor/gzip_spec.rb +29 -0
- data/spec/configuration/compressor/lzma_spec.rb +29 -0
- data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
- data/spec/configuration/database/base_spec.rb +17 -0
- data/spec/configuration/database/mongodb_spec.rb +56 -0
- data/spec/configuration/database/mysql_spec.rb +53 -0
- data/spec/configuration/database/postgresql_spec.rb +53 -0
- data/spec/configuration/database/redis_spec.rb +50 -0
- data/spec/configuration/database/riak_spec.rb +35 -0
- data/spec/configuration/encryptor/gpg_spec.rb +26 -0
- data/spec/configuration/encryptor/open_ssl_spec.rb +35 -0
- data/spec/configuration/notifier/base_spec.rb +32 -0
- data/spec/configuration/notifier/campfire_spec.rb +32 -0
- data/spec/configuration/notifier/hipchat_spec.rb +44 -0
- data/spec/configuration/notifier/mail_spec.rb +71 -0
- data/spec/configuration/notifier/presently_spec.rb +35 -0
- data/spec/configuration/notifier/prowl_spec.rb +29 -0
- data/spec/configuration/notifier/twitter_spec.rb +35 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +41 -0
- data/spec/configuration/storage/dropbox_spec.rb +38 -0
- data/spec/configuration/storage/ftp_spec.rb +44 -0
- data/spec/configuration/storage/local_spec.rb +29 -0
- data/spec/configuration/storage/ninefold_spec.rb +32 -0
- data/spec/configuration/storage/rsync_spec.rb +41 -0
- data/spec/configuration/storage/s3_spec.rb +38 -0
- data/spec/configuration/storage/scp_spec.rb +41 -0
- data/spec/configuration/storage/sftp_spec.rb +41 -0
- data/spec/configuration/syncer/cloud_files_spec.rb +44 -0
- data/spec/configuration/syncer/rsync/base_spec.rb +33 -0
- data/spec/configuration/syncer/rsync/local_spec.rb +10 -0
- data/spec/configuration/syncer/rsync/pull_spec.rb +10 -0
- data/spec/configuration/syncer/rsync/push_spec.rb +43 -0
- data/spec/configuration/syncer/s3_spec.rb +38 -0
- data/spec/database/base_spec.rb +54 -0
- data/spec/database/mongodb_spec.rb +428 -0
- data/spec/database/mysql_spec.rb +335 -0
- data/spec/database/postgresql_spec.rb +278 -0
- data/spec/database/redis_spec.rb +260 -0
- data/spec/database/riak_spec.rb +108 -0
- data/spec/dependency_spec.rb +49 -0
- data/spec/encryptor/base_spec.rb +30 -0
- data/spec/encryptor/gpg_spec.rb +134 -0
- data/spec/encryptor/open_ssl_spec.rb +129 -0
- data/spec/errors_spec.rb +306 -0
- data/spec/logger_spec.rb +363 -0
- data/spec/model_spec.rb +649 -0
- data/spec/notifier/base_spec.rb +89 -0
- data/spec/notifier/campfire_spec.rb +199 -0
- data/spec/notifier/hipchat_spec.rb +188 -0
- data/spec/notifier/mail_spec.rb +280 -0
- data/spec/notifier/presently_spec.rb +181 -0
- data/spec/notifier/prowl_spec.rb +117 -0
- data/spec/notifier/twitter_spec.rb +132 -0
- data/spec/package_spec.rb +61 -0
- data/spec/packager_spec.rb +225 -0
- data/spec/pipeline_spec.rb +257 -0
- data/spec/spec_helper.rb +59 -0
- data/spec/splitter_spec.rb +120 -0
- data/spec/storage/base_spec.rb +160 -0
- data/spec/storage/cloudfiles_spec.rb +230 -0
- data/spec/storage/cycler_spec.rb +239 -0
- data/spec/storage/dropbox_spec.rb +370 -0
- data/spec/storage/ftp_spec.rb +247 -0
- data/spec/storage/local_spec.rb +235 -0
- data/spec/storage/ninefold_spec.rb +319 -0
- data/spec/storage/rsync_spec.rb +345 -0
- data/spec/storage/s3_spec.rb +221 -0
- data/spec/storage/scp_spec.rb +209 -0
- data/spec/storage/sftp_spec.rb +220 -0
- data/spec/syncer/base_spec.rb +22 -0
- data/spec/syncer/cloud_files_spec.rb +192 -0
- data/spec/syncer/rsync/base_spec.rb +118 -0
- data/spec/syncer/rsync/local_spec.rb +121 -0
- data/spec/syncer/rsync/pull_spec.rb +90 -0
- data/spec/syncer/rsync/push_spec.rb +327 -0
- data/spec/syncer/s3_spec.rb +192 -0
- data/spec/version_spec.rb +21 -0
- data/templates/cli/utility/archive +25 -0
- data/templates/cli/utility/compressor/bzip2 +7 -0
- data/templates/cli/utility/compressor/gzip +7 -0
- data/templates/cli/utility/compressor/lzma +7 -0
- data/templates/cli/utility/compressor/pbzip2 +7 -0
- data/templates/cli/utility/config +31 -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 +12 -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/presently +13 -0
- data/templates/cli/utility/notifier/prowl +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 +48 -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 +45 -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 +311 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Backup
|
|
4
|
+
module Syncer
|
|
5
|
+
class CloudFiles < Cloud
|
|
6
|
+
|
|
7
|
+
##
|
|
8
|
+
# Rackspace CloudFiles Credentials
|
|
9
|
+
attr_accessor :api_key, :username
|
|
10
|
+
|
|
11
|
+
##
|
|
12
|
+
# Rackspace CloudFiles Container
|
|
13
|
+
attr_accessor :container
|
|
14
|
+
|
|
15
|
+
##
|
|
16
|
+
# Rackspace AuthURL allows you to connect to a different Rackspace datacenter
|
|
17
|
+
# - https://auth.api.rackspacecloud.com (Default: US)
|
|
18
|
+
# - https://lon.auth.api.rackspacecloud.com (UK)
|
|
19
|
+
attr_accessor :auth_url
|
|
20
|
+
|
|
21
|
+
##
|
|
22
|
+
# Improve performance and avoid data transfer costs by setting @servicenet to `true`
|
|
23
|
+
# This only works if Backup runs on a Rackspace server
|
|
24
|
+
attr_accessor :servicenet
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
##
|
|
29
|
+
# Established and creates a new Fog storage object for CloudFiles.
|
|
30
|
+
def connection
|
|
31
|
+
@connection ||= Fog::Storage.new(
|
|
32
|
+
:provider => provider,
|
|
33
|
+
:rackspace_username => username,
|
|
34
|
+
:rackspace_api_key => api_key,
|
|
35
|
+
:rackspace_auth_url => auth_url,
|
|
36
|
+
:rackspace_servicenet => servicenet
|
|
37
|
+
)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
##
|
|
41
|
+
# Creates a new @repository_object (container). Fetches it from Cloud Files
|
|
42
|
+
# if it already exists, otherwise it will create it first and fetch use that instead.
|
|
43
|
+
def repository_object
|
|
44
|
+
@repository_object ||= connection.directories.get(container) ||
|
|
45
|
+
connection.directories.create(:key => container)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
##
|
|
49
|
+
# This is the provider that Fog uses for the Cloud Files
|
|
50
|
+
def provider
|
|
51
|
+
"Rackspace"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
load_defaults!
|
|
16
|
+
|
|
17
|
+
@path ||= 'backups'
|
|
18
|
+
@directories = Array.new
|
|
19
|
+
@mirror ||= false
|
|
20
|
+
@additional_options ||= Array.new
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
##
|
|
26
|
+
# Returns the @directories as a space-delimited string of
|
|
27
|
+
# single-quoted values for use in the `rsync` command line.
|
|
28
|
+
# Each path is expanded, since these refer to local paths
|
|
29
|
+
# for both RSync::Local and RSync::Push.
|
|
30
|
+
# RSync::Pull does not use this method.
|
|
31
|
+
def directories_option
|
|
32
|
+
@directories.map do |directory|
|
|
33
|
+
"'#{ File.expand_path(directory) }'"
|
|
34
|
+
end.join(' ')
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
##
|
|
38
|
+
# Returns Rsync syntax for enabling mirroring
|
|
39
|
+
def mirror_option
|
|
40
|
+
'--delete' if @mirror
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
##
|
|
44
|
+
# Returns Rsync syntax for invoking "archive" mode
|
|
45
|
+
def archive_option
|
|
46
|
+
'--archive'
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
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 object.
|
|
10
|
+
# Default configuration values and any specified in
|
|
11
|
+
# Backup::Configuration::Syncer::RSync::Local are set from Base.
|
|
12
|
+
# The user's configuration file is then evaluated to overwrite
|
|
13
|
+
# these values or provide additional configuration.
|
|
14
|
+
def initialize(&block)
|
|
15
|
+
super
|
|
16
|
+
|
|
17
|
+
instance_eval(&block) if block_given?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
##
|
|
21
|
+
# Performs the RSync::Local operation
|
|
22
|
+
# debug options: -vhP
|
|
23
|
+
def perform!
|
|
24
|
+
Logger.message(
|
|
25
|
+
"#{ syncer_name } started syncing the following directories:\n\s\s" +
|
|
26
|
+
@directories.join("\n\s\s")
|
|
27
|
+
)
|
|
28
|
+
Logger.silent(
|
|
29
|
+
run("#{ utility(:rsync) } #{ options } " +
|
|
30
|
+
"#{ directories_option } '#{ dest_path }'")
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
##
|
|
37
|
+
# Return expanded @path
|
|
38
|
+
def dest_path
|
|
39
|
+
@dest_path ||= File.expand_path(@path)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
##
|
|
43
|
+
# Returns all the specified Rsync::Local options,
|
|
44
|
+
# concatenated, ready for the CLI
|
|
45
|
+
def options
|
|
46
|
+
([archive_option, mirror_option] +
|
|
47
|
+
additional_options).compact.join("\s")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
Logger.silent(
|
|
17
|
+
run("#{ utility(:rsync) } #{ options } " +
|
|
18
|
+
"'#{ username }@#{ ip }:#{ directory.sub(/^\~\//, '') }' " +
|
|
19
|
+
"'#{ dest_path }'")
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
ensure
|
|
24
|
+
remove_password_file!
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
##
|
|
30
|
+
# Return expanded @path
|
|
31
|
+
def dest_path
|
|
32
|
+
@dest_path ||= File.expand_path(@path)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,113 @@
|
|
|
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 object.
|
|
26
|
+
# Default configuration values and any specified in
|
|
27
|
+
# Backup::Configuration::Syncer::RSync::[Push/Pull] are set from Base.
|
|
28
|
+
# The user's configuration file is then evaluated to overwrite
|
|
29
|
+
# these values or provide additional configuration.
|
|
30
|
+
def initialize(&block)
|
|
31
|
+
super
|
|
32
|
+
|
|
33
|
+
@port ||= 22
|
|
34
|
+
@compress ||= false
|
|
35
|
+
|
|
36
|
+
instance_eval(&block) if block_given?
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
##
|
|
40
|
+
# Performs the RSync:Push operation
|
|
41
|
+
# debug options: -vhP
|
|
42
|
+
def perform!
|
|
43
|
+
write_password_file!
|
|
44
|
+
|
|
45
|
+
Logger.message(
|
|
46
|
+
"#{ syncer_name } started syncing the following directories:\n\s\s" +
|
|
47
|
+
@directories.join("\n\s\s")
|
|
48
|
+
)
|
|
49
|
+
Logger.silent(
|
|
50
|
+
run("#{ utility(:rsync) } #{ options } #{ directories_option } " +
|
|
51
|
+
"'#{ username }@#{ ip }:#{ dest_path }'")
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
ensure
|
|
55
|
+
remove_password_file!
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
##
|
|
61
|
+
# Return @path with any preceeding "~/" removed
|
|
62
|
+
def dest_path
|
|
63
|
+
@dest_path ||= @path.sub(/^\~\//, '')
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
##
|
|
67
|
+
# Returns all the specified Rsync::[Push/Pull] options,
|
|
68
|
+
# concatenated, ready for the CLI
|
|
69
|
+
def options
|
|
70
|
+
([archive_option, mirror_option, compress_option, port_option,
|
|
71
|
+
password_option] + additional_options).compact.join("\s")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
##
|
|
75
|
+
# Returns Rsync syntax for compressing the file transfers
|
|
76
|
+
def compress_option
|
|
77
|
+
'--compress' if @compress
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
##
|
|
81
|
+
# Returns Rsync syntax for defining a port to connect to
|
|
82
|
+
def port_option
|
|
83
|
+
"-e 'ssh -p #{@port}'"
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
##
|
|
87
|
+
# Returns Rsync syntax for setting a password (via a file)
|
|
88
|
+
def password_option
|
|
89
|
+
"--password-file='#{@password_file.path}'" if @password_file
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
##
|
|
93
|
+
# Writes the provided password to a temporary file so that
|
|
94
|
+
# the rsync utility can read the password from this file
|
|
95
|
+
def write_password_file!
|
|
96
|
+
unless @password.nil?
|
|
97
|
+
@password_file = Tempfile.new('backup-rsync-password')
|
|
98
|
+
@password_file.write(@password)
|
|
99
|
+
@password_file.close
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
##
|
|
104
|
+
# Removes the previously created @password_file
|
|
105
|
+
# (temporary file containing the password)
|
|
106
|
+
def remove_password_file!
|
|
107
|
+
@password_file.delete if @password_file
|
|
108
|
+
@password_file = nil
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Backup
|
|
4
|
+
module Syncer
|
|
5
|
+
class S3 < Cloud
|
|
6
|
+
|
|
7
|
+
##
|
|
8
|
+
# Amazon Simple Storage Service (S3) Credentials
|
|
9
|
+
attr_accessor :access_key_id, :secret_access_key
|
|
10
|
+
|
|
11
|
+
##
|
|
12
|
+
# The S3 bucket to store files to
|
|
13
|
+
attr_accessor :bucket
|
|
14
|
+
|
|
15
|
+
##
|
|
16
|
+
# The AWS region of the specified S3 bucket
|
|
17
|
+
attr_accessor :region
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
##
|
|
22
|
+
# Established and creates a new Fog storage object for S3.
|
|
23
|
+
def connection
|
|
24
|
+
@connection ||= Fog::Storage.new(
|
|
25
|
+
:provider => provider,
|
|
26
|
+
:aws_access_key_id => access_key_id,
|
|
27
|
+
:aws_secret_access_key => secret_access_key,
|
|
28
|
+
:region => region
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
##
|
|
33
|
+
# Creates a new @repository_object (bucket). Fetches it from S3
|
|
34
|
+
# if it already exists, otherwise it will create it first and fetch use that instead.
|
|
35
|
+
def repository_object
|
|
36
|
+
@repository_object ||= connection.directories.get(bucket) ||
|
|
37
|
+
connection.directories.create(:key => bucket, :location => region)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
##
|
|
41
|
+
# This is the provider that Fog uses for the Cloud Files
|
|
42
|
+
def provider
|
|
43
|
+
"AWS"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
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
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Backup
|
|
4
|
+
class Version
|
|
5
|
+
|
|
6
|
+
##
|
|
7
|
+
# Change the MAJOR, MINOR and PATCH constants below
|
|
8
|
+
# to adjust the version of the Backup gem
|
|
9
|
+
#
|
|
10
|
+
# MAJOR:
|
|
11
|
+
# Defines the major version
|
|
12
|
+
# MINOR:
|
|
13
|
+
# Defines the minor version
|
|
14
|
+
# PATCH:
|
|
15
|
+
# Defines the patch version
|
|
16
|
+
MAJOR, MINOR, PATCH = 3, 0, 23
|
|
17
|
+
|
|
18
|
+
##
|
|
19
|
+
# Returns the major version ( big release based off of multiple minor releases )
|
|
20
|
+
def self.major
|
|
21
|
+
MAJOR
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
##
|
|
25
|
+
# Returns the minor version ( small release based off of multiple patches )
|
|
26
|
+
def self.minor
|
|
27
|
+
MINOR
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
##
|
|
31
|
+
# Returns the patch version ( updates, features and (crucial) bug fixes )
|
|
32
|
+
def self.patch
|
|
33
|
+
PATCH
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
##
|
|
37
|
+
# Returns the current version of the Backup gem ( qualified for the gemspec )
|
|
38
|
+
def self.current
|
|
39
|
+
"#{major}.#{minor}.#{patch}"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
end
|