1Rsync(3)              User Contributed Perl Documentation             Rsync(3)
2
3
4

NAME

6       File::Rsync - perl module interface to rsync(1)
7       http://rsync.samba.org/rsync/
8

SYNOPSIS

10           use File::Rsync;
11
12           $obj = File::Rsync->new(
13               archive      => 1,
14               compress     => 1,
15               rsh          => '/usr/local/bin/ssh',
16               'rsync-path' => '/usr/local/bin/rsync'
17           );
18
19           $obj->exec( src => 'localdir', dest => 'rhost:remotedir' )
20               or warn "rsync failed\n";
21

DESCRIPTION

23       Perl Convenience wrapper for the rsync(1) program.  Written for
24       rsync-2.3.2 and updated for rsync-3.1.1 but should perform properly
25       with most recent versions.
26
27   File::Rsync::new
28           $obj = new File::Rsync;
29
30               or
31
32           $obj = File::Rsync->new;
33
34               or
35
36           $obj = File::Rsync->new(@options);
37
38       Create a File::Rsync object.  Any options passed at creation are stored
39       in the object as defaults for all future exec calls on that object.
40       Options may be passed in the style of a hash (key/value pairs) and are
41       the same as the long options in rsync(1) without the leading double-
42       hyphen.  Any leading single or double-hyphens are removed, and you may
43       use underscore in place of hyphens in option names to simplify quoting
44       and avoid possible equation parsing (subtraction).
45
46       Although options are key/value pairs, as of version 0.46 the order is
47       now preserved.  Passing a hash reference is still supported for
48       backwards compatibility, but is deprecated as order cannot be preserved
49       for this case.
50
51       An additional option of path-to-rsync also exists which can be used to
52       override the using PATH environemt variable to find the rsync command
53       binary, and moddebug which causes the module methods to print some
54       debugging information to STDERR.
55
56       There are also 2 options to wrap the source and/or destination paths in
57       double-quotes: these are quote-src and quote-dst, which may be useful
58       in protecting the paths from shell expansion (particularly useful for
59       paths containing spaces).  This wraps all source and/or destination
60       paths in double-quotes to limit remote shell expansion.  It is similar
61       but not necessarily the same result as the protect-args option in rsync
62       itself.
63
64       The outfun and errfun options take a function reference, called once
65       for each line of output from the rsync program with the output line
66       passed in as the first argument, the second arg is either 'out' or
67       'err' depending on the source.  This makes it possible to use the same
68       function for both and still determine where the output came from.
69
70       If options are passed as a hash reference (deprecated), the exclude
71       needs an array reference as it's value since there cannot be duplicate
72       keys in a hash.  Since order cannot be preserved in a hash, this module
73       currently limits the use of exclude or include together.  They can be
74       mixed together if options are in the form of a list or array ref.
75
76       Use the '+ ' or '- ' prefix trick to put includes in an exclude array,
77       or to put excludes in an include array (see rsync(1) for details).
78
79       Include/exclude options form an ordered list.  The order must be
80       retained for proper execution.  There are also source and dest keys.
81       The key src is also accepted as an equivalent to source, and dst or
82       destination may be used as equivalents to dest.  The source option may
83       take a scalar or an array reference.  If the source is the local system
84       then multiple source paths are allowed.  In this case an array
85       reference should be used.  There is also a method for passing multiple
86       source paths to a remote system.  This method may be triggered in this
87       module by passing the remote hostname to the srchost key and passing an
88       array reference to the source key.  If the source host is being
89       accessed via an Rsync server, the remote hostname should have a single
90       trailing colon on the name.  When rsync is called, the srchost value
91       and the values in the source array will be joined with a colon
92       resulting in the double-colon required for server access.  The dest key
93       only takes a scalar since rsync only accepts a single destination path.
94
95       Version 2.6.0 of rsync(1) provides a new files-from option along with a
96       few other supporting options (from0, no-relative, and no-implied-dirs).
97       To support this wonderful new option at the level it deserves, this
98       module now has an additional parameter.  As of version 0.46 the value
99       of files-from may be an array reference.  The contents of the array are
100       passed to files-from the same as the below method using infun but
101       implemented inside the module.
102
103       If files-from is set to '-' (meaning read from stdin) you can define
104       infun to be a reference to a function that prints your file list to the
105       default file handle.  The output from the function is attached to stdin
106       of the rsync call during exec.  If infun is defined it will be called
107       regardless of the value of files-from, so it can provide any data
108       expected on stdin, but keep in mind that stdin will not be attached to
109       a tty so it is not very useful for sending passwords (see the rsync(1)
110       and ssh(1) man pages for ways to handle authentication).  The rsync(1)
111       man page has a more complete description of files-from.  Also see
112       File::Find for ideas to use with files-from and infun.
113
114       The infun option may also be used with the include-from or exclude-from
115       options, but this is generally more clumsy than using the include or
116       exclude arrays.
117
118       Version 2.6.3 of rsync(1) provides new options partial-dir, checksum-
119       seed, keep-dirlinks, inplace, ipv4, and ipv6.  Version 2.6.4 of
120       rsync(1) provides new options del, delete-before delete-during, delay-
121       updates, dirs, filter, fuzzy, itemize-changes, list-only, omit-dir-
122       times, remove-sent-files, max-size, and protocol.
123
124       Version 0.38 of this module also added support for the acls option that
125       is not part of rsync(1) unless the patch has been applied, but people
126       do use it.  It also includes a new literal option that takes an array
127       reference similar to include, exclude, and filter.  Any arguments in
128       the array are passed as literal arguments to rsync, and are passed
129       first.  They should have the proper single or double hyphen prefixes
130       and the elements should be split up the way you want them passed to
131       exec.  The purpose of this option is to allow the use of arbitrary
132       options added by patches, and/or to allow the use of new options in
133       rsync without needing an imediate update to the module in addtition to
134       rsync(1) itself.
135
136   File::Rsync::defopts
137           $obj->defopts(@options);
138
139               or
140
141           $obj->defopts(\@options);
142
143       Set default options for future exec calls for the object.  See rsync(1)
144       for a complete list of valid options.  This is really the internal
145       method that new calls but you can use it too.  The verbose and quiet
146       options to rsync are actually counters.  When assigning the perl hash-
147       style options you may specify the counter value directly and the module
148       will pass the proper number of options to rsync.
149
150   File::Rsync::getcmd
151           my $cmd = $obj->getcmd(@options);
152
153               or
154
155           my $cmd = $obj->getcmd(\@options);
156
157               or
158
159           my ($cmd, $infun, $outfun, $errfun, $debug) = $obj->getcmd(\@options);
160
161       getcmd returns a reference to an array containing the real rsync
162       command that would be called if the exec function were called.  The
163       last example above includes a reference to the optional stdin function,
164       stdout function, stderr function, and the debug setting.  This is the
165       form used by the exec method to get the extra parameters it needs to do
166       its job.  The function is exposed to allow a user-defined exec function
167       to be used, or for debugging purposes.
168
169   File::Rsync::exec
170           $obj->exec(@options) or warn "rsync failed\n";
171
172               or
173
174           $obj->exec(\@options) or warn "rsync failed\n";
175
176       This is the method that does the real work.  Any options passed to this
177       routine are appended to any pre-set options and are not saved.  They
178       effect the current execution of rsync only.  In the case of conflicts,
179       the options passed directly to exec take precedence.  It returns 1 if
180       the return status was zero (or true), if the rsync return status was
181       non-zero it returns 0 and stores the return status.  You can examine
182       the return status from rsync and any output to stdout and stderr with
183       the methods listed below.
184
185   File::Rsync::list
186           $out = $obj->list(@options);
187
188               or
189
190           $out = $obj->list(\@options);
191
192               or
193
194           @out = $obj->list(\@options);
195
196       This is a wrapper for exec called without a destination to get a
197       listing.  It returns the output of stdout like the out function below.
198       When no destination is given rsync returns the equivalent of 'ls -l' or
199       'ls -lr' modified by any include/exclude/filter parameters you specify.
200       This is useful for manual comparison without actual changes to the
201       destination or for comparing against another listing taken at a
202       different point in time.
203
204       (As of rsync version 2.6.4-pre1 this can also be accomplished with the
205       'list-only' option regardless of whether a destination is given.)
206
207   File::Rsync::status
208           $rval = $obj->status;
209
210       Returns the status from last exec call right shifted 8 bits.
211
212   File::Rsync::realstatus
213           $rval = $obj->realstatus;
214
215       Returns the real status from last exec call (not right shifted).
216
217   File::Rsync::err
218           $aref = $obj->err;
219
220       In scalar context this method will return a reference to an array
221       containing all output to stderr from the last exec call, or zero
222       (false) if there was no output.  In an array context it will return an
223       array of all output to stderr or an empty list.  The scalar context can
224       be used to efficiently test for the existance of output.  rsync sends
225       all messages from the remote rsync process and any error messages to
226       stderr.  This method's purpose is to make it easier for you to parse
227       that output for appropriate information.
228
229   File::Rsync::out
230           $aref = $obj->out;
231
232       Similar to the err method, in a scalar context it returns a reference
233       to an array containing all output to stdout from the last exec call, or
234       zero (false) if there was no output.  In an array context it returns an
235       array of all output to stdout or an empty list.  rsync sends all
236       informational messages (verbose option) from the local rsync process to
237       stdout.
238
239   File::Rsync::lastcmd
240           $aref = $obj->lastcmd;
241
242       Returns the actual system command used by the last exec call, or ''
243       before any calls to exec for the object.  This can be useful in the
244       case of an error condition to give a more informative message or for
245       debugging purposes.  In an array context it return an array of args as
246       passed to the system, in a scalar context it returns a space-seperated
247       string.  See getcmd for access to the command before execution.
248

