backup-ssh 4.1.10

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 (132) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +24 -0
  3. data/README.md +25 -0
  4. data/bin/backup +5 -0
  5. data/lib/backup.rb +141 -0
  6. data/lib/backup/archive.rb +170 -0
  7. data/lib/backup/binder.rb +22 -0
  8. data/lib/backup/cleaner.rb +116 -0
  9. data/lib/backup/cli.rb +374 -0
  10. data/lib/backup/cloud_io/base.rb +41 -0
  11. data/lib/backup/cloud_io/cloud_files.rb +298 -0
  12. data/lib/backup/cloud_io/s3.rb +260 -0
  13. data/lib/backup/compressor/base.rb +35 -0
  14. data/lib/backup/compressor/bzip2.rb +39 -0
  15. data/lib/backup/compressor/custom.rb +53 -0
  16. data/lib/backup/compressor/gzip.rb +74 -0
  17. data/lib/backup/config.rb +119 -0
  18. data/lib/backup/config/dsl.rb +103 -0
  19. data/lib/backup/config/helpers.rb +143 -0
  20. data/lib/backup/database/base.rb +85 -0
  21. data/lib/backup/database/mongodb.rb +186 -0
  22. data/lib/backup/database/mysql.rb +200 -0
  23. data/lib/backup/database/openldap.rb +95 -0
  24. data/lib/backup/database/postgresql.rb +133 -0
  25. data/lib/backup/database/redis.rb +179 -0
  26. data/lib/backup/database/riak.rb +82 -0
  27. data/lib/backup/database/sqlite.rb +57 -0
  28. data/lib/backup/encryptor/base.rb +29 -0
  29. data/lib/backup/encryptor/gpg.rb +747 -0
  30. data/lib/backup/encryptor/open_ssl.rb +77 -0
  31. data/lib/backup/errors.rb +58 -0
  32. data/lib/backup/logger.rb +199 -0
  33. data/lib/backup/logger/console.rb +51 -0
  34. data/lib/backup/logger/fog_adapter.rb +29 -0
  35. data/lib/backup/logger/logfile.rb +133 -0
  36. data/lib/backup/logger/syslog.rb +116 -0
  37. data/lib/backup/model.rb +454 -0
  38. data/lib/backup/notifier/base.rb +98 -0
  39. data/lib/backup/notifier/campfire.rb +69 -0
  40. data/lib/backup/notifier/datadog.rb +116 -0
  41. data/lib/backup/notifier/flowdock.rb +102 -0
  42. data/lib/backup/notifier/hipchat.rb +93 -0
  43. data/lib/backup/notifier/http_post.rb +122 -0
  44. data/lib/backup/notifier/mail.rb +238 -0
  45. data/lib/backup/notifier/nagios.rb +74 -0
  46. data/lib/backup/notifier/pagerduty.rb +81 -0
  47. data/lib/backup/notifier/prowl.rb +69 -0
  48. data/lib/backup/notifier/pushover.rb +80 -0
  49. data/lib/backup/notifier/ses.rb +94 -0
  50. data/lib/backup/notifier/slack.rb +154 -0
  51. data/lib/backup/notifier/twitter.rb +64 -0
  52. data/lib/backup/notifier/zabbix.rb +68 -0
  53. data/lib/backup/package.rb +51 -0
  54. data/lib/backup/packager.rb +101 -0
  55. data/lib/backup/pipeline.rb +124 -0
  56. data/lib/backup/splitter.rb +76 -0
  57. data/lib/backup/storage/base.rb +57 -0
  58. data/lib/backup/storage/cloud_files.rb +158 -0
  59. data/lib/backup/storage/cycler.rb +65 -0
  60. data/lib/backup/storage/dropbox.rb +236 -0
  61. data/lib/backup/storage/ftp.rb +98 -0
  62. data/lib/backup/storage/local.rb +64 -0
  63. data/lib/backup/storage/ninefold.rb +74 -0
  64. data/lib/backup/storage/rsync.rb +248 -0
  65. data/lib/backup/storage/s3.rb +155 -0
  66. data/lib/backup/storage/scp.rb +67 -0
  67. data/lib/backup/storage/sftp.rb +82 -0
  68. data/lib/backup/syncer/base.rb +70 -0
  69. data/lib/backup/syncer/cloud/base.rb +179 -0
  70. data/lib/backup/syncer/cloud/cloud_files.rb +83 -0
  71. data/lib/backup/syncer/cloud/local_file.rb +100 -0
  72. data/lib/backup/syncer/cloud/s3.rb +110 -0
  73. data/lib/backup/syncer/rsync/base.rb +48 -0
  74. data/lib/backup/syncer/rsync/local.rb +31 -0
  75. data/lib/backup/syncer/rsync/pull.rb +51 -0
  76. data/lib/backup/syncer/rsync/push.rb +205 -0
  77. data/lib/backup/template.rb +46 -0
  78. data/lib/backup/utilities.rb +224 -0
  79. data/lib/backup/version.rb +5 -0
  80. data/templates/cli/archive +28 -0
  81. data/templates/cli/compressor/bzip2 +4 -0
  82. data/templates/cli/compressor/custom +7 -0
  83. data/templates/cli/compressor/gzip +4 -0
  84. data/templates/cli/config +123 -0
  85. data/templates/cli/databases/mongodb +15 -0
  86. data/templates/cli/databases/mysql +18 -0
  87. data/templates/cli/databases/openldap +24 -0
  88. data/templates/cli/databases/postgresql +16 -0
  89. data/templates/cli/databases/redis +16 -0
  90. data/templates/cli/databases/riak +17 -0
  91. data/templates/cli/databases/sqlite +11 -0
  92. data/templates/cli/encryptor/gpg +27 -0
  93. data/templates/cli/encryptor/openssl +9 -0
  94. data/templates/cli/model +26 -0
  95. data/templates/cli/notifier/zabbix +15 -0
  96. data/templates/cli/notifiers/campfire +12 -0
  97. data/templates/cli/notifiers/datadog +57 -0
  98. data/templates/cli/notifiers/flowdock +16 -0
  99. data/templates/cli/notifiers/hipchat +15 -0
  100. data/templates/cli/notifiers/http_post +32 -0
  101. data/templates/cli/notifiers/mail +21 -0
  102. data/templates/cli/notifiers/nagios +13 -0
  103. data/templates/cli/notifiers/pagerduty +12 -0
  104. data/templates/cli/notifiers/prowl +11 -0
  105. data/templates/cli/notifiers/pushover +11 -0
  106. data/templates/cli/notifiers/ses +15 -0
  107. data/templates/cli/notifiers/slack +22 -0
  108. data/templates/cli/notifiers/twitter +13 -0
  109. data/templates/cli/splitter +7 -0
  110. data/templates/cli/storages/cloud_files +11 -0
  111. data/templates/cli/storages/dropbox +19 -0
  112. data/templates/cli/storages/ftp +12 -0
  113. data/templates/cli/storages/local +7 -0
  114. data/templates/cli/storages/ninefold +9 -0
  115. data/templates/cli/storages/rsync +17 -0
  116. data/templates/cli/storages/s3 +14 -0
  117. data/templates/cli/storages/scp +14 -0
  118. data/templates/cli/storages/sftp +14 -0
  119. data/templates/cli/syncers/cloud_files +22 -0
  120. data/templates/cli/syncers/rsync_local +20 -0
  121. data/templates/cli/syncers/rsync_pull +28 -0
  122. data/templates/cli/syncers/rsync_push +28 -0
  123. data/templates/cli/syncers/s3 +27 -0
  124. data/templates/general/links +3 -0
  125. data/templates/general/version.erb +2 -0
  126. data/templates/notifier/mail/failure.erb +16 -0
  127. data/templates/notifier/mail/success.erb +16 -0
  128. data/templates/notifier/mail/warning.erb +16 -0
  129. data/templates/storage/dropbox/authorization_url.erb +6 -0
  130. data/templates/storage/dropbox/authorized.erb +4 -0
  131. data/templates/storage/dropbox/cache_file_written.erb +10 -0
  132. metadata +1057 -0
