webtranslateit-safe 0.4.2 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +22 -9
  3. data/bin/webtranslateit-safe +13 -13
  4. data/lib/webtranslateit/safe/archive.rb +9 -4
  5. data/lib/webtranslateit/safe/backup.rb +9 -2
  6. data/lib/webtranslateit/safe/cloudfiles.rb +21 -15
  7. data/lib/webtranslateit/safe/config/builder.rb +17 -8
  8. data/lib/webtranslateit/safe/config/node.rb +17 -10
  9. data/lib/webtranslateit/safe/ftp.rb +25 -25
  10. data/lib/webtranslateit/safe/gpg.rb +8 -2
  11. data/lib/webtranslateit/safe/gzip.rb +5 -1
  12. data/lib/webtranslateit/safe/local.rb +15 -11
  13. data/lib/webtranslateit/safe/mongodump.rb +12 -6
  14. data/lib/webtranslateit/safe/mysqldump.rb +9 -5
  15. data/lib/webtranslateit/safe/pgdump.rb +9 -9
  16. data/lib/webtranslateit/safe/pipe.rb +6 -0
  17. data/lib/webtranslateit/safe/s3.rb +28 -22
  18. data/lib/webtranslateit/safe/sftp.rb +42 -25
  19. data/lib/webtranslateit/safe/sink.rb +7 -2
  20. data/lib/webtranslateit/safe/source.rb +13 -9
  21. data/lib/webtranslateit/safe/stream.rb +14 -6
  22. data/lib/webtranslateit/safe/svndump.rb +5 -1
  23. data/lib/webtranslateit/safe/tmp_file.rb +16 -11
  24. data/lib/webtranslateit/safe.rb +12 -13
  25. metadata +3 -36
  26. data/.autotest +0 -3
  27. data/.document +0 -5
  28. data/.github/dependabot.yml +0 -26
  29. data/.github/release-drafter.yml +0 -36
  30. data/.github/workflows/ci.yml +0 -51
  31. data/.github/workflows/release-drafter.yml +0 -29
  32. data/.gitignore +0 -18
  33. data/.rspec +0 -3
  34. data/.rubocop.yml +0 -8
  35. data/.rubocop_todo.yml +0 -965
  36. data/Gemfile +0 -11
  37. data/Gemfile.lock +0 -89
  38. data/LICENSE.txt +0 -22
  39. data/Rakefile +0 -8
  40. data/TODO +0 -31
  41. data/lib/extensions/mktmpdir.rb +0 -45
  42. data/lib/webtranslateit/safe/version.rb +0 -5
  43. data/spec/integration/archive_integration_spec.rb +0 -89
  44. data/spec/integration/cleanup_spec.rb +0 -62
  45. data/spec/spec_helper.rb +0 -7
  46. data/spec/webtranslateit/safe/archive_spec.rb +0 -67
  47. data/spec/webtranslateit/safe/cloudfiles_spec.rb +0 -175
  48. data/spec/webtranslateit/safe/config_spec.rb +0 -307
  49. data/spec/webtranslateit/safe/gpg_spec.rb +0 -148
  50. data/spec/webtranslateit/safe/gzip_spec.rb +0 -64
  51. data/spec/webtranslateit/safe/local_spec.rb +0 -109
  52. data/spec/webtranslateit/safe/mongodump_spec.rb +0 -54
  53. data/spec/webtranslateit/safe/mysqldump_spec.rb +0 -83
  54. data/spec/webtranslateit/safe/pgdump_spec.rb +0 -45
  55. data/spec/webtranslateit/safe/s3_spec.rb +0 -168
  56. data/spec/webtranslateit/safe/svndump_spec.rb +0 -39
  57. data/templates/script.rb +0 -183
  58. data/webtranslateit-safe.gemspec +0 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed0d297f5252af872b39f52b6d5a4263c6b56f4ee38b1772258a92d4df3fa2ef
4
- data.tar.gz: 4557ea851c8240d088595989ffa43c8d74c1084ff6cac83a49bc33a6e5f1f0ee
3
+ metadata.gz: 1d56d9c1814184138e0ac2f4c7c1c62d977db103d6aecebd441ae6c861a4f85e
4
+ data.tar.gz: 818c66a0f9307e18add81ef25fd29822a77ae1980cbbbdeafbcfdd5684ae65b7
5
5
  SHA512:
