rei has asked for the wisdom of the Perl Monks concerning the following question:

Hello !

I have a problem with the File::Rsync lib.

I try to transfer some log files, matching patterns from a remote /var/log, to my local machine.

Part of my script:

my %rsyncOptions = ( 'recursive' => '1', 'times' => '1', 'ignore-existing' => '1', 'rsh' => '"/usr/bin/ssh"', 'verbose' => '1' ); my $pattern = "\"+ mail.log*\""; push(@includePatterns, $pattern); push(@includePatterns, '"- **"'); #exclude everything else $rsyncOptions{'include'} = \@includePatterns; my $rsync = File::Rsync->new(\%rsyncOptions); my ($cmd, $infun, $outfun, $errfun, $debug) =$rsync->getcmd(%rsyncOpti +ons, 'src' => $sourceDir, 'dest' => $destDir); print "Cmd: " . join(" ", @$cmd) . "\n"; my $sourceDir = "/var/log/"; my $destDir = "log/mail/"; $rsync->exec( { src => $sourceDir, dest => $destDir } );

The getcmd sub give me the following line:

/usr/bin/rsync --ignore-existing --recursive --times --rsh="/usr/bin/ssh" --verbose --include="+ mail.log*" --include="- *" user@XXX.XXX.XXX.XXX:/var/log/ log/mail/

So, connection, user, ssh key, dirs and files permissions are ok;

The problem is that the script transfers all my /var/log/ files... But, that's not all: I've tried to execute the command gave by the getcmd, and it works ! rsync just download the mail.log* files...

an idea ?

Replies are listed 'Best First'.
Re: File::Rsync match pattern
by salva (Canon) on Jul 20, 2011 at 15:24 UTC
    I guess the problem is the double quoting of the include/exclude patterns.

    Anyway, you can also try using Net::OpenSSH instead of File::Rsync:

    use Net::OpenSSH; my $ssh = Net::OpenSSH->new($host); $ssh->rsync_get({glob => 1, verbose => 1, times => 1}, "/var/log/mail.log*", "log/mail");

      Thank you very much for the tip ! I will try it and I feedback to you

        You can also try running your script with strace (or similar) in order to see the rsync invocation done by File::Rsync.