Movatterモバイル変換


[0]ホーム

URL:


 / 
File-Rsync-0.49
River stage one • 5 direct dependents • 7 total dependents
/File::Rsync

NAME

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

SYNOPSIS

use File::Rsync;$obj = File::Rsync->new(    archive      => 1,    compress     => 1,    rsh          => '/usr/local/bin/ssh',    'rsync-path' => '/usr/local/bin/rsync');$obj->exec( src => 'localdir', dest => 'rhost:remotedir' )    or warn "rsync failed\n";

DESCRIPTION

Perl Convenience wrapper for the rsync(1) program. Written forrsync-2.3.2 and updated forrsync-3.1.1 but should perform properly with most recent versions.

File::Rsync::new

$obj = new File::Rsync;    or$obj = File::Rsync->new;    or$obj = File::Rsync->new(@options);

Create aFile::Rsync object. Any options passed at creation are stored in the object as defaults for all futureexec calls on that object. Options may be passed in the style of a hash (key/value pairs) and are the same as the long options inrsync(1) without the leading double-hyphen. Any leading single or double-hyphens are removed, and you may use underscore in place of hyphens in option names to simplify quoting and avoid possible equation parsing (subtraction).

Although options are key/value pairs, as of version 0.46 the order is now preserved. Passing a hash reference is still supported for backwards compatibility, but is deprecated as order cannot be preserved for this case.

An additional option ofpath-to-rsync also exists which can be used to override the using PATH environemt variable to find the rsync command binary, andmoddebug which causes the module methods to print some debugging information to STDERR.

There are also 2 options to wrap the source and/or destination paths in double-quotes: these arequote-src andquote-dst, which may be useful in protecting the paths from shell expansion (particularly useful for paths containing spaces). This wraps all source and/or destination paths in double-quotes to limit remote shell expansion. It is similar but not necessarily the same result as theprotect-args option in rsync itself.

Theoutfun anderrfun options take a function reference, called once for each line of output from thersync program with the output line passed in as the first argument, the second arg is either 'out' or 'err' depending on the source. This makes it possible to use the same function for both and still determine where the output came from.

If options are passed as a hash reference (deprecated), theexclude needs an array reference as it's value since there cannot be duplicate keys in a hash. Since order cannot be preserved in a hash, this module currently limits the use ofexclude orinclude together. They can be mixed together if options are in the form of a list or array ref.

Use the '+ ' or '- ' prefix trick to put includes in anexclude array, or to put excludes in aninclude array (seersync(1) for details).

Include/exclude options form an ordered list. The order must be retained for proper execution. There are alsosource anddest keys. The keysrc is also accepted as an equivalent tosource, anddst ordestination may be used as equivalents todest. Thesource option may take a scalar or an array reference. If the source is the local system then multiplesource paths are allowed. In this case an array reference should be used. There is also a method for passing multiple source paths to a remote system. This method may be triggered in this module by passing the remote hostname to thesrchost key and passing an array reference to thesource key. If the source host is being accessed via an Rsync server, the remote hostname should have a single trailing colon on the name. When rsync is called, thesrchost value and the values in thesource array will be joined with a colon resulting in the double-colon required for server access. Thedest key only takes a scalar sincersync only accepts a single destination path.

Version 2.6.0 ofrsync(1) provides a newfiles-from option along with a few other supporting options (from0,no-relative, andno-implied-dirs). To support this wonderful new option at the level it deserves, this module now has an additional parameter. As of version 0.46 the value offiles-from may be an array reference. The contents of the array are passed tofiles-from the same as the below method usinginfun but implemented inside the module.

Iffiles-from is set to '-' (meaning read from stdin) you can defineinfun to be a reference to a function that prints your file list to the default file handle. The output from the function is attached to stdin of the rsync call during exec. Ifinfun is defined it will be called regardless of the value offiles-from, so it can provide any data expected on stdin, but keep in mind that stdin will not be attached to a tty so it is not very useful for sending passwords (see thersync(1) andssh(1) man pages for ways to handle authentication). Thersync(1) man page has a more complete description offiles-from. Also seeFile::Find for ideas to use withfiles-from andinfun.

Theinfun option may also be used with theinclude-from orexclude-from options, but this is generally more clumsy than using theinclude orexclude arrays.

Version 2.6.3 ofrsync(1) provides new optionspartial-dir,checksum-seed,keep-dirlinks,inplace,ipv4, andipv6. Version 2.6.4 ofrsync(1) provides new optionsdel,delete-beforedelete-during,delay-updates,dirs,filter,fuzzy,itemize-changes,list-only,omit-dir-times,remove-sent-files,max-size, andprotocol.

Version 0.38 of this module also added support for theacls option that is not part ofrsync(1) unless the patch has been applied, but people do use it. It also includes a newliteral option that takes an array reference similar toinclude,exclude, andfilter. Any arguments in the array are passed as literal arguments to rsync, and are passed first. They should have the proper single or double hyphen prefixes and the elements should be split up the way you want them passed to exec. The purpose of this option is to allow the use of arbitrary options added by patches, and/or to allow the use of new options in rsync without needing an imediate update to the module in addtition torsync(1) itself.

File::Rsync::defopts

$obj->defopts(@options);    or$obj->defopts(\@options);

Set default options for future exec calls for the object. Seersync(1) for a complete list of valid options. This is really the internal method thatnew calls but you can use it too. Theverbose andquiet options to rsync are actually counters. When assigning the perl hash-style options you may specify the counter value directly and the module will pass the proper number of options to rsync.