6
- metadata.gz: 703d06c850c8eecf317a2c58c27ad2e44ff3c784b203272e3a94bd7af70ccdfc038dbb6826e4cbc7b15e5cfd008b465928991f0f93d07bbccff4666acafbf1b4
7
- data.tar.gz: 579fd82043f01589793cd8765fce1402931075ef1031ee070d2243726ac596e1127278b15646ec0615efa918721793dbf431a321a1fe3170ba0143129636ec84
6
+ metadata.gz: 10a974ca460fdfd6ccf52f19a55466b70f74ea2f7e929084935453cf04bc67f0c9618c44f7b9d70bca2fd23f7af84ee54e77d2161a0a7219df3800c73e466e77
7
+ data.tar.gz: 6975cc66f99b3220b69556a20e5646c51ace16c7544380a1459f61cd9ce2781b8f5923dd942088676390cb50701daed4b964898562bf001edb4b9da590874ebd
data/CHANGELOG CHANGED
@@ -1,31 +1,44 @@
1
- 0.4.2
1
+ ## 0.4.4 - 2023-06-30
2
2
 
3
- Bug fix on executable
3
+ * Remove `default_executable` line and simplify executables definition.
4
+ * Autocorrect rubocop offences.
5
+ * Convert rspec syntax from `should` to `expect`.
6
+ * Remove unused extension `Dir.mktmpdir`.
7
+ * Upload retry logic for SFTP.
4
8
 
5
- 0.4.1
9
+ ## 0.4.3 - 2023-06-29
10
+
11
+ * Bug fix on builder.
12
+ * Move version number to gemspec file.
13
+
14
+ ## 0.4.2 - 2023-05-22
15
+
16
+ * Bug fix on executable
17
+
18
+ ## 0.4.1 - 2023-05-20
6
19
 
7
20
  * Add ruby 3.2 compantibility
8
21
  * Modernize gem
9
22
  * Rename astrails-safe to webtranslateit-safe
10
23
 
11
- 0.3.1
24
+ ## 0.3.1
12
25
 
13
26
  * plain ftp support from seroy
14
27
  * mongodump support from Matt Berther
15
28
 
16
- 0.3.0
29
+ ## 0.3.0
17
30
 
18
31
  * switch to bundler
19
32
  * fixed the rspec
20
33
 
21
- 0.2.8
34
+ ## 0.2.8
22
35
 
23
36
  * ruby 1.9.2 compatibility (tests mostly)
24
37
  * code review, and tons of small fixes
25
38
  * check file size before attempting to upload to cloudfiles
26
39
  * testing framework changed from micronaut to rspec
27
40
 
28
- 0.2.7
41
+ ## 0.2.7
29
42
 
30
43
  * default options for gpg now include '--no-use-agent'
31
44
  * support for 'command' option for gpg
@@ -33,13 +46,13 @@ Bug fix on executable
33
46
  * add 'lib' to $:
34
47
  * [EXPERIMENTAL] Rackspace Cloud Files support
35
48
 
36
- 0.2.6
49
+ ## 0.2.6
37
50
 
38
51
  * fix typo in the template config file. (change option to options in pgdump)
39
52
  * add example 'options' for tar in the template config file.
40
53
  * do not try to upload more then 5G of data to S3. print error instead
41
54
 
42
- 0.2.5
55
+ ## 0.2.5
43
56
 
44
57
  * Safety mesure: Disable overwrite of existing configuration keys except for multi-value keys
45
58
  supported multi-value keys: skip_tables, exclude, files
@@ -12,16 +12,16 @@ def die(msg)
12
12
  end
13
13
 
14
14
  def usage
15
- puts <<-END
16
- Usage: webtranslateit-safe [OPTIONS] CONFIG_FILE
17
- Options:
18
- -h, --help This help screen
19
- -v, --verbose be verbose, duh!
20
- -n, --dry-run just pretend, don't do anything.
21
- -L, --local skip S3 and Cloud Files
22
-
23
- Note: config file will be created from template if missing
24
- END
15
+ puts <<~END
16
+ Usage: webtranslateit-safe [OPTIONS] CONFIG_FILE
17
+ Options:
18
+ -h, --help This help screen
19
+ -v, --verbose be verbose, duh!
20
+ -n, --dry-run just pretend, don't do anything.
21
+ -L, --local skip S3 and Cloud Files
22
+
23
+ Note: config file will be created from template if missing
24
+ END
25
25
  exit 1
