riserva 0.1.4 → 0.1.5

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: 14f4d5ec8623ba7581225f4909122d8cb168043f8ea282957a4c9344ca1c33d6
4
- data.tar.gz: 918601c9444c915eb2e21a254b375b867df4709926966964c54f48e76765ddfe
3
+ metadata.gz: 5d12cf9a1a3acc7eabbcfced6e6a7ea4d465ec88a3d70dfdae420ee0805985a6
4
+ data.tar.gz: 7d8baa45525189353501c81ca3cc7624e0b5610dc260b57d75f9f7b9b8e52911
5
5
  SHA512:
6
- metadata.gz: d979e4adb68e95e13f4d3a33cfa173808e921341f457e7269f20b0fee9fb45db54d4755ecb3bd748b853bdd80201ab98d4888f79d4b9c528081b91eaa03431f4
7
- data.tar.gz: b31cd18f26460963331bfbef68fcba9626edbe386ff27fcbd62ed0ceeaf3e846f63b0c21e24699b2a6969f084fa1a97764d75fb4ffc3ffe679bbf63bbc14eef7
6
+ metadata.gz: 8cd2c8f78942f05fbf8edb187a2189c3eb8a65aaf5d62d4d83531976564597e2ad9e5af4c2f83b59b050ef50bca1f5f4a9213677a6532b4653ea8a1e4aebbc94
7
+ data.tar.gz: 67382d492412968b35dae6f3d7e5881f78130c7c9265bb952a9a44e761b327b750027f5825da740a37550570720ac0e07eb3db7e1382af753c8958e06b90c2a0
data/TODO.md CHANGED
@@ -1,5 +1,5 @@
1
1
  ## TODO
2
2
 
3
- * delete old files
4
3
  * restore from backup
4
+ * implement deduplication
5
5
  * create archives in `/tmp` folder if location is not specified
data/bin/riserva CHANGED
@@ -12,6 +12,8 @@ class RiservaExecutable
12
12
  case Choice[:perform]
13
13
  when 'backup' then
14
14
  Riserva::Commands::Backup.new.call
15
+ when 'clean' then
16
+ Riserva::Commands::Clean.new.call
15
17
  end
16
18
  end
17
19
  end
@@ -8,6 +8,8 @@ folders:
8
8
  storage:
9
9
  google_drive:
10
10
  secrets: 'config/google_drive_secrets.json'
11
+ days_to_keep: 30
11
12
 
12
13
  dropbox:
13
14
  secrets: 'config/dropbox_secrets.json'
15
+ days_to_keep: 30
@@ -4,8 +4,8 @@ Choice.options do
4
4
  option :perform do
5
5
  short '-p'
6
6
  long '--perform=OPERATION'
7
- desc 'Operation to perform, valid options: backup (default)'
8
- valid %w[backup]
7
+ desc 'Operation to perform, valid options: backup (default), clean'
8
+ valid %w[backup clean]
9
9
  default 'backup'
10
10
  end
11
11
 
@@ -12,6 +12,9 @@ module Riserva::Commands
12
12
  push_to_cloud
13
13
 
14
14
  success? ? broadcast(:ok) : broadcast(:failed)
15
+ rescue StandardError => exception
16
+ broadcast(:failed)
17
+ raise exception
15
18
  end
16
19
 
17
20
  private
@@ -0,0 +1,11 @@
1
+ module Riserva::Commands
2
+ class Clean < ApplicationCommand
3
+ def call
4
+ Riserva::Config.storages do |storage|
5
+ broadcast(:start_cleaning, storage)
6
+
7
+ storage.clean
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ module Riserva::Listeners
2
+ class Clean < ApplicationListener
3
+ def initialize
4
+ Riserva.logger.info('Starting cleanup...')
5
+ end
6
+
7
+ def ok
8
+ Riserva.logger.info('OK')
9
+ end
10
+
11
+ def failed
12
+ Riserva.logger.info('Failed')
13
+ end
14
+
15
+ def start_cleaning(storage)
16
+ Riserva.logger.info("Deleting old files on #{storage.title}...")
17
+ end
18
+ end
19
+ end
@@ -17,5 +17,12 @@ module Riserva::Storage
17
17
  def config_secrets
18
18
  Riserva::Config.read([:storage, title, :secrets].join('.'))
19
19
  end
20
+
21
+ def time_to_keep
22
+ value = Riserva::Config.read([:storage, title, :days_to_keep].join('.'))
23
+ return unless value
24
+
25
+ value.days
26
+ end
20
27
  end
21
28
  end
@@ -26,6 +26,16 @@ module Riserva::Storage
26
26
  data.content_hash == checksum
27
27
  end
28
28
 
29
+ def clean
30
+ return unless time_to_keep
31
+
32
+ session.list_folder('').entries.each do |file|
33
+ next unless file.client_modified < time_to_keep.ago
34
+
35
+ session.delete file.path_lower
36
+ end
37
+ end
38
+
29
39
  private
30
40
 
31
41
  def session
@@ -20,6 +20,14 @@ module Riserva::Storage
20
20
  file.md5_checksum == checksum
21
21
  end
22
22
 
23
+ def clean
24
+ return unless time_to_keep
25
+
26
+ session.files.each do |file|
27
+ file.delete if file.created_time < time_to_keep.ago
28
+ end
29
+ end
30
+
23
31
  private
24
32
 
25
33
  def session
@@ -1,3 +1,3 @@
1
1
  module Riserva
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
data/lib/riserva.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'riserva/version'
4
4
  require 'active_support/core_ext/string/inflections'
5
+ require 'active_support/time'
5
6
  require 'pathname'
6
7
 
7
8
  module Riserva
@@ -11,6 +12,7 @@ module Riserva
11
12
  module Commands
12
13
  autoload :ApplicationCommand, 'riserva/commands/application_command'
13
14
  autoload :Backup, 'riserva/commands/backup'
15
+ autoload :Clean, 'riserva/commands/clean'
14
16
  autoload :CreateArchive, 'riserva/commands/create_archive'
15
17
  autoload :UploadFile, 'riserva/commands/upload_file'
16
18
  end
@@ -18,6 +20,7 @@ module Riserva
18
20
  module Listeners
19
21
  autoload :ApplicationListener, 'riserva/listeners/application_listener'
20
22
  autoload :Backup, 'riserva/listeners/backup'
23
+ autoload :Clean, 'riserva/listeners/clean'
21
24
  autoload :CreateArchive, 'riserva/listeners/create_archive'
22
25
  autoload :UploadFile, 'riserva/listeners/upload_file'
23
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riserva
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Malinovskiy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-19 00:00:00.000000000 Z
11
+ date: 2019-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -218,11 +218,13 @@ files:
218
218
  - lib/riserva/command_line.rb
219
219
  - lib/riserva/commands/application_command.rb
220
220
  - lib/riserva/commands/backup.rb
221
+ - lib/riserva/commands/clean.rb
221
222
  - lib/riserva/commands/create_archive.rb
222
223
  - lib/riserva/commands/upload_file.rb
223
224
  - lib/riserva/config.rb
224
225
  - lib/riserva/listeners/application_listener.rb
225
226
  - lib/riserva/listeners/backup.rb
227
+ - lib/riserva/listeners/clean.rb
226
228
  - lib/riserva/listeners/create_archive.rb
227
229
  - lib/riserva/listeners/upload_file.rb
228
230
  - lib/riserva/log.rb