Monks
The docs say to use an array ref to pass the exclude list,
but I've tried this and it ignores the exclude list.
#!/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"; } } }
The code above rsyncs everything in the src path, regardless of the exclude list.
Can't seem to find an example via google or Supersearch.
Thx for any solutions
Chris

Readmore tags added by GrandFather


In reply to How do I use the exclude option in the File::Rsync module? by chrism01

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.