26
26
  end
27
27
 
@@ -30,7 +30,7 @@ OPTS = [
30
30
  '-v', '--verbose', '--not-verbose',
31
31
  '-n', '--dry-run', '--not-dry-run',
32
32
  '-L', '--local', '--not-local'
33
- ]
33
+ ].freeze
34
34
  def main
35
35
  opts = ARGV & OPTS
36
36
  args = ARGV - OPTS
@@ -40,7 +40,7 @@ def main
40
40
 
41
41
  config_file = File.expand_path(args.first)
42
42
 
43
- is_dry = (opts.delete('-n') || opts.delete('--dry-run')) && ! opts.delete('--not-dry-run')
43
+ is_dry = (opts.delete('-n') || opts.delete('--dry-run')) && !opts.delete('--not-dry-run')
44
44
  is_verbose = (opts.delete('-v') || opts.delete('--verbose')) && !opts.delete('--not-verbose')
45
45
  is_local_only = (opts.delete('-L') || opts.delete('--local')) && !opts.delete('--not-local')
46
46
 
@@ -61,4 +61,4 @@ def main
61
61
  process config
62
62
  end
63
63
 
64
- main
64
+ main
@@ -1,24 +1,29 @@
1
1
  module WebTranslateIt
2
+
2
3
  module Safe
4
+
3
5
  class Archive < Source
4
6
 
5
7
  def command
6
8
  "tar -cf - #{config[:options]} #{tar_exclude_files} #{tar_files}"
7
9
  end
8
10
 
9
- def extension; '.tar'; end
11
+ def extension = '.tar'
10
12
 
11
13
  protected
12
14
 
13
15
  def tar_exclude_files
14
- [*config[:exclude]].compact.map{|x| "--exclude=#{x}"}.join(' ')
16
+ [*config[:exclude]].compact.map { |x| "--exclude=#{x}" }.join(' ')
15
17
  end
16
18
 
17
19
  def tar_files
18
- raise RuntimeError, 'missing files for tar' unless config[:files]
19
- [*config[:files]].map{|s| s.strip}.join(' ')
20
+ raise 'missing files for tar' unless config[:files]
21
+
22
+ [*config[:files]].map(&:strip).join(' ')
20
23
  end
21
24
 
22
25
  end
26
+
23
27
  end
28
+
24
29
  end
@@ -1,10 +1,14 @@
1
1
  module WebTranslateIt
2
+
2
3
  module Safe
4
+
3
5
  class Backup
6
+
4
7
  attr_accessor :id, :kind, :filename, :extension, :command, :compressed, :timestamp, :path
8
+
5
9
  def initialize(opts = {})
6
10
  opts.each do |k, v|
7
- self.send("#{k}=", v)
11
+ send("#{k}=", v)
8
12
  end
9
13
  end
10
14
 
@@ -15,6 +19,9 @@ module WebTranslateIt
15
19
  WebTranslateIt::Safe.const_get(mod).new(config, self).process
16
20
  end
17
21
  end
22
+
18
23
  end
24
+
19
25
  end
20
- end
26
+
27
+ end
@@ -1,7 +1,10 @@
1
1
  module WebTranslateIt
2
+
2
3
  module Safe
4
+
3
5
  class Cloudfiles < Sink
4
- MAX_CLOUDFILES_FILE_SIZE = 5368709120
6
+
7
+ MAX_CLOUDFILES_FILE_SIZE = 5_368_709_120
5
8
 
6
9
  def active?
7
10
  container && user && api_key
@@ -21,24 +24,24 @@ module WebTranslateIt
21
24
  end
22
25
 
23
26
  def save
24
- raise RuntimeError, 'pipe-streaming not supported for S3.' unless @backup.path
27
+ raise 'pipe-streaming not supported for S3.' unless @backup.path
25
28
 
26
29
  # needed in cleanup even on dry run
27
30
  cf = CloudFiles::Connection.new(user, api_key, true, service_net) unless local_only?
