rsync_cron 1.0.8 → 1.1.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
  SHA1:
3
- metadata.gz: d9bdf25fe2470358e6e7b7481cf95decd6ea923a
4
- data.tar.gz: 499d221a5ce98c084d37850fb50fe69a199f171a
3
+ metadata.gz: c2575308bc9803d0ece5c71d56115c423a4f57a3
4
+ data.tar.gz: 303b02d78de7296e94499745eea1a62cfe34e045
5
5
  SHA512:
6
- metadata.gz: ab7773214e1c73426672aec01663191c5cae2a2b4c696af71d4932481bf1e7010dfd1467a27a5985b8a27ba4401fd8e0de72b35807708b01b2fd872dcad0849e
7
- data.tar.gz: c9f9804ed7b6ed53cfe745a0ee779370b61af7295ee0a4de89325477b1241f977452ed0e0ba9ea459feca540758920db2ca50d2f88214d4678e45fb88f696c2f
6
+ metadata.gz: 3514d059391e6484357cbad1e1a94efb97999a8ce1f661fad92f907235e636b81ba7e8719a4bdc82f91ad9643716f8372d6af54b29687753f48da96ea601abb4
7
+ data.tar.gz: fa594e0265047d102fcfb01d18937999dc19aa950c659fc7685ae710a7bd7ccf77e42f84974781ef750a91d69880385b22f1fc74baf2e43d85c7b9537b0b7064
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsync_cron (1.0.8)
4
+ rsync_cron (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -14,14 +14,15 @@ gem install rsync_cron
14
14
  ```
15
15
 
16
16
  # Usage
17
- The gem comes with a CLI interface. You can print its help by:
17
+ The gem comes with a CLI interface, you can print its help by:
18
18
  ```shell
19
19
  rsync_cron -h
20
- Usage: rsync_cron --cron=15,30 21 * * * --src=/ --dest=/tmp --log=/var/log/rsync.log
21
- -c, --cron=CRON The cron string, i.e.: 15 21 * * *
20
+ Usage: rsync_cron --cron='15,30 21' --src=/ --dest=/tmp --log=/var/log/rsync.log --opts=noatime,temp-dir='./temp'
21
+ -c, --cron=CRON The cron string, i.e.: '15 21 * * *'
22
22
  -s, --src=SRC The rsync source, i.e. user@src.com:files
23
23
  -d, --dest=DEST The rsync dest, i.e. user@dest.com:home/
24
24
  -l, --log=LOG log command output to specified file
25
+ -o, --opts=OPTS merge specified extra options
25
26
  -p, --print Print crontab command without installing it
26
27
  -k, --check Check src and dest before installing crontab
27
28
  -h, --help Prints this help
@@ -32,12 +33,5 @@ The `crontab` is scheduled one per day by default (at midnight).
32
33
  You can specify a different schedule directly on the command line:
33
34
  ```shell
34
35
  # run every sunday
35
- rsync_cron --cron=* * * * 0 --src=user@src.com:files --dest=~/tmp
36
+ rsync_cron --cron='* * * * 0' --src=user@src.com:files --dest=~/tmp
36
37
  ```
37
-
38
- ## Log to a file
39
- It is possible to log the `rsync` output to a file:
40
- ```shell
41
- rsync_cron --src=user@src.com:files --dest=~/tmp --log=./rsync.log
42
- ```
43
-
@@ -8,18 +8,21 @@ module RsyncCron
8
8
  class CLI
9
9
  SHELL = `which crontab`.strip
10
10
 
11
+ attr_reader :options
12
+
11
13
  def initialize(args, io = STDOUT, shell = SHELL)
12
14
  @args = args
13
15
  @io = io
14
16
  @cron = Cron.factory("* 0 * * *")
15
17
  @shell = shell
18
+ @options = Options.new
16
19
  end
17
20
 
18
21
  def call
19
22
  parser.parse!(@args)
20
23
  return @io.puts "specify valid src" unless @src
21
24
  return @io.puts "specify valid dest" unless @dest
22
- command = Command.new(src: @src, dest: @dest, log: @log, io: @io)
25
+ command = Command.new(src: @src, dest: @dest, options: @options, log: @log, io: @io)
23
26
  return unless command.valid? if @check
24
27
  crontab = "#{@cron} #{command}"
25
28
  return @io.puts crontab unless @shell
@@ -30,9 +33,9 @@ module RsyncCron
30
33
 
31
34
  private def parser
32
35
  OptionParser.new do |opts|
33
- opts.banner = "Usage: rsync_cron --cron=15,30 21 * * * --src=/ --dest=/tmp --log=/var/log/rsync.log"
36
+ opts.banner = "Usage: rsync_cron --cron='15,30 21' --src=/ --dest=/tmp --log=/var/log/rsync.log --opts=noatime,temp-dir='./temp'"
34
37
 
35
- opts.on("-cCRON", "--cron=CRON", "The cron string, i.e.: 15 21 * * *") do |cron|
38
+ opts.on("-cCRON", "--cron=CRON", "The cron string, i.e.: '15 21 * * *'") do |cron|
36
39
  @cron = Cron.factory(cron)
37
40
  end
38
41
 
@@ -48,6 +51,10 @@ module RsyncCron
48
51
  @log = log
49
52
  end
50
53
 
54
+ opts.on("-oOPTS", "--opts=OPTS", "merge specified extra options") do |_opts|
55
+ @options << _opts
56
+ end
57
+
51
58
  opts.on("-p", "--print", "Print crontab command without installing it") do
52
59
  @shell = nil
53
60
  end
@@ -14,7 +14,7 @@ module RsyncCron
14
14
  end
15
15
 
16
16
  def to_s
17
- return "echo 'rsync not installed'" if @name.empty?
17
+ return @io.puts "rsync not installed" if @name.empty?
18
18
  "#{@name} #{@options} #{@src} #{@dest}#{log}"
19
19
  end
20
20
 
@@ -1,37 +1,26 @@
1
1
  module RsyncCron
2
2
  class Options
3
- BANDWITH_LIMIT = 5*1024
4
- DEFAULT = {
5
- rsh: "ssh",
6
- bwlimit: BANDWITH_LIMIT,
7
- exclude: "'DfsrPrivate'"
8
- }
9
- FLAGS = %w[noatime verbose archive compress]
3
+ BW_LIMIT = 5*1024
4
+ DEFAULT_FLAGS = %W[verbose archive compress rsh=ssh bwlimit=#{BW_LIMIT} exclude='DfsrPrivate']
10
5
 
11
- def initialize(data: DEFAULT, flags: FLAGS)
12
- @data = data.to_h
13
- @flags = flags.to_a
6
+ def initialize(flags = DEFAULT_FLAGS)
7
+ @flags = Array(flags.dup)
14
8
  end
15
9
 
16
10
  def to_s
17
- [flags, data].compact.join(" ")
11
+ return if @flags.empty?
12
+ @flags.map { |flag| "--#{flag}" }.join(" ")
18
13
  end
19
14
 
20
- def merge(opt)
21
- @data = @data.merge(opt)
15
+ def <<(flags)
16
+ flags.split(",").each do |flag|
17
+ @flags << flag if supported?(flag)
18
+ end
22
19
  self
23
20
  end
24
21
 
25
- private def flags
26
- return if @flags.empty?
27
- @flags.map { |flag| "--#{flag}" }.join(" ")
28
- end
29
-
30
- private def data
31
- return if @data.empty?
32
- @data.reduce([]) do |acc, (opt, val)|
33
- acc << "--#{opt}=#{val}"
34
- end.join(" ")
22
+ private def supported?(flag)
23
+ %x[rsync --#{flag} 2>&1].match(/unknown option/).nil?
35
24
  end
36
25
  end
37
26
  end
@@ -1,3 +1,3 @@
1
1
  module RsyncCron
2
- VERSION = "1.0.8"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsync_cron
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - costajob