scalingo_backups_manager 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb4252e471c6c966e5673feab9807268aaafcb8a59d5d2aea1f0a6d49a994bd8
|
4
|
+
data.tar.gz: f9861da02ad73c2446c78c8cf5cda3259413c90abb7e3f46e5d5c93be6fd57a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08d683e68796cdb06ee814d6e01fc68e48dac4ff8d6d8f57ca1c3a065d3d48e141513ba0811f97d7f7cef10a5fa28ac5ab6bef5af4948c7533f917aa1f31aa20'
|
7
|
+
data.tar.gz: 49683566926006725fa2eab13418542ba7b60d6f74d6e1643b38ffe2ace9967bd7e24636a52dc820bb2a5a5affbfbb5a80d552c539c72100ae00428942204a24
|
data/Gemfile.lock
CHANGED
@@ -128,38 +128,41 @@ module ScalingoBackupsManager
|
|
128
128
|
def upload_to_ftp
|
129
129
|
invoke :download, [], application: options[:application], addon: options[:addon]
|
130
130
|
configuration = Configuration.new
|
131
|
+
opts = {
|
132
|
+
webhooks: configuration.config[:webhooks]
|
133
|
+
}
|
131
134
|
configuration.for_each_addons do |application, addon|
|
132
135
|
step = 1
|
133
|
-
|
136
|
+
sftp_config = addon.sftp_config
|
134
137
|
path = ("#{addon.config[:path]}" || "backups/#{addon.addon_provider[:id]}") + "/#{Time.now.strftime("%Y%m%d")}.tar.gz"
|
135
138
|
next unless File.exists?(path)
|
136
139
|
puts "** Upload backup for #{application.name} **"
|
137
140
|
|
138
|
-
sftp = ScalingoBackupsManager::SftpTools.new(
|
141
|
+
sftp = ScalingoBackupsManager::SftpTools.new(sftp_config[:auth])
|
139
142
|
|
140
143
|
folders = [
|
141
|
-
|
142
|
-
|
144
|
+
sftp_config.dig(:auth, :dir),
|
145
|
+
sftp_config.dig(:dir) || application.name,
|
143
146
|
addon.addon_provider[:id]
|
144
147
|
]
|
145
148
|
|
146
|
-
if
|
149
|
+
if sftp_config[:retention].blank?
|
147
150
|
remote_path = "/" + [folders].delete_if(&:blank?).join("/")
|
148
151
|
sftp.mkdir!(remote_path)
|
149
|
-
sftp.upload_file(path, remote_path)
|
152
|
+
sftp.upload_file(path, remote_path, options: opts)
|
150
153
|
next
|
151
154
|
end
|
152
155
|
|
153
|
-
|
156
|
+
sftp_config[:retention].each do |k, retention_config|
|
154
157
|
retention_folders = folders.dup
|
155
|
-
retention_folders <<
|
158
|
+
retention_folders << sftp_config.dig(:retention, k, :dir)
|
156
159
|
remote_path = "/" + retention_folders.delete_if(&:blank?).join("/")
|
157
160
|
puts "#{step} - Creating remote directory at #{remote_path}"
|
158
161
|
step += 1
|
159
162
|
sftp.mkdir!(remote_path)
|
160
163
|
case k
|
161
164
|
when "daily"
|
162
|
-
sftp.upload_file(path, remote_path)
|
165
|
+
sftp.upload_file(path, remote_path, options: opts)
|
163
166
|
files = sftp.list_files(remote_path)
|
164
167
|
puts "#{step} - Checking daily backups"
|
165
168
|
step += 1
|
@@ -173,7 +176,7 @@ module ScalingoBackupsManager
|
|
173
176
|
end
|
174
177
|
when "monthly"
|
175
178
|
next unless Date.today.day == 1
|
176
|
-
sftp.upload_file(path, remote_path)
|
179
|
+
sftp.upload_file(path, remote_path, options: opts)
|
177
180
|
puts "#{step} - Checking monthly backups"
|
178
181
|
step += 1
|
179
182
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
module ScalingoBackupsManager
|
3
|
+
|
4
|
+
class Notification
|
5
|
+
|
6
|
+
def self.send_slack_notification(hook_url, message)
|
7
|
+
HTTParty.post(
|
8
|
+
hook_url,
|
9
|
+
body: {
|
10
|
+
message: message
|
11
|
+
}.to_json,
|
12
|
+
headers: { 'Content-Type' => 'application/json' }
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.send_discord_notification(hook_url, message)
|
17
|
+
payload = {
|
18
|
+
user: 'Scalingo backups manager',
|
19
|
+
content: message
|
20
|
+
}.to_json
|
21
|
+
HTTParty.post(
|
22
|
+
hook_url,
|
23
|
+
body: payload,
|
24
|
+
headers: { 'Content-Type': 'application/json' }
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'scalingo_backups_manager/notification'
|
1
2
|
require 'net/sftp'
|
2
3
|
|
3
4
|
module ScalingoBackupsManager
|
@@ -45,10 +46,19 @@ module ScalingoBackupsManager
|
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
|
-
def upload_file(filepath, remote_dir)
|
49
|
+
def upload_file(filepath, remote_dir, options: {})
|
49
50
|
filename = filepath.split('/').last
|
50
51
|
start do |sftp|
|
51
|
-
|
52
|
+
begin
|
53
|
+
sftp.upload!(filepath, "#{remote_dir}/#{filename}")
|
54
|
+
rescue
|
55
|
+
if options.dig(:webhooks, :slack_webhook_url)
|
56
|
+
ScalingoBackupsManager::Notification.send_slack_notification(options.dig(:webhooks, :slack_webhook_url), "An error has occured while uploading backup, see the logs for more information")
|
57
|
+
end
|
58
|
+
if options.dig(:webhooks, :discord_webhook_url)
|
59
|
+
ScalingoBackupsManager::Notification.send_discord_notification(options.dig(:webhooks, :discord_webhook_url), "An error has occured while uploading backup, see the logs for more information")
|
60
|
+
end
|
61
|
+
end
|
52
62
|
end
|
53
63
|
end
|
54
64
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scalingo_backups_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Clercin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- lib/scalingo_backups_manager/backup.rb
|
93
93
|
- lib/scalingo_backups_manager/cli.rb
|
94
94
|
- lib/scalingo_backups_manager/configuration.rb
|
95
|
+
- lib/scalingo_backups_manager/notification.rb
|
95
96
|
- lib/scalingo_backups_manager/restore/mongodb.rb
|
96
97
|
- lib/scalingo_backups_manager/restore/mysql.rb
|
97
98
|
- lib/scalingo_backups_manager/restore/postgres.rb
|