Added retry logic
This commit is contained in:
@@ -34,7 +34,9 @@ my $flags = "rvz";
|
|||||||
my $verbose;
|
my $verbose;
|
||||||
my $help;
|
my $help;
|
||||||
my $dir;
|
my $dir;
|
||||||
|
my $retries = 2;
|
||||||
|
my $tries = 0;
|
||||||
|
my $returncode;
|
||||||
# options
|
# options
|
||||||
my $result = GetOptions ( "path=s" => \$path,
|
my $result = GetOptions ( "path=s" => \$path,
|
||||||
"host=s" => \$host,
|
"host=s" => \$host,
|
||||||
@@ -43,6 +45,7 @@ my $result = GetOptions ( "path=s" => \$path,
|
|||||||
"dest=s" => \$dest,
|
"dest=s" => \$dest,
|
||||||
"flags=s" => \$flags,
|
"flags=s" => \$flags,
|
||||||
"verbose" => \$verbose,
|
"verbose" => \$verbose,
|
||||||
|
"retries" => \$retries,
|
||||||
"help" => \$help);
|
"help" => \$help);
|
||||||
|
|
||||||
|
|
||||||
@@ -58,9 +61,17 @@ sub transfer {
|
|||||||
elsif ($dir && length $host && length $dest && length $user) {
|
elsif ($dir && length $host && length $dest && length $user) {
|
||||||
|
|
||||||
print "Transferring object 1 of 1 \n\n";
|
print "Transferring object 1 of 1 \n\n";
|
||||||
|
$tries = 0
|
||||||
# transfer our directory
|
# transfer our directory
|
||||||
system("rsync", "-$flags", "$dir", "$user\@$host:$dest");
|
while ($tries <= $retries) {
|
||||||
|
|
||||||
|
$returncode = system("rsync", "-$flags", "$dir", "$user\@$host:$dest");
|
||||||
|
if ($returncode == 0) {
|
||||||
|
last;
|
||||||
|
} else {
|
||||||
|
$tries++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
# If we have all the right options set for an infile, begin the copy
|
# If we have all the right options set for an infile, begin the copy
|
||||||
elsif (length $path && length $host && length $user && length $dest) {
|
elsif (length $path && length $host && length $user && length $dest) {
|
||||||
@@ -85,15 +96,31 @@ sub transfer {
|
|||||||
#print "in second while loop\n";
|
#print "in second while loop\n";
|
||||||
$xfernum++;
|
$xfernum++;
|
||||||
chomp $line;
|
chomp $line;
|
||||||
|
$tries = 0;
|
||||||
# actual copy logic
|
# actual copy logic
|
||||||
if (length $verbose) {
|
if (length $verbose) {
|
||||||
#print "in verbose section";
|
while ($tries <= $retries) {
|
||||||
print "\n\nTransferring object $xfernum of $linesnum\n\n";
|
#print "in verbose section";
|
||||||
system("rsync", "-vvv", "-$flags", "$line", "$user\@$host:$dest");
|
print "\n\nTransferring object $xfernum of $linesnum\n\n";
|
||||||
|
$returncode = system("rsync", "-vvv", "-$flags", "$line", "$user\@$host:$dest");
|
||||||
|
if ($returncode == 0) {
|
||||||
|
last;
|
||||||
|
} else {
|
||||||
|
$tries++:
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
#print "in non-verbose section";
|
while ($tries <= $retries) {
|
||||||
print "\n\nTransferring object $xfernum of $linesnum\n\n";
|
#print "in non-verbose section";
|
||||||
system("rsync", "-$flags", "$line", "$user\@$host:$dest");
|
print "\n\nTransferring object $xfernum of $linesnum\n\n";
|
||||||
|
$returncode = system("rsync", "-$flags", "$line", "$user\@$host:$dest");
|
||||||
|
|
||||||
|
if ($returncode == 0) {
|
||||||
|
last;
|
||||||
|
} else {
|
||||||
|
$tries++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close $path;
|
close $path;
|
||||||
@@ -114,6 +141,7 @@ sub transfer {
|
|||||||
--user - User account on the remote system to use
|
--user - User account on the remote system to use
|
||||||
--dest - Destination on the remote system to copy files to
|
--dest - Destination on the remote system to copy files to
|
||||||
--flags - rsync flags to use when copying the files over. Defaults to rvz
|
--flags - rsync flags to use when copying the files over. Defaults to rvz
|
||||||
|
--retries - number of retries on failed rsync (default 2)
|
||||||
--verbose - run rsync with -vvv
|
--verbose - run rsync with -vvv
|
||||||
--help - show this help\n";
|
--help - show this help\n";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user