28
31
  puts "Uploading #{container}:#{full_path} from #{@backup.path}" if verbose? || dry_run?
29
- unless dry_run? || local_only?
30
- if get_file_size(@backup.path) > MAX_CLOUDFILES_FILE_SIZE
31
- STDERR.puts "ERROR: File size exceeds maximum allowed for upload to Cloud Files (#{MAX_CLOUDFILES_FILE_SIZE}): #{@backup.path}"
32
- return
33
- end
34
- benchmark = Benchmark.realtime do
35
- cf_container = cf.create_container(container)
36
- o = cf_container.create_object(full_path,true)
37
- o.write(File.open(@backup.path))
38
- end
39
- puts '...done' if verbose?
40
- puts('Upload took ' + sprintf('%.2f', benchmark) + ' second(s).') if verbose?
32
+ return if dry_run? || local_only?
33
+
34
+ if get_file_size(@backup.path) > MAX_CLOUDFILES_FILE_SIZE
35
+ warn "ERROR: File size exceeds maximum allowed for upload to Cloud Files (#{MAX_CLOUDFILES_FILE_SIZE}): #{@backup.path}"
36
+ return
41
37
  end
38
+ benchmark = Benchmark.realtime do
39
+ cf_container = cf.create_container(container)
40
+ o = cf_container.create_object(full_path, true)
41
+ o.write(File.open(@backup.path))
42
+ end
43
+ puts '...done' if verbose?
44
+ puts("Upload took #{format('%.2f', benchmark)} second(s).") if verbose?
42
45
  end
43
46
 
44
47
  def cleanup
@@ -49,7 +52,7 @@ module WebTranslateIt
49
52
  puts "listing files: #{container}:#{base}*" if verbose?
50
53
  cf = CloudFiles::Connection.new(user, api_key, true, service_net) unless local_only?
51
54
  cf_container = cf.container(container)
52
- files = cf_container.objects(:prefix => base).sort
55
+ files = cf_container.objects(prefix: base).sort
53
56
 
54
57
  cleanup_with_limit(files, keep) do |f|
55
58
  puts "removing Cloud File #{container}:#{f}" if dry_run? || verbose?
@@ -72,6 +75,9 @@ module WebTranslateIt
72
75
  def service_net
73
76
  config[:cloudfiles, :service_net] || false
74
77
  end
78
+
75
79
  end
80
+
76
81
  end
82
+
77
83
  end
@@ -1,15 +1,19 @@
1
1
  module WebTranslateIt
2
+
2
3
  module Safe
4
+
3
5
  module Config
6
+
4
7
  class Builder
5
8
 
6
9
  def initialize(node, data = {})
7
10
  @node = node
8
- data.each { |k, v| self.send k, v }
11
+ data.each { |k, v| send k, v }
9
12
  end
10
13
 
11
14
 
12
15
  class << self
16
+
13
17
  def simple_value(*names)
14
18
  names.each do |m|
15
19
  define_method(m) do |value|
@@ -40,7 +44,7 @@ module WebTranslateIt
40
44
 
41
45
  def mixed_value(*names)
42
46
  names.each do |m|
43
- define_method(m) do |data={}, &block|
47
+ define_method(m) do |data = {}, &block|
44
48
  ensure_uniq(m)
45
49
  if data.is_a?(Hash) || block
46
50
  ensure_hash(m, data) if block
@@ -54,8 +58,9 @@ module WebTranslateIt
54
58
 
55
59
  def collection(*names)
56
60
  names.each do |m|
57
- define_method(m) do |id, data={}, &block|
61
+ define_method(m) do |id, data = {}, &block|
58
62
  raise "bad collection id: #{id.inspect}" unless id
63
+
59
64
  ensure_hash(m, data)
60
65
 
61
66
  name = "#{m}s"
@@ -64,15 +69,15 @@ module WebTranslateIt
64
69
  end
65
70
  end
66
71
  end
72
+
67
73
  end
68
74
 
69
75
  simple_value :verbose, :dry_run, :local_only, :path, :command,
70
- :options, :user, :host, :port, :password, :key, :secret, :bucket,
71
- :api_key, :container, :socket, :service_net, :repo_path
76
+ :options, :user, :host, :port, :password, :key, :secret, :bucket,
77
+ :api_key, :container, :socket, :service_net, :repo_path
72
78
  multi_value :skip_tables, :exclude, :files
