Class: Rsync
Instance Attribute Summary collapse
Attributes inherited from CliFuncs
#ignore_bad_exit
Instance Method Summary
collapse
Methods inherited from CliFuncs
#clear_values, #flag_add, #flags_run, #run_and_capture, #set_dirs
Constructor Details
#initialize ⇒ Rsync
Returns a new instance of Rsync.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/cli_funcs_rsync.rb', line 8
def initialize
super
@utility = CliUtils.new("rsync").utility_path
@uptodate = Array.new
@deleted = Array.new
@modified = Array.new
@created = Array.new
@excluded = Hash.new
@ignored = Array.new
@duplicates = Array.new
@transfer_stats = Hash.new
@source = Array.new
@destination = String
@output_filter_junk = Regexp
@output_filter_excluded = Regexp
@output_filter_warn_err = Regexp
@output_filter_stats = Regexp
@output_filter_duplicates = Regexp
@output_filter_created = Regexp
set_flags_base
set_output_filters
end
|
Instance Attribute Details
#base_dir ⇒ Object
Returns the value of attribute base_dir.
6
7
8
|
# File 'lib/cli_funcs_rsync.rb', line 6
def base_dir
@base_dir
end
|
#cmd_run ⇒ Object
Returns the value of attribute cmd_run.
5
6
7
|
# File 'lib/cli_funcs_rsync.rb', line 5
def cmd_run
@cmd_run
end
|
#created ⇒ Object
Returns the value of attribute created.
6
7
8
|
# File 'lib/cli_funcs_rsync.rb', line 6
def created
@created
end
|
#data_dir ⇒ Object
Returns the value of attribute data_dir.
6
7
8
|
# File 'lib/cli_funcs_rsync.rb', line 6
def data_dir
@data_dir
end
|
#deleted ⇒ Object
Returns the value of attribute deleted.
6
7
8
|
# File 'lib/cli_funcs_rsync.rb', line 6
def deleted
@deleted
end
|
#destination ⇒ Object
Returns the value of attribute destination.
5
6
7
|
# File 'lib/cli_funcs_rsync.rb', line 5
def destination
@destination
end
|
#duplicates ⇒ Object
Returns the value of attribute duplicates.
6
7
8
|
# File 'lib/cli_funcs_rsync.rb', line 6
def duplicates
@duplicates
end
|
#excluded ⇒ Object
Returns the value of attribute excluded.
6
7
8
|
# File 'lib/cli_funcs_rsync.rb', line 6
def excluded
@excluded
end
|
#flags_all ⇒ Object
Returns the value of attribute flags_all.
5
6
7
|
# File 'lib/cli_funcs_rsync.rb', line 5
def flags_all
@flags_all
end
|
#ignored ⇒ Object
Returns the value of attribute ignored.
6
7
8
|
# File 'lib/cli_funcs_rsync.rb', line 6
def ignored
@ignored
end
|
#modified ⇒ Object
Returns the value of attribute modified.
6
7
8
|
# File 'lib/cli_funcs_rsync.rb', line 6
def modified
@modified
end
|
#output ⇒ Object
Returns the value of attribute output.
6
7
8
|
# File 'lib/cli_funcs_rsync.rb', line 6
def output
@output
end
|
#source ⇒ Object
Returns the value of attribute source.
5
6
7
|
# File 'lib/cli_funcs_rsync.rb', line 5
def source
@source
end
|
#transfer_stats ⇒ Object
Returns the value of attribute transfer_stats.
6
7
8
|
# File 'lib/cli_funcs_rsync.rb', line 6
def transfer_stats
@transfer_stats
end
|
#uptodate ⇒ Object
Returns the value of attribute uptodate.
6
7
8
|
# File 'lib/cli_funcs_rsync.rb', line 6
def uptodate
@uptodate
end
|
Instance Method Details
#flag_archive ⇒ Object
316
317
318
|
# File 'lib/cli_funcs_rsync.rb', line 316
def flag_archive
flag_add("-a")
end
|
#flag_bwlimit(kbps) ⇒ Object
332
333
334
|
# File 'lib/cli_funcs_rsync.rb', line 332
def flag_bwlimit(kbps)
flag_add("--bwlimit=#{kbps}")
end
|
#flag_checksum ⇒ Object
324
325
326
|
# File 'lib/cli_funcs_rsync.rb', line 324
def flag_checksum
flag_add("-c")
end
|
#flag_compress ⇒ Object
304
305
306
|
# File 'lib/cli_funcs_rsync.rb', line 304
def flag_compress
flag_add("-z")
end
|
#flag_delete ⇒ Object
300
301
302
|
# File 'lib/cli_funcs_rsync.rb', line 300
def flag_delete
flag_add("--delete")
end
|
#flag_dryrun ⇒ Object
308
309
310
|
# File 'lib/cli_funcs_rsync.rb', line 308
def flag_dryrun
flag_add("-n")
end
|
#flag_exclude(pattern) ⇒ Object
340
341
342
|
# File 'lib/cli_funcs_rsync.rb', line 340
def flag_exclude(pattern)
flag_add("--exclude=#{pattern[1..-1]}")
end
|
#flag_itemized ⇒ Object
320
321
322
|
# File 'lib/cli_funcs_rsync.rb', line 320
def flag_itemized
flag_add("-i")
end
|
#flag_rsync_path(path) ⇒ Object
336
337
338
|
# File 'lib/cli_funcs_rsync.rb', line 336
def flag_rsync_path(path)
flag_add("--rsync-path=#{path}")
end
|
#flag_stats ⇒ Object
328
329
330
|
# File 'lib/cli_funcs_rsync.rb', line 328
def flag_stats
flag_add("--stats")
end
|
#flag_verbose ⇒ Object
312
313
314
|
# File 'lib/cli_funcs_rsync.rb', line 312
def flag_verbose
flag_add("-vv")
end
|
#output_process ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/cli_funcs_rsync.rb', line 44
def output_process
@output.each do |line|
if line.match @output_filter_junk
next
elsif line.match @output_filter_duplicates
puts "#{line.chomp} DUPLICATE!" if DEBUG
@duplicates.push(line)
next
elsif line.match @output_filter_excluded
puts "#{line.chomp} EXCLUDED!" if DEBUG
@excluded[$3] = $4
next
elsif line.match @output_filter_warn_err
next
elsif line.match @output_filter_stats
@transfer_stats[$1] = $2
@transfer_stats[$3] = $4
@transfer_stats[$5] = $6
@transfer_stats[$7] = $8
@transfer_stats[$9] = $10
@transfer_stats[$11] = $12
@transfer_stats[$13] = $14
@transfer_stats[$15] = $16
@transfer_stats[$17] = $18
@transfer_stats[$19] = $20
@transfer_stats[$21] = $22
next
elsif line.match @output_filter_created
next
else
process_itemized(line)
end
end
puts @transfer_stats.inspect if DEBUG
end
|
#process_itemized(line) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/cli_funcs_rsync.rb', line 84
def process_itemized(line)
attrs,item = line.split(/\s+/, 2)
attrs_p = attrs.split("")
if(attrs_p[0] == ".")
if(
attrs_p[1] == "d" and
attrs_p[2] == "." and
attrs_p[3] == "." and
attrs_p[4] == "t" and
attrs_p[5] == "." and
attrs_p[6] == "." and
attrs_p[7] == "." and
attrs_p[8] == "." and
attrs_p[9] == "." and
attrs_p[10] == "."
)
puts "#{line.chomp} IGNORED!" if DEBUG
@ignored.push(line)
elsif(
attrs_p[1] =~ /f|d|L|D|S/ and
attrs_p[2] == nil and
attrs_p[3] == nil and
attrs_p[4] == nil and
attrs_p[5] == nil and
attrs_p[6] == nil and
attrs_p[7] == nil and
attrs_p[8] == nil and
attrs_p[9] == nil and
attrs_p[10] == nil
)
puts "#{line.chomp} UPTODATE!" if DEBUG
@uptodate.push(line)
else
puts "#{line.chomp} MODIFIED OWNERSHIP OR MODE!" if DEBUG
@modified.push(line)
end
elsif(attrs_p[0] =~ /\*|<|>|c|h/)
if(
attrs_p[1] == "d" and
attrs_p[2] == "e" and
attrs_p[3] == "l" and
attrs_p[4] == "e" and
attrs_p[5] == "t" and
attrs_p[6] == "i" and
attrs_p[7] == "n" and
attrs_p[8] == "g" and
attrs_p[9] == nil and
attrs_p[10] == nil
)
puts "#{line.chomp} DELETED!" if DEBUG
@deleted.push(line)
elsif(
attrs_p[1] =~ /f|d/ and
attrs_p[2] == "+" and
attrs_p[3] == "+" and
attrs_p[4] == "+" and
attrs_p[5] == "+" and
attrs_p[6] == "+" and
attrs_p[7] == "+" and
attrs_p[8] == "+" and
attrs_p[9] == "+" and
attrs_p[10] == "+"
)
puts "#{line.chomp} CREATED!" if DEBUG
@created.push(line)
else
puts "#{line.chomp} MODIFIED CATCH ALL 1!" if DEBUG
@modified.push(line)
end
else
puts "#{line.chomp} MODIFIED CATCH ALL 2!" if DEBUG
@modified.push(line)
end
end
|
#rsync ⇒ Object
31
32
33
|
# File 'lib/cli_funcs_rsync.rb', line 31
def rsync
run_and_capture(cmd_run)
end
|
#set_flags_base ⇒ Object
344
345
346
347
348
349
350
|
# File 'lib/cli_funcs_rsync.rb', line 344
def set_flags_base
flag_archive
flag_verbose
flag_itemized
flag_delete
flag_stats
end
|
#set_output_filter_created ⇒ Object
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/cli_funcs_rsync.rb', line 185
def set_output_filter_created
filter = Array.new
filter.push("^created directory .*")
@output_filter_created = /#{filter[0]}/
end
|
#set_output_filter_duplicates ⇒ Object
220
221
222
223
224
225
226
227
|
# File 'lib/cli_funcs_rsync.rb', line 220
def set_output_filter_duplicates
filter = Array.new
filter.push("^removing duplicate name .* from file list .*")
@output_filter_duplicates = /#{filter[0]}/
end
|
#set_output_filter_excluded ⇒ Object
215
216
217
218
|
# File 'lib/cli_funcs_rsync.rb', line 215
def set_output_filter_excluded
@output_filter_excluded = /^\[generator\] (excluding|protecting) (file|directory) (.*) because of pattern (.*)$/
end
|
#set_output_filter_junk ⇒ Object
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
# File 'lib/cli_funcs_rsync.rb', line 229
def set_output_filter_junk
filter = Array.new
filter.push("^$")
filter.push("^sending incremental file list")
filter.push("^building file list ...")
filter.push("^expand file_list\s\w+")
filter.push("^rsync: expand\s\w+")
filter.push("^opening connection\s\w+")
filter.push("^total")
filter.push("^wrote")
filter.push("^sent")
filter.push("^done")
filter.push("^excluding")
filter.push("^hiding")
filter.push("^delta( |-)transmission (dis|en)abled")
filter.push("^deleting in \./")
filter.push("^opening connection using: ssh")
filter.push("^rsync\\[\\d+\\] \\(sender\\) heap statistics:")
filter.push("^rsync\\[\\d+\\] \\(server receiver\\) heap statistics:")
filter.push("^rsync\\[\\d+\\] \\(server generator\\) heap statistics:")
filter.push("^ arena:")
filter.push("^ ordblks:")
filter.push("^ smblks:")
filter.push("^ hblks:")
filter.push("^ hblkhd:")
filter.push("^ allmem:")
filter.push("^ usmblks:")
filter.push("^ fsmblks:")
filter.push("^ uordblks:")
filter.push("^ fordblks:")
filter.push("^ keepcost:")
@output_filter_junk = /#{filter.join("|")}/
end
|
#set_output_filter_stats ⇒ Object
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
# File 'lib/cli_funcs_rsync.rb', line 196
def set_output_filter_stats
filter = Array.new
filter.push("(Number of files): (\\d+)")
filter.push("(Number of files transferred): (\\d+)")
filter.push("(Total file size): (\\d+) bytes")
filter.push("(Total transferred file size): (\\d+) bytes")
filter.push("(Literal data): (\\d+) bytes")
filter.push("(Matched data): (\\d+) bytes")
filter.push("(File list size): (\\d+)")
filter.push("(File list generation time): (.*) seconds")
filter.push("(File list transfer time): (.*) seconds")
filter.push("(Total bytes sent): (\\d+)")
filter.push("(Total bytes received): (\\d+)")
@output_filter_stats = /#{filter.join("|")}/
end
|
#set_output_filter_warn_err ⇒ Object
172
173
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/cli_funcs_rsync.rb', line 172
def set_output_filter_warn_err
filter = Array.new
filter.push("WARNING: .* failed verification -- update discarded \(will try again\)\.")
filter.push("IO error encountered -- skipping file deletion")
filter.push("file has vanished: .*")
filter.push("rsync (error|warning): .*")
filter.push("cannot delete non-empty directory: .*")
@output_filter_warn_err = /#{filter.join("|")}/
end
|
#set_output_filters ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/cli_funcs_rsync.rb', line 35
def set_output_filters
set_output_filter_junk
set_output_filter_excluded
set_output_filter_warn_err
set_output_filter_stats
set_output_filter_duplicates
set_output_filter_created
end
|