rustic 0.3.0 → 0.3.3

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: 3cffcd950bd1cafc45ac925deed3c4d5ffeed28feecd547f83fbe270b990d8c6
4
- data.tar.gz: aa028fac39c981b0b4a6667dd1d84da19157ff2666a44abe06143c7b8f0473c1
3
+ metadata.gz: 749ff9e10d60fb610892f8c1984fcc5badf605eb5ef7dbe954d71f70aaf6e335
4
+ data.tar.gz: 0c499c7d0fd8536f464a8c9410099c9d0d9e587895f53fd50e8aff406dc20344
5
5
  SHA512:
6
- metadata.gz: 4877cbfd5481d617d15cd4a58332516e533f9af4168a9e05e1099edbf0b3572fb087bd01b985958ca77d8f96053bea3c5e660ce545af36d7a26ab2c718f03faa
7
- data.tar.gz: ad3f12c6b8cba8de97544d91481569ccc7dd0152dcdcb53a73f27f0b2b56ffeb70cca5747fc5966d0de093ce4c05e621b95842fc3fae68e60d6a7c6c7fe2c45d
6
+ metadata.gz: 1d806e658a7aedb406195cf6eeb87579c891a2e4c71db159685a5bcfe8ad94375e9ecdb9dcf9d56c06ed1e2164376f565793e55854b1d222fdf0fd2ada5bdcae
7
+ data.tar.gz: 1f592a8a4e737873ede871bc1877bf0da4f5959a8e384835f7412950456d6db38fb55ce691b71cd75a2f0a22144cc80730a873bbf77026db4b12bb1a990fef2a
@@ -44,7 +44,6 @@ jobs:
44
44
 
45
45
  - uses: ruby/setup-ruby@v1
46
46
  with:
47
- ruby-version: 3.0
48
47
  bundler-cache: true
49
48
 
50
49
  - name: Build gem
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rustic (0.3.0)
4
+ rustic (0.3.3)
5
5
  async-process (~> 1.3)
6
6
  ptools (~> 1.4)
7
7
  zeitwerk (~> 2.5)
@@ -10,11 +10,11 @@ GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  ast (2.4.2)
13
- async (1.30.1)
13
+ async (1.30.3)
14
14
  console (~> 1.10)
15
15
  nio4r (~> 2.3)
16
16
  timers (~> 4.1)
17
- async-io (1.32.2)
17
+ async-io (1.33.0)
18
18
  async
19
19
  async-process (1.3.1)
20
20
  async
@@ -25,7 +25,7 @@ GEM
25
25
  rspec-memory (~> 1.0)
26
26
  backport (1.2.0)
27
27
  benchmark (0.2.0)
28
- console (1.14.0)
28
+ console (1.15.3)
29
29
  fiber-local
30
30
  diff-lcs (1.4.4)
31
31
  docile (1.4.0)
@@ -110,7 +110,7 @@ GEM
110
110
  timers (4.3.3)
111
111
  unicode-display_width (2.1.0)
112
112
  yard (0.9.26)
113
- zeitwerk (2.5.1)
113
+ zeitwerk (2.6.0)
114
114
 
115
115
  PLATFORMS
116
116
  x86_64-linux
@@ -3,7 +3,7 @@
3
3
 
4
4
  require "rustic"
5
5
 
6
- Rustic.define do
6
+ Rustic.define do # rubocop:disable Metrics/BlockLength
7
7
  repository "tmp/repository"
8
8
 
9
9
  password "password"
@@ -27,6 +27,29 @@ Rustic.define do
27
27
  exclude "lib/rustic"
28
28
  end
29
29
 
30
+ check do
31
+ before do
32
+ logger.info(self, "BEFORE CHECK")
33
+ end
34
+
35
+ after do
36
+ logger.info(self, "AFTER CHECK")
37
+ end
38
+ end
39
+
40
+ forget do
41
+ before do
42
+ logger.info(self, "BEFORE FORGET")
43
+ end
44
+
45
+ after do
46
+ logger.info(self, "AFTER FORGET")
47
+ end
48
+
49
+ prune!
50
+ keep(last: 2, weekly: 2, monthly: 2)
51
+ end
52
+
30
53
  after do
31
54
  logger.info(self, "AFTER")
32
55
  end
@@ -7,9 +7,8 @@ class Rustic::Application
7
7
  @config = config
8
8
  end
9
9
 
10
- def run(argv)
10
+ def run(*argv)
11
11
  command = argv.first || "backup"
12
- command, env = Rustic::CommandBuilder.new(command, @config).build
13
- Rustic::Wrapper.new(command, env).run
12
+ Rustic::Evaluator.new(command, @config).evaluate
14
13
  end
15
14
  end
@@ -18,14 +18,14 @@ class Rustic::CommandBuilder
18
18
  add_repository_path!
19
19
  add_password!
20
20
 
21
- add_command!
21
+ config = add_command!
22
22
 