73
- hash_value :mysqldump, :tar, :gpg, :keep, :pgdump, :tar, :svndump,
74
- :sftp, :ftp, :mongodump
75
- mixed_value :s3, :local, :cloudfiles
79
+ mixed_value :s3, :local, :cloudfiles, :sftp, :mysqldump, :tar, :gpg, :keep, :pgdump, :tar, :svndump,
80
+ :ftp, :mongodump
76
81
  collection :database, :archive, :repo
77
82
 
78
83
  private
@@ -84,7 +89,11 @@ module WebTranslateIt
84
89
  def ensure_hash(k, v)
85
90
  raise "#{k}: hash expected: #{v.inspect}" unless v.is_a?(Hash)
86
91
  end
92
+
87
93
  end
94
+
88
95
  end
96
+
89
97
  end
98
+
90
99
  end
@@ -1,8 +1,12 @@
1
1
  require 'webtranslateit/safe/config/builder'
2
2
  module WebTranslateIt
3
+
3
4
  module Safe
5
+
4
6
  module Config
7
+
5
8
  class Node
9
+
6
10
  attr_reader :parent, :data
7
11
 
8
12
  def initialize(parent = nil, data = {}, &block)
@@ -11,7 +15,7 @@ module WebTranslateIt
11
15
  merge data, &block
12
16
  end
13
17
 
14
- def merge data = {}, &block
18
+ def merge(data = {}, &block)
15
19
  builder = Builder.new(self, data)
16
20
  builder.instance_eval(&block) if block
17
21
  self
@@ -21,27 +25,27 @@ module WebTranslateIt
21
25
  def get(*path)
22
26
  key = path.shift
23
27
  value = @data[key.to_s]
24
- return value if (nil != value) && path.empty?
28
+ return value if !value.nil? && path.empty?
25
29
 
26
- value && value.get(*path)
30
+ value&.get(*path)
27
31
  end
28
32
 
29
33
  # recursive find
30
34
  # starts at the node and continues to the parent
31
35
  def find(*path)
32
- get(*path) || @parent && @parent.find(*path)
36
+ get(*path) || @parent&.find(*path)
33
37
  end
34
- alias :[] :find
38
+ alias [] find
35
39
 
36
40
  def set_multi(key, value)
37
41
  @data[key.to_s] ||= []
38
- @data[key.to_s].concat [*value]
42
+ @data[key.to_s].push(*value)
39
43
  end
40
44
 
41
45
  def set(key, value)
42
46
  @data[key.to_s] = value
43
47
  end
44
- alias :[]= :set
48
+ alias []= set
45
49
 
46
50
  def each(&block)
47
51
  @data.each(&block)
@@ -49,10 +53,9 @@ module WebTranslateIt
49
53
  include Enumerable
50
54
 
51
55
  def to_hash
52
- @data.keys.inject({}) do |res, key|
56
+ @data.keys.each_with_object({}) do |key, res|
53
57
  value = @data[key]
54
58
  res[key] = value.is_a?(Node) ? value.to_hash : value
55
- res
56
59
  end
57
60
  end
58
61
 
@@ -60,13 +63,17 @@ module WebTranslateIt
60
63
  @data.each do |key, value|
61
64
  if value.is_a?(Node)
62
65
  puts "#{indent}#{key}:"
63
- value.dump(indent + ' ')
66
+ value.dump("#{indent} ")
64
67
  else
65
68
  puts "#{indent}#{key}: #{value.inspect}"
66
69
  end
67
70
  end
68
71
  end
72
+
69
73
  end
74
+
70
75
  end
76
+
71
77
  end
78
+
72
79
  end
@@ -1,5 +1,7 @@
1
1
  module WebTranslateIt
2
+
2
3
  module Safe
4
+
3
5
  class Ftp < Sink
4
6
 
5
7
  protected
@@ -13,26 +15,24 @@ module WebTranslateIt
13
15
  end
14
16
 
15
17
  def save
16
- raise RuntimeError, 'pipe-streaming not supported for FTP.' unless @backup.path
18
+ raise 'pipe-streaming not supported for FTP.' unless @backup.path
17
19
 