Author

250       Lee Eakin <leakin@dfw.nostrum.com>
251

Credits

253       The following people have contributed ideas, bug fixes, code or helped
254       out by reporting or tracking down bugs in order to improve this module
255       since it's initial release.  See the Changelog for details:
256
257       Greg Ward
258
259       Boris Goldowsky
260
261       James Mello
262
263       Andreas Koenig
264
265       Joe Smith
266
267       Jonathan Pelletier
268
269       Heiko Jansen
270
271       Tong Zhu
272
273       Paul Egan
274
275       Ronald J Kimball
276
277       James CE Johnson
278
279       Bill Uhl
280
281       Peter teStrake
282
283       Harald Flaucher
284
285       Simon Myers
286
287       Gavin Carr
288
289       Petya Kohts
290
291       Neil Hooey
292
293       Erez Schatz
294
295       Max Maischein
296

Inspiration and Assistance

298       Gerard Hickey                             "PGP::Pipe"
299
300       Russ Allbery                              "PGP::Sign"
301
302       Graham Barr                               "Net::*"
303
304       Andrew Tridgell and Paul Mackerras        rsync(1)
305
306       John Steele   <steele@nostrum.com>
307
308       Philip Kizer  <pckizer@nostrum.com>
309
310       Larry Wall                                perl(1)
311
312       I borrowed many clues on wrapping an external program from the PGP
313       modules, and I would not have had such a useful tool to wrap except for
314       the great work of the rsync authors.  Thanks also to Graham Barr, the
315       author of the libnet modules and many others, for looking over this
316       code.  Of course I must mention the other half of my brain, John
317       Steele, and his good friend Philip Kizer for finding rsync and bringing
318       it to my attention.  And I would not have been able to enjoy writing
319       useful tools if not for the creator of the perl language.
320

Copyrights

322             Copyright (c) 1999-2015 Lee Eakin.  All rights reserved.
323
324             This program is free software; you can redistribute it and/or modify
325             it under the same terms as Perl itself.
326
327
328
329perl v5.34.0                      2021-07-22                          Rsync(3)
Impressum