scalingo_backups_manager 0.5.0 → 0.6.4
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/scalingo_backups_manager/cli.rb +14 -10
- data/lib/scalingo_backups_manager/notification.rb +30 -0
- data/lib/scalingo_backups_manager/restore/mysql.rb +1 -1
- data/lib/scalingo_backups_manager/restore/postgres.rb +18 -8
- data/lib/scalingo_backups_manager/sftp_tools.rb +12 -2
- data/lib/scalingo_backups_manager/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 056e83371931b63ddaca8c2b498627937c162fe11bab3f10c2455823c1029bee
|
4
|
+
data.tar.gz: 74109af520ec387a17c413590e7f92b6b670cb8d71caa467c57eb52c4343dc14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 937f12a1baac04e58dbd1572e8176774d874a3ef67743cdd8da6c51054dfe78179f9bce64cf6a0af8e419803bfae88e9fb08df4641825017c10d5ba698351d5d
|
7
|
+
data.tar.gz: 164beb5eb694f5ad2f802d7eaf28cc66e6e04a190a9f08c0df75cbc7800409b5072706c3cd9a21e05051c3ca534bcd019b644d3a7679f981adb4a3ddd059f21d
|
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,13 +176,14 @@ 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
|
180
183
|
end
|
181
184
|
|
182
185
|
end
|
186
|
+
FileUtils.rm_r 'backups/'
|
183
187
|
end
|
184
188
|
|
185
189
|
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
|
@@ -63,7 +63,7 @@ module ScalingoBackupsManager
|
|
63
63
|
puts "*** Restoring backup to mysql database ***"
|
64
64
|
puts "Command: #{restore_cmd}"
|
65
65
|
system(restore_cmd)
|
66
|
-
|
66
|
+
FileUtils.rm_r destination_path unless opts[:skip_rm]
|
67
67
|
end
|
68
68
|
|
69
69
|
end
|
@@ -33,22 +33,32 @@ module ScalingoBackupsManager
|
|
33
33
|
password: rails_db_config["password"],
|
34
34
|
user: rails_db_config["user"],
|
35
35
|
}
|
36
|
+
restore_cmd = ""
|
37
|
+
if config[:password].present?
|
38
|
+
restore_cmd = "PGPASSWORD=#{config[:password]} "
|
39
|
+
end
|
40
|
+
restore_cmd << "/usr/bin/env"
|
41
|
+
restore_cmd << " pg_restore"
|
36
42
|
|
37
|
-
|
43
|
+
file_path = Dir["#{destination_path}*.pgsql"]
|
44
|
+
if file_path.empty?
|
45
|
+
puts "*** No SQL file found in tar ***"
|
46
|
+
return
|
47
|
+
end
|
48
|
+
restore_cmd << " #{file_path.first}"
|
38
49
|
|
50
|
+
if config[:host].present?
|
51
|
+
restore_cmd << " -h #{opts[:host] || config[:host] || 'localhost'}"
|
52
|
+
end
|
39
53
|
if config[:user].present?
|
40
|
-
restore_cmd << "
|
41
|
-
if config[:password].present?
|
42
|
-
restore_cmd << " --password"
|
43
|
-
restore_cmd << " #{config[:password]}"
|
44
|
-
end
|
54
|
+
restore_cmd << " -U #{config[:user]}"
|
45
55
|
end
|
46
56
|
|
47
|
-
if config[:port].present?
|
57
|
+
if opts[:port].present? || config[:port].present?
|
48
58
|
restore_cmd << " -p #{opts[:port] || config[:port] || 5432}"
|
49
59
|
end
|
50
60
|
|
51
|
-
restore_cmd << "
|
61
|
+
restore_cmd << " -d #{config[:database]} --no-owner"
|
52
62
|
|
53
63
|
puts "*** Restoring backup to Postgres database ***"
|
54
64
|
system(restore_cmd)
|
@@ -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.4
|
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-15 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
|