chrism01 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use locale; # Ensure correct charset for eg 'uc()' use File::Rsync; # Perl rsync interface use strict; # enforce declarations # Ctrl rsync processes rsync_ctrl(); #********************************************************************* +********* sub rsync_ctrl { my ( $rsync, # rsync object @rsync_data, # params as a hash ref perl array element $rs_rec, # 1 element of above array @exclude, # array of dirs to exclude $error_msg, # if any @error # rsync error text ); @exclude = ("/home/c/d/rsync_code/rsync_src/excl_1", "/home/c/d/rs +ync_code/rsync_src/excl_2"); # Declare SIG ALARM sub in case of eg unknown user # will cause rsync to hang; # more accurately ssh hangs, asking for passwd $SIG{ALRM} = sub { die "timeout"}; # Create rsync object + set options $rsync = File::Rsync->new({ 'path-to-rsync' => '/usr/bin/rsync', src => '/home/c/d/rsync_code/rsync_src/', dest => 'c@g.a.c.u:/home/c/rsync_dest/', exclude => \@exclude }); $rsync->defopts({ archive => 1, verbose => 1, recursive => 1, owner => 1, perms => 1, group => 1, times => 1, debug => 0, compress => 1, 'dry-run' => 0 }); # Eval the rsync call, so we can use SIG ALARM eval { # Set timeout (seconds), clear error msg + go for it alarm(10); $error_msg = ""; $rsync->exec; @error = $rsync->err; # collect possible errors alarm(0); # clear alarm }; # Check non-alarm error if( scalar(@error) > 0 ) { # Collect error info (inc cmd used) & log/email it $error_msg .= $rsync->lastcmd."\n"; $error_msg .= "\tErr: @error\n"; print "$error_msg"; } # Check if SIG ALARM got called if( $@ ) { if( $@ =~ /timeout/ ) { # Log timeout $error_msg = "Rsync Timeout for $rs_rec->{'src'} ". "$rs_rec->{'dest'}\n"; $error_msg .= $rsync->lastcmd."\n"; print "$error_msg"; } else { # Unexpected error alarm(0); $error_msg = "Unexpected rsync ALARM error $@ for ". "$rs_rec->{'src'} $rs_rec->{'dest'}\n" +; $error_msg .= $rsync->lastcmd."\n"; print "$error_msg"; } } }
Readmore tags added by GrandFather
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I use the exclude option in the File::Rsync module?
by planetscape (Chancellor) on Oct 26, 2005 at 06:50 UTC | |
| |
| A reply falls below the community's threshold of quality. You may see it by logging in. |