@@ -0,0 +1,69 @@
1
+ # encoding: utf-8
2
+ require 'uri'
3
+
4
+ module Backup
5
+ module Notifier
6
+ class Prowl < Base
7
+
8
+ ##
9
+ # Application name
10
+ # Tell something like your server name. Example: "Server1 Backup"
11
+ attr_accessor :application
12
+
13
+ ##
14
+ # API-Key
15
+ # Create a Prowl account and request an API key on prowlapp.com.
16
+ attr_accessor :api_key
17
+
18
+ def initialize(model, &block)
19
+ super
20
+ instance_eval(&block) if block_given?
21
+ end
22
+
23
+ private
24
+
25
+ ##
26
+ # Notify the user of the backup operation results.
27
+ #
28
+ # `status` indicates one of the following:
29
+ #
30
+ # `:success`
31
+ # : The backup completed successfully.
32
+ # : Notification will be sent if `on_success` is `true`.
33
+ #
34
+ # `:warning`
35
+ # : The backup completed successfully, but warnings were logged.
36
+ # : Notification will be sent if `on_warning` or `on_success` is `true`.
37
+ #
38
+ # `:failure`
39
+ # : The backup operation failed.
40
+ # : Notification will be sent if `on_warning` or `on_success` is `true`.
41
+ #
42
+ def notify!(status)
43
+ tag = case status
44
+ when :success then '[Backup::Success]'
45
+ when :warning then '[Backup::Warning]'
46
+ when :failure then '[Backup::Failure]'
47
+ end
48
+ send_message(tag)
49
+ end
50
+
51
+ def send_message(message)
52
+ uri = 'https://api.prowlapp.com/publicapi/add'
53
+ data = {
54
+ :application => application,
55
+ :apikey => api_key,
56
+ :event => message,
57
+ :description => "#{ model.label } (#{ model.trigger })"
58
+ }
59
+ options = {
60
+ :headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
61
+ :body => URI.encode_www_form(data)
62
+ }
63
+ options.merge!(:expects => 200) # raise error if unsuccessful
64
+ Excon.post(uri, options)
65
+ end
66
+
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,80 @@
1
+ # encoding: utf-8
2
+ require 'uri'
3
+
4
+ module Backup
5
+ module Notifier
6
+ class Pushover < Base
7
+
8
+ ##
9
+ # The API User Token
10
+ attr_accessor :user
11
+
12
+ ##
13
+ # The API Application Token
14
+ attr_accessor :token
15
+
16
+ ##
17
+ # The user's device identifier to sent the message directly to,
18
+ # rather than all of the user's devices
19
+ attr_accessor :device
20
+
21
+ ##
22
+ # The message title
23
+ attr_accessor :title
24
+
25
+ ##
26
+ # The priority of the notification
27
+ attr_accessor :priority
28
+
29
+ def initialize(model, &block)
30
+ super
31
+ instance_eval(&block) if block_given?
32
+ end
33
+
34
+ private
35
+
36
+ ##
37
+ # Notify the user of the backup operation results.
38
+ #
39
+ # `status` indicates one of the following:
40
+ #
41
+ # `:success`
42
+ # : The backup completed successfully.
43
+ # : Notification will be sent if `on_success` is `true`.
44
+ #
45
+ # `:warning`
46
+ # : The backup completed successfully, but warnings were logged.
47
+ # : Notification will be sent if `on_warning` or `on_success` is `true`.
48
+ #
49
+ # `:failure`
50
+ # : The backup operation failed.
51
+ # : Notification will be sent if `on_warning` or `on_success` is `true`.
52
+ #
53
+ def notify!(status)
54
+ tag = case status
55
+ when :success then '[Backup::Success]'
56
+ when :failure then '[Backup::Failure]'
57
+ when :warning then '[Backup::Warning]'
58
+ end
59
+ message = "#{ tag } #{ model.label } (#{ model.trigger })"
60
+ send_message(message)
61
+ end
62
+
63
+ def send_message(message)
64
+ uri = 'https://api.pushover.net/1/messages.json'
65
+ data = { :user => user, :token => token, :message => message }
66
+ [:device, :title, :priority].each do |param|
67
+ val = send(param)
68
+ data.merge!(param => val) if val
69
+ end
70
+ options = {
71
+ :headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
72
+ :body => URI.encode_www_form(data)
73
+ }
74
+ options.merge!(:expects => 200) # raise error if unsuccessful
75
+ Excon.post(uri, options)
76
+ end
77
+
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,94 @@
1
+ # encoding: utf-8
2
+ require 'aws/ses'
3
+
4
+ module Backup
5
+ module Notifier
6
+ class Ses < Base
7
+
8
+ ##
9
+ # Amazon Simple Email Service (SES) Credentials
10
+ attr_accessor :access_key_id, :secret_access_key
11
+
12
+ ##
13
+ # SES Region
14
+ attr_accessor :region
15
+
16
+ ##
17
+ # Sender Email Address
18
+ attr_accessor :from
19
+
20
+ ##
21
+ # Receiver Email Address
22
+ attr_accessor :to
23
+
24
+ def initialize(model, &block)
25
+ super
26
+ instance_eval(&block) if block_given?
27
+
28
+ @region ||= 'eu-west-1'
29
+ @send_log_on ||= [:warning, :failure]
30
+ end
31
+
32
+ ##
33
+ # Array of statuses for which the log file should be attached.
34
+ #
35
+ # Available statuses are: `:success`, `:warning` and `:failure`.
36
+ # Default: [:warning, :failure]
37
+ attr_accessor :send_log_on
38
+
39
+ private
40
+
41
+ def client
42
+ AWS::SES::Base.new(
43
+ :access_key_id => access_key_id,
44
+ :secret_access_key => secret_access_key,
45
+ :server => "email.#{region}.amazonaws.com"
46
+ )
47
+ end
48
+
49
+ ##
50
+ # Notify the user of the backup operation results.
51
+ #
52
+ # `status` indicates one of the following:
53
+ #
54
+ # `:success`
55
+ # : The backup completed successfully.
56
+ # : Notification will be sent if `on_success` is `true`.
57
+ #
58
+ # `:warning`
59
+ # : The backup completed successfully, but warnings were logged.
60
+ # : Notification will be sent, including a copy of the current
61
+ # : backup log, if `on_warning` or `on_success` is `true`.
62
+ #
63
+ # `:failure`
64
+ # : The backup operation failed.
65
+ # : Notification will be sent, including a copy of the current
66
+ # : backup log, if `on_failure` is `true`.
67
+ #
68
+ def notify!(status)
69
+ tag = case status
70
+ when :success then '[Backup::Success]'
71
+ when :warning then '[Backup::Warning]'
72
+ when :failure then '[Backup::Failure]'
73
+ end
74
+
75
+ email = ::Mail.new(:to => to, :from => from)
76
+ email.subject = "#{ tag } #{ model.label } (#{ model.trigger })"
77
+
78
+ send_log = send_log_on.include?(status)
79
+ template = Backup::Template.new({ :model => model, :send_log => send_log })
80
+ email.body = template.result('notifier/mail/%s.erb' % status.to_s)
81
+
82
+ if send_log
83
+ email.convert_to_multipart
84
+ email.attachments["#{ model.time }.#{ model.trigger }.log"] = {
85
+ :mime_type => 'text/plain;',
86
+ :content => Logger.messages.map(&:formatted_lines).flatten.join("\n")
87
+ }
88
+ end
89
+
90
+ client.send_raw_email(email)
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,154 @@
1
+ # encoding: utf-8
2
+ require 'uri'
3
+ require 'json'
4
+
5
+ module Backup
6
+ module Notifier
7
+ class Slack < Base
8
+
9
+ ##
10
+ # The incoming webhook url
11
+ attr_accessor :webhook_url
12
+
13
+ ##
14
+ # The channel to send messages to
15
+ attr_accessor :channel
16
+
17
+ ##
18
+ # The username to display along with the notification
19
+ attr_accessor :username
20
+
21
+ ##
22
+ # The emoji icon to display along with the notification
23
+ #
24
+ # See http://www.emoji-cheat-sheet.com for a list of icons.
25
+ #
26
+ # Default: :floppy_disk:
27
+ attr_accessor :icon_emoji
28
+
29
+ ##
30
+ # Array of statuses for which the log file should be attached.
31
+ #
32
+ # Available statuses are: `:success`, `:warning` and `:failure`.
33
+ # Default: [:warning, :failure]
34
+ attr_accessor :send_log_on
35
+
36
+ def initialize(model, &block)
37
+ super
38
+ instance_eval(&block) if block_given?
39
+
40
+ @send_log_on ||= [:warning, :failure]
41
+ @icon_emoji ||= ':floppy_disk:'
42
+ end
43
+
44
+ private
45
+
46
+ ##
47
+ # Notify the user of the backup operation results.
48
+ #
49
+ # `status` indicates one of the following:
50
+ #
51
+ # `:success`
52
+ # : The backup completed successfully.
53
+ # : Notification will be sent if `on_success` is `true`.
54
+ #
55
+ # `:warning`
56
+ # : The backup completed successfully, but warnings were logged.
57
+ # : Notification will be sent if `on_warning` or `on_success` is `true`.
58
+ #
59
+ # `:failure`
60
+ # : The backup operation failed.
61
+ # : Notification will be sent if `on_warning` or `on_success` is `true`.
62
+ #
63
+ def notify!(status)
64
+ tag = case status
65
+ when :success then '[Backup::Success]'
66
+ when :failure then '[Backup::Failure]'
67
+ when :warning then '[Backup::Warning]'
68
+ end
69
+ message = "#{ tag } #{ model.label } (#{ model.trigger })"
70
+
71
+ data = { :text => message }
72
+ [:channel, :username, :icon_emoji].each do |param|
73
+ val = send(param)
74
+ data.merge!(param => val) if val
75
+ end
76
+
77
+ data.merge!(:attachments => [attachment(status)])
78
+
79
+ options = {
80
+ :headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
81
+ :body => URI.encode_www_form(:payload => JSON.dump(data))
82
+ }
83
+ options.merge!(:expects => 200) # raise error if unsuccessful
84
+ Excon.post(uri, options)
85
+ end
86
+
87
+ def attachment(status)
88
+ {
89
+ :fallback => "#{title(status)} - Job: #{model.label} (#{model.trigger})",
90
+ :text => title(status),
91
+ :color => color(status),
92
+ :fields => [
93
+ {
94
+ :title => "Job",
95
+ :value => "#{model.label} (#{model.trigger})",
96
+ :short => false
97
+ },
98
+ {
99
+ :title => "Started",
100
+ :value => model.started_at,
101
+ :short => true
102
+ },
103
+ {
104
+ :title => "Finished",
105
+ :value => model.finished_at,
106
+ :short => true
107
+ },
108
+ {
109
+ :title => "Duration",
110
+ :value => model.duration,
111
+ :short => true
112
+ },
113
+ {
114
+ :title => "Version",
115
+ :value => "Backup v#{Backup::VERSION}\nRuby: #{RUBY_DESCRIPTION}",
116
+ :short => false
117
+ },
118
+ log_field(status)
119
+ ].compact
120
+ }
121
+ end
122
+
123
+ def log_field(status)
124
+ send_log = send_log_on.include?(status)
125
+
126
+ return {
127
+ :title => "Detailed Backup Log",
128
+ :value => Logger.messages.map(&:formatted_lines).flatten.join("\n"),
129
+ :short => false,
130
+ } if send_log
131
+ end
132
+
133
+ def color(status)
134
+ case status
135
+ when :success then 'good'
136
+ when :failure then 'danger'
137
+ when :warning then 'warning'
138
+ end
139
+ end
140
+
141
+ def title(status)
142
+ case status
143
+ when :success then 'Backup Completed Successfully!'
144
+ when :failure then 'Backup Failed!'
145
+ when :warning then 'Backup Completed Successfully (with Warnings)!'
146
+ end
147
+ end
148
+
149
+ def uri
150
+ @uri ||= webhook_url
151
+ end
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,64 @@
1
+ # encoding: utf-8
2
+ require 'twitter'
3
+
4
+ module Backup
5
+ module Notifier
6
+ class Twitter < Base
7
+
8
+ ##
9
+ # Twitter consumer key credentials
10
+ attr_accessor :consumer_key, :consumer_secret
11
+
12
+ ##
13
+ # OAuth credentials
14
+ attr_accessor :oauth_token, :oauth_token_secret
15
+
16
+ def initialize(model, &block)
17
+ super
18
+ instance_eval(&block) if block_given?
19
+ end
20
+
21
+ private
22
+
23
+ ##
24
+ # Notify the user of the backup operation results.
25
+ #
26
+ # `status` indicates one of the following:
27
+ #
28
+ # `:success`
29
+ # : The backup completed successfully.
30
+ # : Notification will be sent if `on_success` is `true`.
31
+ #
32
+ # `:warning`
33
+ # : The backup completed successfully, but warnings were logged.
34
+ # : Notification will be sent if `on_warning` or `on_success` is `true`.
35
+ #
36
+ # `:failure`
37
+ # : The backup operation failed.
38
+ # : Notification will be sent if `on_warning` or `on_success` is `true`.
39
+ #
40
+ def notify!(status)
41
+ tag = case status
42
+ when :success then '[Backup::Success]'
43
+ when :warning then '[Backup::Warning]'
44
+ when :failure then '[Backup::Failure]'
45
+ end
46
+ message = "#{ tag } #{ model.label } (#{ model.trigger }) (@ #{ model.time })"
47
+ send_message(message)
48
+ end
49
+
50
+ # Twitter::Client will raise an error if unsuccessful.
51
+ def send_message(message)
52
+ client = ::Twitter::REST::Client.new do |config|
53
+ config.consumer_key = @consumer_key
54
+ config.consumer_secret = @consumer_secret
55
+ config.access_token = @oauth_token
56
+ config.access_token_secret = @oauth_token_secret
57
+ end
58
+
59
+ client.update(message)
60
+ end
61
+
62
+ end
63
+ end
64
+ end