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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +5 -11
- data/lib/rsync_cron/cli.rb +10 -3
- data/lib/rsync_cron/command.rb +1 -1
- data/lib/rsync_cron/options.rb +12 -23
- data/lib/rsync_cron/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2575308bc9803d0ece5c71d56115c423a4f57a3
|
4
|
+
data.tar.gz: 303b02d78de7296e94499745eea1a62cfe34e045
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3514d059391e6484357cbad1e1a94efb97999a8ce1f661fad92f907235e636b81ba7e8719a4bdc82f91ad9643716f8372d6af54b29687753f48da96ea601abb4
|
7
|
+
data.tar.gz: fa594e0265047d102fcfb01d18937999dc19aa950c659fc7685ae710a7bd7ccf77e42f84974781ef750a91d69880385b22f1fc74baf2e43d85c7b9537b0b7064
|
data/Gemfile.lock
CHANGED
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
|
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
|
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
|
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
|
-
|
data/lib/rsync_cron/cli.rb
CHANGED
@@ -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
|
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
|
data/lib/rsync_cron/command.rb
CHANGED
data/lib/rsync_cron/options.rb
CHANGED
@@ -1,37 +1,26 @@
|
|
1
1
|
module RsyncCron
|
2
2
|
class Options
|
3
|
-
|
4
|
-
|
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(
|
12
|
-
@
|
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
|
-
|
11
|
+
return if @flags.empty?
|
12
|
+
@flags.map { |flag| "--#{flag}" }.join(" ")
|
18
13
|
end
|
19
14
|
|
20
|
-
def
|
21
|
-
|
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
|
26
|
-
|
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
|
data/lib/rsync_cron/version.rb
CHANGED