backup 3.0.20 → 3.0.21

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.
Files changed (178) hide show
  1. data/Gemfile +1 -5
  2. data/Gemfile.lock +46 -50
  3. data/README.md +54 -27
  4. data/lib/backup.rb +16 -39
  5. data/lib/backup/archive.rb +42 -18
  6. data/lib/backup/cleaner.rb +110 -25
  7. data/lib/backup/cli/helpers.rb +17 -32
  8. data/lib/backup/cli/utility.rb +46 -107
  9. data/lib/backup/compressor/base.rb +14 -2
  10. data/lib/backup/compressor/bzip2.rb +10 -24
  11. data/lib/backup/compressor/gzip.rb +10 -24
  12. data/lib/backup/compressor/lzma.rb +10 -23
  13. data/lib/backup/compressor/pbzip2.rb +12 -32
  14. data/lib/backup/config.rb +171 -0
  15. data/lib/backup/configuration/compressor/base.rb +1 -2
  16. data/lib/backup/configuration/compressor/pbzip2.rb +4 -4
  17. data/lib/backup/configuration/database/base.rb +2 -1
  18. data/lib/backup/configuration/database/mongodb.rb +8 -0
  19. data/lib/backup/configuration/database/mysql.rb +4 -0
  20. data/lib/backup/configuration/database/postgresql.rb +4 -0
  21. data/lib/backup/configuration/database/redis.rb +4 -0
  22. data/lib/backup/configuration/database/riak.rb +5 -1
  23. data/lib/backup/configuration/encryptor/base.rb +1 -2
  24. data/lib/backup/configuration/encryptor/open_ssl.rb +1 -1
  25. data/lib/backup/configuration/helpers.rb +7 -2
  26. data/lib/backup/configuration/notifier/base.rb +4 -28
  27. data/lib/backup/configuration/storage/base.rb +1 -1
  28. data/lib/backup/configuration/storage/dropbox.rb +14 -4
  29. data/lib/backup/configuration/syncer/base.rb +10 -0
  30. data/lib/backup/configuration/syncer/rsync/base.rb +28 -0
  31. data/lib/backup/configuration/syncer/rsync/local.rb +11 -0
  32. data/lib/backup/configuration/syncer/rsync/pull.rb +11 -0
  33. data/lib/backup/configuration/syncer/rsync/push.rb +31 -0
  34. data/lib/backup/configuration/syncer/s3.rb +0 -4
  35. data/lib/backup/database/base.rb +25 -7
  36. data/lib/backup/database/mongodb.rb +112 -75
  37. data/lib/backup/database/mysql.rb +54 -29
  38. data/lib/backup/database/postgresql.rb +60 -42
  39. data/lib/backup/database/redis.rb +61 -39
  40. data/lib/backup/database/riak.rb +35 -11
  41. data/lib/backup/dependency.rb +4 -5
  42. data/lib/backup/encryptor/base.rb +13 -1
  43. data/lib/backup/encryptor/gpg.rb +39 -39
  44. data/lib/backup/encryptor/open_ssl.rb +28 -38
  45. data/lib/backup/logger.rb +20 -11
  46. data/lib/backup/model.rb +206 -163
  47. data/lib/backup/notifier/base.rb +27 -25
  48. data/lib/backup/notifier/campfire.rb +7 -13
  49. data/lib/backup/notifier/hipchat.rb +28 -28
  50. data/lib/backup/notifier/mail.rb +24 -26
  51. data/lib/backup/notifier/presently.rb +10 -18
  52. data/lib/backup/notifier/prowl.rb +9 -17
  53. data/lib/backup/notifier/twitter.rb +11 -18
  54. data/lib/backup/package.rb +47 -0
  55. data/lib/backup/packager.rb +81 -16
  56. data/lib/backup/splitter.rb +48 -35
  57. data/lib/backup/storage/base.rb +44 -172
  58. data/lib/backup/storage/cloudfiles.rb +31 -46
  59. data/lib/backup/storage/cycler.rb +117 -0
  60. data/lib/backup/storage/dropbox.rb +92 -76
  61. data/lib/backup/storage/ftp.rb +30 -40
  62. data/lib/backup/storage/local.rb +44 -45
  63. data/lib/backup/storage/ninefold.rb +55 -49
  64. data/lib/backup/storage/rsync.rb +49 -56
  65. data/lib/backup/storage/s3.rb +33 -44
  66. data/lib/backup/storage/scp.rb +21 -48
  67. data/lib/backup/storage/sftp.rb +26 -40
  68. data/lib/backup/syncer/base.rb +7 -0
  69. data/lib/backup/syncer/rsync/base.rb +78 -0
  70. data/lib/backup/syncer/rsync/local.rb +53 -0
  71. data/lib/backup/syncer/rsync/pull.rb +38 -0
  72. data/lib/backup/syncer/rsync/push.rb +113 -0
  73. data/lib/backup/syncer/s3.rb +42 -32
  74. data/lib/backup/version.rb +1 -1
  75. data/spec/archive_spec.rb +235 -69
  76. data/spec/cleaner_spec.rb +304 -0
  77. data/spec/cli/helpers_spec.rb +142 -1
  78. data/spec/cli/utility_spec.rb +338 -13
  79. data/spec/compressor/base_spec.rb +31 -0
  80. data/spec/compressor/bzip2_spec.rb +60 -35
  81. data/spec/compressor/gzip_spec.rb +60 -35
  82. data/spec/compressor/lzma_spec.rb +60 -35
  83. data/spec/compressor/pbzip2_spec.rb +98 -37
  84. data/spec/config_spec.rb +321 -0
  85. data/spec/configuration/base_spec.rb +4 -4
  86. data/spec/configuration/compressor/bzip2_spec.rb +1 -0
  87. data/spec/configuration/compressor/gzip_spec.rb +1 -0
  88. data/spec/configuration/compressor/lzma_spec.rb +1 -0
  89. data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
  90. data/spec/configuration/database/base_spec.rb +2 -1
  91. data/spec/configuration/database/mongodb_spec.rb +26 -16
  92. data/spec/configuration/database/mysql_spec.rb +4 -0
  93. data/spec/configuration/database/postgresql_spec.rb +4 -0
  94. data/spec/configuration/database/redis_spec.rb +4 -0
  95. data/spec/configuration/database/riak_spec.rb +4 -0
  96. data/spec/configuration/encryptor/gpg_spec.rb +1 -0
  97. data/spec/configuration/encryptor/open_ssl_spec.rb +1 -0
  98. data/spec/configuration/notifier/base_spec.rb +32 -0
  99. data/spec/configuration/notifier/campfire_spec.rb +1 -0
  100. data/spec/configuration/notifier/hipchat_spec.rb +1 -0
  101. data/spec/configuration/notifier/mail_spec.rb +1 -0
  102. data/spec/configuration/notifier/presently_spec.rb +1 -0
  103. data/spec/configuration/notifier/prowl_spec.rb +1 -0
  104. data/spec/configuration/notifier/twitter_spec.rb +1 -0
  105. data/spec/configuration/storage/cloudfiles_spec.rb +1 -0
  106. data/spec/configuration/storage/dropbox_spec.rb +4 -3
  107. data/spec/configuration/storage/ftp_spec.rb +1 -0
  108. data/spec/configuration/storage/local_spec.rb +1 -0
  109. data/spec/configuration/storage/ninefold_spec.rb +1 -0
  110. data/spec/configuration/storage/rsync_spec.rb +3 -1
  111. data/spec/configuration/storage/s3_spec.rb +1 -0
  112. data/spec/configuration/storage/scp_spec.rb +1 -0
  113. data/spec/configuration/storage/sftp_spec.rb +1 -0
  114. data/spec/configuration/syncer/rsync/base_spec.rb +33 -0
  115. data/spec/configuration/syncer/rsync/local_spec.rb +10 -0
  116. data/spec/configuration/syncer/rsync/pull_spec.rb +10 -0
  117. data/spec/configuration/syncer/{rsync_spec.rb → rsync/push_spec.rb} +12 -15
  118. data/spec/configuration/syncer/s3_spec.rb +2 -3
  119. data/spec/database/base_spec.rb +35 -20
  120. data/spec/database/mongodb_spec.rb +298 -119
  121. data/spec/database/mysql_spec.rb +147 -72
  122. data/spec/database/postgresql_spec.rb +155 -100
  123. data/spec/database/redis_spec.rb +200 -97
  124. data/spec/database/riak_spec.rb +82 -24
  125. data/spec/dependency_spec.rb +49 -0
  126. data/spec/encryptor/base_spec.rb +30 -0
  127. data/spec/encryptor/gpg_spec.rb +105 -28
  128. data/spec/encryptor/open_ssl_spec.rb +85 -114
  129. data/spec/logger_spec.rb +74 -8
  130. data/spec/model_spec.rb +528 -220
  131. data/spec/notifier/base_spec.rb +89 -0
  132. data/spec/notifier/campfire_spec.rb +147 -119
  133. data/spec/notifier/hipchat_spec.rb +140 -145
  134. data/spec/notifier/mail_spec.rb +190 -248
  135. data/spec/notifier/presently_spec.rb +147 -282
  136. data/spec/notifier/prowl_spec.rb +79 -111
  137. data/spec/notifier/twitter_spec.rb +87 -106
  138. data/spec/package_spec.rb +61 -0
  139. data/spec/packager_spec.rb +154 -0
  140. data/spec/spec_helper.rb +36 -13
  141. data/spec/splitter_spec.rb +90 -41
  142. data/spec/storage/base_spec.rb +95 -239
  143. data/spec/storage/cloudfiles_spec.rb +185 -75
  144. data/spec/storage/cycler_spec.rb +239 -0
  145. data/spec/storage/dropbox_spec.rb +318 -87
  146. data/spec/storage/ftp_spec.rb +165 -152
  147. data/spec/storage/local_spec.rb +206 -54
  148. data/spec/storage/ninefold_spec.rb +264 -128
  149. data/spec/storage/rsync_spec.rb +244 -163
  150. data/spec/storage/s3_spec.rb +175 -64
  151. data/spec/storage/scp_spec.rb +156 -150
  152. data/spec/storage/sftp_spec.rb +153 -135
  153. data/spec/syncer/base_spec.rb +22 -0
  154. data/spec/syncer/rsync/base_spec.rb +118 -0
  155. data/spec/syncer/rsync/local_spec.rb +121 -0
  156. data/spec/syncer/rsync/pull_spec.rb +90 -0
  157. data/spec/syncer/rsync/push_spec.rb +327 -0
  158. data/spec/syncer/s3_spec.rb +180 -91
  159. data/templates/cli/utility/config +1 -1
  160. data/templates/cli/utility/database/mongodb +4 -0
  161. data/templates/cli/utility/database/mysql +3 -0
  162. data/templates/cli/utility/database/postgresql +3 -0
  163. data/templates/cli/utility/database/redis +3 -0
  164. data/templates/cli/utility/database/riak +3 -0
  165. data/templates/cli/utility/storage/dropbox +4 -1
  166. data/templates/cli/utility/syncer/rsync_local +12 -0
  167. data/templates/cli/utility/syncer/{rsync → rsync_pull} +2 -2
  168. data/templates/cli/utility/syncer/rsync_push +17 -0
  169. data/templates/storage/dropbox/authorization_url.erb +1 -1
  170. metadata +42 -17
  171. data/lib/backup/configuration/syncer/rsync.rb +0 -45
  172. data/lib/backup/finder.rb +0 -87
  173. data/lib/backup/storage/object.rb +0 -47
  174. data/lib/backup/syncer/rsync.rb +0 -152
  175. data/spec/backup_spec.rb +0 -11
  176. data/spec/finder_spec.rb +0 -91
  177. data/spec/storage/object_spec.rb +0 -74
  178. data/spec/syncer/rsync_spec.rb +0 -195