23
- [[@config.restic_path, *@args], @env_variables] # TODO: properly handle spaces in paths
23
+ [[@config.restic_path, *@args], @env_variables, config] # TODO: properly handle spaces in paths
24
24
  end
25
25
 
26
26
  private
27
27
 
28
- def add_repository_path! = @args += ["-r", @config.repository]
28
+ def add_repository_path! = @args.concat(["-r", @config.repository])
29
29
 
30
30
  def add_password!
31
31
  return @env_variables.merge!("RESTIC_PASSWORD" => @config.password) if @config.password
@@ -35,8 +35,9 @@ class Rustic::CommandBuilder
35
35
  end
36
36
 
37
37
  def add_command!
38
- command_class = Rustic::CommandBuilders.const_get(@command.capitalize)
39
- @args.concat(command_class.new(@config).build)
38
+ command_builder = Rustic::CommandBuilders.const_get(@command.capitalize).new(@config)
39
+ @args.concat(command_builder.build)
40
+ command_builder.config
40
41
  rescue NameError
41
42
  raise UnknownCommandError, "Unknown command #{@command}"
42
43
  end
@@ -1,24 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Rustic::CommandBuilders::Backup
4
+ attr_reader :config
5
+
4
6
  def initialize(config)
5
- @config = config
7
+ @config = config.backup_config
6
8
  end
7
9
 
8
10
  def build
9
- config = @config.backup_config
10
- raise Rustic::CommandBuilder::MissingConfigError, "Command `backup` misses it's configuration" if config.nil?
11
- raise Rustic::CommandBuilder::MalformedConfigError, "Backup paths cannot be empty" if config.paths.empty?
11
+ raise Rustic::CommandBuilder::MissingConfigError, "Command `backup` misses it's configuration" if @config.nil?
12
+ raise Rustic::CommandBuilder::MalformedConfigError, "Backup paths cannot be empty" if @config.paths.empty?
12
13
 
13
14
  [
15
+ "--compression",
16
+ @config.compression_mode,
14
17
  "backup",
15
- config.one_fs ? "-x" : nil,
16
- *config.paths,
18
+ @config.one_fs ? "-x" : nil,
19
+ *@config.paths,
17
20
  *excludes
18
21
  ].compact
19
22
  end
20
23
 
21
24
  private
22
25
 
23
- def excludes = ["--exclude"].product(@config.backup_config.excluded_paths).flatten
26
+ def excludes = ["--exclude"].product(@config.excluded_paths).flatten
24
27
  end
@@ -1,24 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Rustic::CommandBuilders::Check
4
+ attr_reader :config
5
+
4
6
  def initialize(config)
5
- @config = config
7
+ @config = config.check_config
6
8
  end
7
9
 
8
10
  def build
9
- config = @config.check_config
10
11
  [
11
12
  "check",
12
- config&.check_unused ? "--check-unused" : nil,
13
- read_data_subset(config),
14
- config&.with_cache ? "--with-cache" : nil
13
+ @config&.check_unused ? "--check-unused" : nil,
14
+ read_data_subset,
15
+ @config&.with_cache ? "--with-cache" : nil
15
16
  ].compact
16
17
  end
17
18
 
18
- def read_data_subset(config)
19
- return nil if config.nil? || config.read_data_subset.nil?
20
- return "--read-data" if config.read_data_subset == 100
19
+ private
20
+
21
+ def read_data_subset
22
+ return nil if @config.nil? || @config.read_data_subset.nil?
23
+ return "--read-data" if @config.read_data_subset == 100
21
24
 
22
- "--read-data-subset=#{config.read_data_subset}%"
25
+ "--read-data-subset=#{@config.read_data_subset}%"
23
26
  end
24
27
  end
@@ -1,20 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Rustic::CommandBuilders::Forget
4
+ attr_reader :config
5
+
4
6
  def initialize(config)
5
- @config = config
7
+ @config = config.forget_config
6
8
  end
7
9
 
8
10
  def build
9
- config = @config.forget_config
10
- raise Rustic::CommandBuilder::MissingConfigError, "Command `forget` misses it's configuration" if config.nil?
11
+ raise Rustic::CommandBuilder::MissingConfigError, "Command `forget` misses it's configuration" if @config.nil?
11
12
 
12
13
  [
13
14
  "forget",
14
- config.keep_last ? "--keep-last=#{config.keep_last}" : nil,
15
- config.keep_weekly ? "--keep-weekly=#{config.keep_weekly}" : nil,
16
- config.keep_monthly ? "--keep-monthly=#{config.keep_monthly}" : nil,
17
- config.prune ? "--prune" : nil
15
+ @config.keep_last ? "--keep-last=#{@config.keep_last}" : nil,
16
+ @config.keep_weekly ? "--keep-weekly=#{@config.keep_weekly}" : nil,
17
+ @config.keep_monthly ? "--keep-monthly=#{@config.keep_monthly}" : nil,
18
+ @config.prune ? "--prune" : nil
18
19
  ].compact