File::Rsync::getcmd

my $cmd = $obj->getcmd(@options);    ormy $cmd = $obj->getcmd(\@options);    ormy ($cmd, $infun, $outfun, $errfun, $debug) = $obj->getcmd(\@options);

getcmd returns a reference to an array containing the real rsync command that would be called if the exec function were called. The last example above includes a reference to the optional stdin function, stdout function, stderr function, and the debug setting. This is the form used by theexec method to get the extra parameters it needs to do its job. The function is exposed to allow a user-defined exec function to be used, or for debugging purposes.

File::Rsync::exec

$obj->exec(@options) or warn "rsync failed\n";    or$obj->exec(\@options) or warn "rsync failed\n";

This is the method that does the real work. Any options passed to this routine are appended to any pre-set options and are not saved. They effect the current execution ofrsync only. In the case of conflicts, the options passed directly toexec take precedence. It returns1 if the return status was zero (or true), if thersync return status was non-zero it returns0 and stores the return status. You can examine the return status fromrsync and any output to stdout and stderr with the methods listed below.

File::Rsync::list

$out = $obj->list(@options);    or$out = $obj->list(\@options);    or@out = $obj->list(\@options);

This is a wrapper forexec called without a destination to get a listing. It returns the output of stdout like theout function below. When no destination is given rsync returns the equivalent of 'ls -l' or 'ls -lr' modified by any include/exclude/filter parameters you specify. This is useful for manual comparison without actual changes to the destination or for comparing against another listing taken at a different point in time.

(As of rsync version 2.6.4-pre1 this can also be accomplished with the 'list-only' option regardless of whether a destination is given.)

File::Rsync::status

$rval = $obj->status;

Returns the status from lastexec call right shifted 8 bits.

File::Rsync::realstatus

$rval = $obj->realstatus;

Returns the real status from lastexec call (not right shifted).

File::Rsync::err

$aref = $obj->err;

In scalar context this method will return a reference to an array containing all output to stderr from the lastexec call, or zero (false) if there was no output. In an array context it will return an array of all output to stderr or an empty list. The scalar context can be used to efficiently test for the existance of output.rsync sends all messages from the remotersync process and any error messages to stderr. This method's purpose is to make it easier for you to parse that output for appropriate information.

File::Rsync::out

$aref = $obj->out;

Similar to theerr method, in a scalar context it returns a reference to an array containing all output to stdout from the lastexec call, or zero (false) if there was no output. In an array context it returns an array of all output to stdout or an empty list.rsync sends all informational messages (verbose option) from the localrsync process to stdout.

File::Rsync::lastcmd

$aref = $obj->lastcmd;

Returns the actual system command used by the lastexec call, or '' before any calls toexec for the object. This can be useful in the case of an error condition to give a more informative message or for debugging purposes. In an array context it return an array of args as passed to the system, in a scalar context it returns a space-seperated string. Seegetcmd for access to the command before execution.

Author

Lee Eakin <leakin@dfw.nostrum.com>

Credits

The following people have contributed ideas, bug fixes, code or helped out by reporting or tracking down bugs in order to improve this module since it's initial release. See the Changelog for details:

Greg Ward

Boris Goldowsky

James Mello

Andreas Koenig

Joe Smith

Jonathan Pelletier

Heiko Jansen

Tong Zhu

Paul Egan

Ronald J Kimball

James CE Johnson

Bill Uhl

Peter teStrake

Harald Flaucher

Simon Myers

Gavin Carr

Petya Kohts

Neil Hooey

Erez Schatz

Max Maischein

Inspiration and Assistance

Gerard HickeyPGP::Pipe

Russ AllberyPGP::Sign

Graham BarrNet::*

Andrew Tridgell and Paul Mackerras rsync(1)

John Steele <steele@nostrum.com>

Philip Kizer <pckizer@nostrum.com>

Larry Wall perl(1)

I borrowed many clues on wrapping an external program from the PGP modules, and I would not have had such a useful tool to wrap except for the great work of thersync authors. Thanks also to Graham Barr, the author of the libnet modules and many others, for looking over this code. Of course I must mention the other half of my brain, John Steele, and his good friend Philip Kizer for findingrsync and bringing it to my attention. And I would not have been able to enjoy writing useful tools if not for the creator of theperl language.

Copyrights

Copyright (c) 1999-2015 Lee Eakin.  All rights reserved.This program is free software; you can redistribute it and/or modifyit under the same terms as Perl itself.

Module Install Instructions

To install File::Rsync, copy and paste the appropriate command in to your terminal.

cpanm

cpanm File::Rsync

CPAN shell

perl -MCPAN -e shellinstall File::Rsync

For more information on module installation, please visitthe detailed CPAN module installation guide.

Keyboard Shortcuts

Global
sFocus search bar
?Bring up this help dialog
GitHub
gpGo to pull requests
gigo to github issues (only if github is preferred repository)
POD
gaGo to author
gcGo to changes
giGo to issues
gdGo to dist
grGo to repository/SCM
gsGo to source
gbGo to file browse
Search terms
module: (e.g.module:Plugin)
distribution: (e.g.distribution:Dancer auth)
author: (e.g.author:SONGMU Redis)
version: (e.g.version:1.00)

[8]ページ先頭

©2009-2025 Movatter.jp