@@ -21,48 +21,25 @@ module Backup
21
21
  attr_accessor :region
22
22
 
23
23
  ##
24
- # This is the remote path to where the backup files will be stored
25
- def remote_path
26
- File.join(path, TRIGGER, @time).sub(/^\//, '')
27
- end
24
+ # Creates a new instance of the storage object
25
+ def initialize(model, storage_id = nil, &block)
26
+ super(model, storage_id)
28
27
 
29
- ##
30
- # This is the provider that Fog uses for the S3 Storage
31
- def provider
32
- 'AWS'
33
- end
28
+ @path ||= 'backups'
34
29
 
35
- ##
36
- # Performs the backup transfer
37
- def perform!
38
- super
39
- transfer!
40
- cycle!
30
+ instance_eval(&block) if block_given?
41
31
  end
42
32
 
43
- private
33
+ private
44
34
 
45
35
  ##
46
- # Set configuration defaults before evaluating configuration block,
47
- # after setting defaults from Storage::Base
48
- def pre_configure
49
- super
50
- @path ||= 'backups'
51
- end
52
-
53
- ##
54
- # Adjust configuration after evaluating configuration block,
55
- # after adjustments from Storage::Base
56
- def post_configure
57
- super
36
+ # This is the provider that Fog uses for the S3 Storage
37
+ def provider
38
+ 'AWS'
58
39
  end
59
40
 
60
41
  ##
61
- # Establishes a connection to Amazon S3 and returns the Fog object.
62
- # Not doing any instance variable caching because this object gets persisted in YAML
63
- # format to a file and will issues. This, however has no impact on performance since it only
64
- # gets invoked once per object for a #transfer! and once for a remove! Backups run in the
65
- # background anyway so even if it were a bit slower it shouldn't matter.
42
+ # Establishes a connection to Amazon S3
66
43
  def connection
67
44
  @connection ||= Fog::Storage.new(
68
45
  :provider => provider,
@@ -72,29 +49,41 @@ module Backup
72
49
  )
73
50
  end
74
51
 
52
+ def remote_path_for(package)
53
+ super(package).sub(/^\//, '')
54
+ end
55
+
75
56
  ##
76
57
  # Transfers the archived file to the specified Amazon S3 bucket
77
58
  def transfer!
59
+ remote_path = remote_path_for(@package)
60
+
78
61
  connection.sync_clock
79
- files_to_transfer do |local_file, remote_file|
62
+
63
+ files_to_transfer_for(@package) do |local_file, remote_file|
80
64
  Logger.message "#{storage_name} started transferring " +
81
- "'#{ local_file }' to bucket '#{ bucket }'"
65
+ "'#{ local_file }' to bucket '#{ bucket }'."
82
66
 
83
- connection.put_object(
84
- bucket,
85
- File.join(remote_path, remote_file),
86
- File.open(File.join(local_path, local_file))
87
- )
67
+ File.open(File.join(local_path, local_file), 'r') do |file|
68
+ connection.put_object(
69
+ bucket, File.join(remote_path, remote_file), file
70
+ )
71
+ end
88
72
  end
89
73
  end
90
74
 
91
75
  ##
92
- # Removes the transferred archive file from the Amazon S3 bucket
93
- def remove!
76
+ # Removes the transferred archive file(s) from the storage location.
77
+ # Any error raised will be rescued during Cycling
78
+ # and a warning will be logged, containing the error message.
79
+ def remove!(package)
80
+ remote_path = remote_path_for(package)
81
+
94
82
  connection.sync_clock
95
- transferred_files do |local_file, remote_file|
83
+
84
+ transferred_files_for(package) do |local_file, remote_file|
96
85
  Logger.message "#{storage_name} started removing " +
97
- "'#{ local_file }' from bucket '#{ bucket }'"
86
+ "'#{ local_file }' from bucket '#{ bucket }'."
98
87
 
99
88
  connection.delete_object(bucket, File.join(remote_path, remote_file))
100
89
  end
@@ -6,7 +6,6 @@
6
6
  Backup::Dependency.load('net-ssh')
7
7
  Backup::Dependency.load('net-scp')
8
8
 
9
-
10
9
  module Backup
11
10
  module Storage
12
11
  class SCP < Base
@@ -24,38 +23,20 @@ module Backup
24
23
  attr_accessor :path
25
24
 
26
25
  ##
27
- # This is the remote path to where the backup files will be stored
28
- def remote_path
29
- File.join(path, TRIGGER, @time)
30
- end
31
-
32
- ##
33
- # Performs the backup transfer
34
- def perform!
35
- super
36
- transfer!
37
- cycle!
38
- end
26
+ # Creates a new instance of the storage object
27
+ def initialize(model, storage_id = nil, &block)
28
+ super(model, storage_id)
39
29
 
40
- private
41
-
42
- ##
43
- # Set configuration defaults before evaluating configuration block,
44
- # after setting defaults from Storage::Base
45
- def pre_configure
46
- super
47
30
  @port ||= 22
48
31
  @path ||= 'backups'
49
- end
50
32
 
51
- ##
52
- # Adjust configuration after evaluating configuration block,
53
- # after adjustments from Storage::Base
54
- def post_configure
55
- super
33
+ instance_eval(&block) if block_given?
34
+
56
35
  @path = path.sub(/^\~\//, '')
57
36
  end
58
37
 
38
+ private
39
+
59
40
  ##
60
41
  # Establishes a connection to the remote server
61
42
  # and yields the Net::SSH connection.
@@ -69,10 +50,12 @@ module Backup
69
50
  ##
70
51
  # Transfers the archived file to the specified remote server
71
52
  def transfer!
53
+ remote_path = remote_path_for(@package)
54
+
72
55
  connection do |ssh|
73
- create_remote_directories(ssh)
56
+ ssh.exec!("mkdir -p '#{ remote_path }'")
74
57
 
75
- files_to_transfer do |local_file, remote_file|
58
+ files_to_transfer_for(@package) do |local_file, remote_file|
76
59
  Logger.message "#{storage_name} started transferring " +
77
60
  "'#{local_file}' to '#{ip}'."
78
61
 
@@ -85,11 +68,16 @@ module Backup
85
68
  end
86
69
 
87
70
  ##
88
- # Removes the transferred archive file from the server
89
- def remove!
71
+ # Removes the transferred archive file(s) from the storage location.
72
+ # Any error raised will be rescued during Cycling
73
+ # and a warning will be logged, containing the error message.
74
+ def remove!(package)
75
+ remote_path = remote_path_for(package)
76
+
90
77
  messages = []
91
- transferred_files do |local_file, remote_file|
92
- messages << "#{storage_name} started removing '#{local_file}' from '#{ip}'."
78
+ transferred_files_for(package) do |local_file, remote_file|
79
+ messages << "#{storage_name} started removing " +
80
+ "'#{local_file}' from '#{ip}'."
93
81
  end
94
82
  Logger.message messages.join("\n")
95
83
 
@@ -102,22 +90,7 @@ module Backup
102
90
  unless errors.empty?
103
91
  raise Errors::Storage::SCP::SSHError,
104
92
  "Net::SSH reported the following errors:\n" +
105
- errors.join("\n"), caller(1)
106
- end
107
- end
108
-
109
- ##
110
- # Creates (if they don't exist yet) all the directories on the remote
111
- # server in order to upload the backup file. Net::SCP does not support
112
- # paths to directories that don't yet exist when creating new directories.
113
- # Instead, we split the parts up in to an array (for each '/') and loop through
114
- # that to create the directories one by one. Net::SCP raises an exception when
115
- # the directory it's trying ot create already exists, so we have rescue it
116
- def create_remote_directories(ssh)
117
- path_parts = Array.new
118
- remote_path.split('/').each do |path_part|
119
- path_parts << path_part
120
- ssh.exec!("mkdir '#{path_parts.join('/')}'")
93
+ errors.join("\n")
121
94
  end
122
95
  end
123
96
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  ##
4
4
  # Only load the Net::SFTP library/gem when the Backup::Storage::SFTP class is loaded
5
+ Backup::Dependency.load('net-ssh')
5
6
  Backup::Dependency.load('net-sftp')
6
7
 
7
8
  module Backup
@@ -21,44 +22,22 @@ module Backup
21
22
  attr_accessor :path
22
23
 
23
24
  ##
24
- # This is the remote path to where the backup files will be stored
25
- def remote_path
26
- File.join(path, TRIGGER, @time)
27
- end
28
-
29
- ##
30
- # Performs the backup transfer
31
- def perform!
32
- super
33
- transfer!
34
- cycle!
35
- end
36
-
37
- private
25
+ # Creates a new instance of the storage object
26
+ def initialize(model, storage_id = nil, &block)
27
+ super(model, storage_id)
38
28
 
39
- ##
40
- # Set configuration defaults before evaluating configuration block,
41
- # after setting defaults from Storage::Base
42
- def pre_configure
43
- super
44
29
  @port ||= 22
45
30
  @path ||= 'backups'
46
- end
47
31
 
48
- ##
49
- # Adjust configuration after evaluating configuration block,
50
- # after adjustments from Storage::Base
51
- def post_configure
52
- super
32
+ instance_eval(&block) if block_given?
33
+
53
34
  @path = path.sub(/^\~\//, '')
54
35
  end
55
36
 
37
+ private
38
+
56
39
  ##
57
- # Establishes a connection to the remote server and returns the Net::SFTP object.
58
- # Not doing any instance variable caching because this object gets persisted in YAML
59
- # format to a file and will issues. This, however has no impact on performance since it only
60
- # gets invoked once per object for a #transfer! and once for a remove! Backups run in the
61
- # background anyway so even if it were a bit slower it shouldn't matter.
40
+ # Establishes a connection to the remote server
62
41
  def connection
63
42
  Net::SFTP.start(
64
43
  ip, username,
@@ -70,10 +49,12 @@ module Backup
70
49
  ##
71
50
  # Transfers the archived file to the specified remote server
72
51
  def transfer!
52
+ remote_path = remote_path_for(@package)
53
+
73
54
  connection do |sftp|
74
- create_remote_directories(sftp)
55
+ create_remote_path(remote_path, sftp)
75
56
 
76
- files_to_transfer do |local_file, remote_file|
57
+ files_to_transfer_for(@package) do |local_file, remote_file|
77
58
  Logger.message "#{storage_name} started transferring " +
78
59
  "'#{ local_file }' to '#{ ip }'."
79
60
 
@@ -86,10 +67,14 @@ module Backup
86
67
  end
87
68
 
88
69
  ##
89
- # Removes the transferred archive file from the server
90
- def remove!
70
+ # Removes the transferred archive file(s) from the storage location.
71
+ # Any error raised will be rescued during Cycling
72
+ # and a warning will be logged, containing the error message.
73
+ def remove!(package)
74
+ remote_path = remote_path_for(package)
75
+
91
76
  connection do |sftp|
92
- transferred_files do |local_file, remote_file|
77
+ transferred_files_for(package) do |local_file, remote_file|
93
78
  Logger.message "#{storage_name} started removing " +
94
79
  "'#{ local_file }' from '#{ ip }'."
95
80
 
@@ -103,11 +88,12 @@ module Backup
103
88
  ##
104
89
  # Creates (if they don't exist yet) all the directories on the remote
105
90
  # server in order to upload the backup file. Net::SFTP does not support
106
- # paths to directories that don't yet exist when creating new directories.
107
- # Instead, we split the parts up in to an array (for each '/') and loop through
108
- # that to create the directories one by one. Net::SFTP raises an exception when
109
- # the directory it's trying to create already exists, so we have rescue it
110
- def create_remote_directories(sftp)
91
+ # paths to directories that don't yet exist when creating new
92
+ # directories. Instead, we split the parts up in to an array (for each
93
+ # '/') and loop through that to create the directories one by one.
94
+ # Net::SFTP raises an exception when the directory it's trying to create
95
+ # already exists, so we have rescue it
96
+ def create_remote_path(remote_path, sftp)
111
97
  path_parts = Array.new
112
98
  remote_path.split('/').each do |path_part|
113
99
  path_parts << path_part
@@ -5,6 +5,13 @@ module Backup
5
5
  class Base
6
6
  include Backup::CLI::Helpers
7
7
  include Backup::Configuration::Helpers
8
+
9
+ private
10
+
11
+ def syncer_name
12
+ self.class.to_s.sub('Backup::', '')
13
+ end
14
+
8
15
  end
9
16
  end
10
17
  end
@@ -0,0 +1,78 @@
1
+ # encoding: utf-8
2
+
3
+ module Backup
4
+ module Syncer
5
+ module RSync
6
+ class Base < Syncer::Base
7
+
8
+ ##
9
+ # Path to store the synced files/directories to
10
+ attr_accessor :path
11
+
12
+ ##
13
+ # Directories to sync
14
+ attr_writer :directories
15
+
16
+ ##
17
+ # Flag for mirroring the files/directories
18
+ attr_accessor :mirror
19
+
20
+ ##
21
+ # Additional options for the rsync cli
22
+ attr_accessor :additional_options
23
+
24
+ ##
25
+ # Instantiates a new RSync Syncer object
26
+ # and sets the default configuration
27
+ def initialize
28
+ load_defaults!
29
+
30
+ @path ||= 'backups'
31
+ @directories = Array.new
32
+ @mirror ||= false
33
+ @additional_options ||= Array.new
34
+ end
35
+
36
+ ##
37
+ # Syntactical suger for the DSL for adding directories
38
+ def directories(&block)
39
+ return @directories unless block_given?
40
+ instance_eval(&block)
41
+ end
42
+
43
+ ##
44
+ # Adds a path to the @directories array
45
+ def add(path)
46
+ @directories << path
47
+ end
48
+
49
+ private
50
+
51
+ ##
52
+ # Returns the @directories as a space-delimited string of
53
+ # single-quoted values for use in the `rsync` command line.
54
+ # Each path is expanded, since these refer to local paths
55
+ # for both RSync::Local and RSync::Push.
56
+ # RSync::Pull does not use this method.
57
+ def directories_option
58
+ @directories.map do |directory|
59
+ "'#{ File.expand_path(directory) }'"
60
+ end.join(' ')
61
+ end
62
+
63
+ ##
64
+ # Returns Rsync syntax for enabling mirroring
65
+ def mirror_option
66
+ '--delete' if @mirror
67
+ end
68
+
69
+ ##
70
+ # Returns Rsync syntax for invoking "archive" mode
71
+ def archive_option
72
+ '--archive'
73
+ end
74
+
75
+ end
76
+ end
77
+ end
78
+ 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