18
20
  puts "Uploading #{host}:#{full_path} via FTP" if verbose? || dry_run?
19
21
 
20
- unless dry_run? || local_only?
21
- if !port
22
- port = 21
23
- end
24
- Net::FTP.open(host) do |ftp|
25
- ftp.connect(host, port)
26
- ftp.login(user, password)
27
- puts "Sending #{@backup.path} to #{full_path}" if verbose?
28
- begin
29
- ftp.put(@backup.path, full_path)
30
- rescue Net::FTPPermError
31
- puts "Ensuring remote path (#{path}) exists" if verbose?
32
- end
22
+ return if dry_run? || local_only?
23
+
24
+ port ||= 21
25
+ Net::FTP.open(host) do |ftp|
26
+ ftp.connect(host, port)
27
+ ftp.login(user, password)
28
+ puts "Sending #{@backup.path} to #{full_path}" if verbose?
29
+ begin
30
+ ftp.put(@backup.path, full_path)
31
+ rescue Net::FTPPermError
32
+ puts "Ensuring remote path (#{path}) exists" if verbose?
33
33
  end
34
- puts '...done' if verbose?
35
34
  end
35
+ puts '...done' if verbose?
36
36
  end
37
37
 
38
38
  def cleanup
@@ -41,20 +41,18 @@ module WebTranslateIt
41
41
  return unless keep = config[:keep, :ftp]
42
42
 
43
43
  puts "listing files: #{host}:#{base}*" if verbose?
44
- if !port
45
- port = 21
46
- end
44
+ port ||= 21
47
45
  Net::FTP.open(host) do |ftp|
48
46
  ftp.connect(host, port)
49
47
  ftp.login(user, password)
50
48
  files = ftp.nlst(path)
51
- pattern = File.basename("#{base}")
52
- files = files.reject{ |x| !x.start_with?(pattern)}
53
- puts files.collect {|x| x} if verbose?
49
+ pattern = File.basename(base.to_s)
50
+ files = files.select { |x| x.start_with?(pattern) }
51
+ puts files.collect { |x| x } if verbose?
54
52
 
55
- files = files.
56
- collect {|x| x }.
57
- sort
53
+ files = files
54
+ .collect { |x| x }
55
+ .sort
58
56
 
59
57
  cleanup_with_limit(files, keep) do |f|
60
58
  file = File.join(path, f)
@@ -81,5 +79,7 @@ module WebTranslateIt
81
79
  end
82
80
 
83
81
  end
82
+
84
83
  end
85
- end
84
+
85
+ end
@@ -1,9 +1,11 @@
1
1
  module WebTranslateIt
2
+
2
3
  module Safe
4
+
3
5
  class Gpg < Pipe
4
6
 
5
7
  def active?
6
- raise RuntimeError, "can't use both gpg password and pubkey" if key && password
8
+ raise "can't use both gpg password and pubkey" if key && password
7
9
 
8
10
  !!(password || key)
9
11
  end
@@ -39,8 +41,12 @@ module WebTranslateIt
39
41
 
40
42
  def gpg_password_file(pass)
41
43
  return 'TEMP_GENERATED_FILENAME' if dry_run?
44
+
42
45
  WebTranslateIt::Safe::TmpFile.create('gpg-pass') { |file| file.write(pass) }
43
46
  end
47
+
44
48
  end
49
+
45
50
  end
46
- end
51
+
52
+ end
@@ -1,5 +1,7 @@
1
1
  module WebTranslateIt
2
+
2
3
  module Safe
4
+
3
5
  class Gzip < Pipe
4
6
 
5
7
  protected
@@ -21,5 +23,7 @@ module WebTranslateIt
21
23
  end
22
24
 
23
25
  end
26
+
24
27
  end
25
- end
28
+
29
+ end
@@ -1,5 +1,7 @@
1
1
  module WebTranslateIt
2
+
2
3
  module Safe
4
+
3
5
  class Local < Sink
4
6
 
5
7
  def active?
@@ -11,7 +13,7 @@ module WebTranslateIt
11
13
  protected
12
14
 
13
15
  def path
