MMM::Sync::Rsync - MMM::Sync::Rsync documentation


mmm documentation Contained in the mmm distribution.

Index


Code Index:

NAME

Top

MMM::Sync::Rsync

AUTHOR

Top

Olivier Thauvin <nanardon@nanardon.zarb.org>

COPYRIGHT AND LICENSE

Top


mmm documentation Contained in the mmm distribution.
package MMM::Sync::Rsync;

use strict;
use warnings;
our @ISA = qw(MMM::Sync);

sub buildcmd {
    my ($self) = @_;

    my @command = ('rsync');

    if ($self->{options}{rsync_defaults}) {
        push(@command, split(/ +/, $self->{options}{rsync_defaults}));
    } else { push(@command, '-aH'); }
    
    if ($self->{options}{rsync_opts}) {
        push(@command, split(/ +/, $self->{options}{rsync_opts}));
    }

    if ($self->{options}{exclude}) {
        foreach ( map { split( m/ /, $_ ) } $self->{options}{exclude} ) {
            push( @command, '--exclude', $_ );
        }
    }

    my %mo = (
        partialdir => 'partial-dir',
        tempdir => 'temp-dir',
    );
    push(@command, map {
        $self->{options}{$_} 
            ? '--' . ($mo{$_} || $_)
            : ()
        } (qw(delete-after delete delete-excluded)));
    push(@command, map {
        $self->{options}{$_}
            ? ('--' . ($mo{$_} || $_), $self->{options}{$_})
            : ()
        } (qw(partialdir tempdir))
    );
    push(@command, '--partial') if ($self->{options}{partialdir});

    push(@command, '-e', 'ssh') if ($self->{options}{use_ssh});

    push( @command,
        $self->{source},
        $self->{dest}
    );

    $ENV{RSYNC_PASSWORD} = $self->{options}{password} || '-'; # Avoid passwd prompt

    return @command;
}

sub _analyze_output {
    my ($self, $src, $line) = @_;
    if ($src eq 'STDERR') {
        return $line;
    } elsif ($line =~ /vanished|error|permission denied/i) {
        return $line
    } else {
        return;
    }
}

sub _exitcode {
    my ($self, $exitstatus) = @_;

    return 0 if (! $exitstatus);
    # Handle system exit code
    # if (grep { ($? & 127) == $_ } ()) {
    # }
    
    # Rsync exit code - no way to retry
    if (
        grep { ( $exitstatus ) == $_ } (
            1,    # Syntax or usage error
            2,    # Protocol incompatibility
            20,    # SIGUSR1 ou SIGINT reçu
        )
      )
    {
        return ( 2 );
    }

    # This is not a failure, but normal state
    if (
        grep { ( $exitstatus ) == $_ } (
            25,    # The --max-delete limit stopped deletions
        )
      )
    {
        return ( 0 );
    }
    return ( 1 );
}

1;

__END__