MYDan
view release on metacpan or search on metacpan
dan/tools/grsync view on Meta::CPAN
#!/usr/bin/env perl
=head1 SYNOPSIS
$0 [--src src-range(default `hostname`)] --dst dst-range --sp src-path [--dp dst-path] \
[--timeout seconds(default 300)]
[--max number(default 128)]
[--retry number(default 2)]
[--gave number(default 3)]
[--user username(default `id -un`)]
[--sudo user1 ]
[--chown root]
[--chmod 777]
[--cc]
[--delete]
-1 Forces grsync to try protocol version 1
-2 Forces grsync to try protocol version 2
-3 Forces grsync to try protocol version 3
-4 Forces grsync to try protocol version 4
--sp /path/file --dp /path/foo/newfile
--sp /path/file --dp /path/foo/
--sp /path/ --dp /path/foo/
--sp /path/foo* --dp /path/foo/
--sp '/path/file1;/path/file2' --dp /path/foo/
[--immediately]
[--addr 10.10.10.10]
[--listen 9999]
=cut
use strict;
use warnings;
use threads;
use threads::shared;
use Sys::Hostname;
use MYDan::Node;
use MYDan::Agent::GrsyncM;
use MYDan::Util::OptConf;
use AE;
use AnyEvent;
use AnyEvent::Socket;
use AnyEvent::Handle;
use Data::UUID;
use MYDan::Util::Progress;
use MYDan::Util::Percent;
$| ++;
@MYDan::Util::OptConf::CONF = qw( pass_through no_ignore_case );
my $option = MYDan::Util::OptConf->load();
my %o = $option->set( retry => 2, timeout => 300, gave => 3, addr => 0 )
->get( qw( src=s dst=s sp=s dp=s timeout=i max=i retry=i nice=i user=s sudo=s gave=i chown=s chmod=s cc delete 1 2 3 4 immediately addr=s listen=i ) )
->dump();
$o{delete $o{ProtocolVersion}} = 1 unless $o{ProtocolVersion} && $o{ProtocolVersion} =~ /^\d$/ && grep{ $o{$_} }1..3;
$option->assert( qw( dst sp ) );
my ( $ptime, $pcb, $p ) = ( 0 );
my %pp:shared;
if( $o{immediately} )
{
$p = MYDan::Util::Progress->new();
my ( %percent, %pcb );
$pcb = sub
{
my ( $info, $node, $pp ) = @_;
return unless defined $info;
$node ||= 'localhost';
my $percb = sub{ $pcb{$node} = shift };
unless( $percent{$node} )
{
if( $info =~ /^\d+$/ )
{
my $x = $pp ? "2$pp" : '';
$percent{$node} = MYDan::Util::Percent->new(
$info, "Dump$x." .hostname. " ..", $percb );
return;
}
else
{
$percent{$node} = MYDan::Util::Percent->new(
undef, 'sync ..', $percb );
}
}
map{
if( $_ =~ /^\d+$/ )
{
$percent{$node}->add( $_ )->print()
}
else
{
$pcb{$node} = $_;
}
}split "\n", $info;
$pp{$node} = $pcb{$node};
my $time = time;
if( $time ne $ptime )
{
$p->load( %pp );
$p->print();
$ptime = $time;
}
};
my $listen = $o{listen};
unless( $listen )
( run in 1.080 second using v1.01-cache-2.11-cpan-71847e10f99 )