14
- @path ||= File.expand_path(expand(config[:local, :path] || raise(RuntimeError, 'missing :local/:path')))
16
+ @path ||= File.expand_path(expand(config[:local, :path] || raise('missing :local/:path')))
15
17
  end
16
18
 
17
19
  def save
@@ -20,14 +22,13 @@ module WebTranslateIt
20
22
  # FIXME: probably need to change this to smth like @backup.finalize!
21
23
  @backup.path = full_path # need to do it outside DRY_RUN so that it will be avialable for S3 DRY_RUN
22
24
 
23
- unless dry_run?
24
- FileUtils.mkdir_p(path) unless File.directory?(path)
25
- benchmark = Benchmark.realtime do
26
- system "#{@backup.command}>#{@backup.path}"
27
- end
28
- puts('command took ' + sprintf('%.2f', benchmark) + ' second(s).') if verbose?
29
- end
25
+ return if dry_run?
30
26
 
27
+ FileUtils.mkdir_p(path) unless File.directory?(path)
28
+ benchmark = Benchmark.realtime do
29
+ system "#{@backup.command}>#{@backup.path}"
30
+ end
31
+ puts("command took #{format('%.2f', benchmark)} second(s).") if verbose?
31
32
  end
32
33
 
33
34
  def cleanup
@@ -37,15 +38,18 @@ module WebTranslateIt
37
38
 
38
39
  # TODO: cleanup ALL zero-length files
39
40
 
40
- files = Dir["#{base}*"] .
41
- select{|f| File.file?(f) && File.size(f) > 0} .
42
- sort
41
+ files = Dir["#{base}*"]
42
+ .select { |f| File.file?(f) && File.size(f).positive? }
43
+ .sort
43
44
 
44
45
  cleanup_with_limit(files, keep) do |f|
45
46
  puts "removing local file #{f}" if dry_run? || verbose?
46
47
  File.unlink(f) unless dry_run?
47
48
  end
48
49
  end
50
+
49
51
  end
52
+
50
53
  end
54
+
51
55
  end
@@ -1,23 +1,29 @@
1
1
  module WebTranslateIt
2
+
2
3
  module Safe
4
+
3
5
  class Mongodump < Source
4
-
6
+
5
7
  def command
6
8
  opts = []
7
9
  opts << "--host #{config[:host]}" if config[:host]
8
10
  opts << "-u #{config[:user]}" if config[:user]
9
11
  opts << "-p #{config[:password]}" if config[:password]
10
12
  opts << "--out #{output_directory}"
11
-
12
- "mongodump -q \"{xxxx : { \\$ne : 0 } }\" --db #{@id} #{opts.join(" ")} && cd #{output_directory} && tar cf - ."
13
+
14
+ "mongodump -q \"{xxxx : { \\$ne : 0 } }\" --db #{@id} #{opts.join(' ')} && cd #{output_directory} && tar cf - ."
13
15
  end
14
-
15
- def extension; '.tar'; end
16
-
16
+
17
+ def extension = '.tar'
18
+
17
19
  protected
20
+
18
21
  def output_directory
19
22
  File.join(TmpFile.tmproot, 'mongodump')
20
23
  end
24
+
21
25
  end
26
+
22
27
  end
28
+
23
29
  end
@@ -1,12 +1,14 @@
1
1
  module WebTranslateIt
2
+
2
3
  module Safe
4
+
3
5
  class Mysqldump < Source
4
6
 
5
7
  def command
6
8
  "mysqldump --defaults-extra-file=#{mysql_password_file} #{config[:options]} #{mysql_skip_tables} #{@id}"
7
9
  end
8
10
 
9
- def extension; '.sql'; end
11
+ def extension = '.sql'
10
12
 
11
13
  protected
12
14
 
@@ -22,11 +24,13 @@ module WebTranslateIt
22
24
  end
23
25
 
24
26
  def mysql_skip_tables
25
- if skip_tables = config[:skip_tables]
26
- [*skip_tables].map{ |t| "--ignore-table=#{@id}.#{t}" }.join(' ')
27
- end
27
+ return unless skip_tables = config[:skip_tables]
28
+
29
+ [*skip_tables].map { |t| "--ignore-table=#{@id}.#{t}" }.join(' ')
28
30
  end
29
31
 
30
32
  end
33
+
31
34
  end
32
- end
35
+
36
+ end