19
20
  end
20
21
  end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Rustic::CommandBuilders::Prune
4
- def initialize(config)
5
- @config = config
6
- end
4
+ attr_reader :config
5
+
6
+ def initialize(_config) = nil
7
7
 
8
8
  def build
9
9
  ["prune"]
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Rustic::CommandBuilders::Snapshots
4
- def initialize(config)
5
- @config = config
6
- end
4
+ attr_reader :config
5
+
6
+ def initialize(_config) = nil
7
7
 
8
8
  def build
9
9
  ["snapshots"]
@@ -3,12 +3,13 @@
3
3
  class Rustic::Configs::Backup
4
4
  include Rustic::HooksExt
5
5
 
6
- attr_reader :paths, :excluded_paths, :one_fs
6
+ attr_reader :paths, :excluded_paths, :one_fs, :compression_mode
7
7
 
8
8
  def initialize
9
9
  @paths = []
10
10
  @excluded_paths = []
11
11
  @one_fs = false
12
+ @compression_mode = "auto"
12
13
  end
13
14
 
14
15
  def backup(*paths)
@@ -24,4 +25,8 @@ class Rustic::Configs::Backup
24
25
  end
25
26
 
26
27
  def one_fs! = @one_fs = true
28
+
29
+ def compression(value)
30
+ @compression_mode = value
31
+ end
27
32
  end
@@ -3,11 +3,19 @@
3
3
  class Rustic::Evaluator
4
4
  include Console
5
5
 
6
- def initialize(config) = @config = config
6
+ def initialize(command, config)
7
+ @command = command
8
+ @config = config
9
+ end
7
10
 
8
11
  def evaluate
9
12
  with_hooks(@config) do
10
- backup! unless @config.backup_config.nil?
13
+ builder = Rustic::CommandBuilder.new(@command, @config)
14
+ command, env, config = builder.build
15
+
16
+ with_hooks(config) do
17
+ Rustic::Wrapper.new(command, env).run
18
+ end
11
19
  end
12
20
  rescue StandardError => e
13
21
  on_error(e)
@@ -15,13 +23,5 @@ class Rustic::Evaluator
15
23
  end
16
24
 
17
25
  def on_error(error) = @config.on_error&.call(error)
18
-
19
- def backup!
20
- with_hooks(@config.backup_config) do
21
- command, env = Rustic::CommandBuilder.new("backup", @config).build
22
- Rustic::Wrapper.new(command, env).run
23
- end
24
- end
25
-
26
26
  def with_hooks(config, args = nil, &block) = Rustic::Hooks.new(config).with_hooks(args, &block)
27
27
  end
data/lib/rustic/hooks.rb CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  class Rustic::Hooks
4
4
  def initialize(config)
5
- @before = config.before
6
- @after = config.after
5
+ @before = config&.before
6
+ @after = config&.after
7
7
  end
8
8
 
9
9
  def with_hooks(arg = nil)
@@ -11,6 +11,6 @@ class Rustic::Hooks
11
11
 
12
12
  @before&.call(arg)
13
13
  yield
14
- @after&.call(arg) # TODO: do not call the after block if an exception was raised
14
+ @after&.call(arg)
15
15
  end
16
16
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rustic
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.3"
5
5
  end
data/lib/rustic.rb CHANGED
@@ -20,7 +20,7 @@ module Rustic
20
20
  config.instance_eval(&block)
21
21
  validate!(config)
22
22
  Rustic::Application.new(config).tap do |app|
23
- app.run(ARGV) if run
23
+ app.run(*ARGV) if run
24
24
  end
25
25
  end
26
26
  end
data/rustic.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = "DSL for the restic backup tool."
13
13
  spec.homepage = "https://github.com/zhulik/rustic"
14
14
  spec.license = "MIT"
15
- spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
15
+ spec.required_ruby_version = [">= 3.0.0", "< 3.1"]
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
18
  # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rustic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gleb Sinyavskiy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-20 00:00:00.000000000 Z
11
+ date: 2022-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-process
@@ -73,6 +73,7 @@ files:
73
73
  - Rakefile
74
74
  - bin/console
75
75
  - bin/setup
76
+ - examples/rustic.rb
76
77
  - lib/rustic.rb
77
78
  - lib/rustic/application.rb
78
79
  - lib/rustic/command_builder.rb
@@ -92,7 +93,6 @@ files:
92
93
  - lib/rustic/version.rb
93
94
  - lib/rustic/wrapper.rb
94
95
  - rustic.gemspec
95
- - rustic.rb
96
96
  - rustic_script.rb
97
97
  homepage: https://github.com/zhulik/rustic
98
98
  licenses:
@@ -108,6 +108,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: 3.0.0
111
+ - - "<"
112
+ - !ruby/object:Gem::Version
113
+ version: '3.1'
111
114
  required_rubygems_version: !ruby/object:Gem::Requirement
112
115
  requirements:
113
116
  - - ">="