scalingo_backups_manager 0.4.0 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c13c0008cbcd861729fbbc5cb43a3b53ed63db136a2b24393b077c2fbb6b50e
4
- data.tar.gz: d93398d512fe1d0e9fdf964e431fc5c570c3201c5475e51174d3e7f297ef02c8
3
+ metadata.gz: 0ddc26bcd894cfe092ba3fbbcfa954c68661bf64639a88f224e99d8848de16e2
4
+ data.tar.gz: 8742e9f0f1b4d3d2655a96f218eda3a753f13f4873440bb1e1e3c84ab7ba573c
5
5
  SHA512:
6
- metadata.gz: 26cc222b56f4199eb7a1bd06f1c9e787d53a5f3a2a979836f991fc368369252c53cfeb7cbbd457882e4bce32aa07f09dcf8813a5d73a9007de4e958bfefe94fd
7
- data.tar.gz: 0577310f2c5cceef264cd75789572577b7c218ff536cdb878a2ab40e6190f9e5d6b4e429587e596e7f6c71b7f1b787f431dbe4c0d7eee6a04c94a795fcd72a3f
6
+ metadata.gz: 75f37abc3dc0c5fd0eb259d55d857cf79bdd402f2d653dae315822830a06f4dce895cdb686f74e845f806c3847a0606afa088ca0d279408002129c500186d276
7
+ data.tar.gz: 58f6b07bbf870eff376e88c284e8dafa50eb5a0d95d28e685e2127de7544550ea2d81179214d0f031ad9002396237995db78afaa40162ffdace39ae42c3264e0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- scalingo_backups_manager (0.3.0)
4
+ scalingo_backups_manager (0.4.0)
5
5
  httparty (~> 0.18)
6
6
  net-sftp (~> 3.0.0)
7
7
  scalingo (~> 3.0)
@@ -129,9 +129,11 @@ module ScalingoBackupsManager
129
129
  invoke :download, [], application: options[:application], addon: options[:addon]
130
130
  configuration = Configuration.new
131
131
  configuration.for_each_addons do |application, addon|
132
+ step = 1
132
133
  config = addon.sftp_config
133
134
  path = ("#{addon.config[:path]}" || "backups/#{addon.addon_provider[:id]}") + "/#{Time.now.strftime("%Y%m%d")}.tar.gz"
134
135
  next unless File.exists?(path)
136
+ puts "** Upload backup for #{application.name} **"
135
137
 
136
138
  sftp = ScalingoBackupsManager::SftpTools.new(config[:auth])
137
139
 
@@ -148,16 +150,32 @@ module ScalingoBackupsManager
148
150
  next
149
151
  end
150
152
 
151
- config[:retention].each do |k, v|
152
- folders << config.dig(:retention, k, :dir)
153
- remote_path = "/" + [folders].delete_if(&:blank?).join("/")
153
+ config[:retention].each do |k, retention_config|
154
+ retention_folders = folders.dup
155
+ retention_folders << config.dig(:retention, k, :dir)
156
+ remote_path = "/" + retention_folders.delete_if(&:blank?).join("/")
157
+ puts "#{step} - Creating remote directory at #{remote_path}"
158
+ step += 1
154
159
  sftp.mkdir!(remote_path)
155
160
  case k
156
161
  when "daily"
157
162
  sftp.upload_file(path, remote_path)
163
+ files = sftp.list_files(remote_path)
164
+ puts "#{step} - Checking daily backups"
165
+ step += 1
166
+ if files.size > retention_config[:ttl]
167
+ files_to_remove = files.sort_by(&:name).shift(files.size - retention_config[:ttl])
168
+ puts "#{step} - Removing #{files_to_remove.size} backups because of ttl configuration"
169
+ files_to_remove.each do |file|
170
+ puts "Removing file #{remote_path + "/" + file.name}"
171
+ sftp.remove!(remote_path + "/" + file.name)
172
+ end
173
+ end
158
174
  when "monthly"
159
175
  next unless Date.today.day == 1
160
176
  sftp.upload_file(path, remote_path)
177
+ puts "#{step} - Checking monthly backups"
178
+ step += 1
161
179
  end
162
180
  end
163
181
 
@@ -14,6 +14,22 @@ module ScalingoBackupsManager
14
14
  end
15
15
  end
16
16
 
17
+ def list_files(path)
18
+ files = []
19
+ start do |sftp|
20
+ sftp.dir.glob("#{path}", "*.tar.gz").each do |file|
21
+ files << file
22
+ end
23
+ end
24
+ files
25
+ end
26
+
27
+ def remove!(path)
28
+ start do |sftp|
29
+ sftp.remove!(path)
30
+ end
31
+ end
32
+
17
33
  def mkdir!(path)
18
34
  start do |sftp|
19
35
  folder_tree = []
@@ -1,3 +1,3 @@
1
1
  module ScalingoBackupsManager
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scalingo_backups_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Clercin