version 1.3, 2011/07/01 12:44:28 |
version 1.7, 2011/12/21 10:19:26 |
|
|
# spool path constants (without leading slash) |
# spool path constants (without leading slash) |
our $SPOOL_ZAYAVKI = "/mnt/archive/archive/wp/zayavki"; |
our $SPOOL_ZAYAVKI = "/mnt/archive/archive/wp/zayavki"; |
our $SPOOL_PROBAS = "/mnt/archive/archive/wp/proba"; |
our $SPOOL_PROBAS = "/mnt/archive/archive/wp/proba"; |
|
our $SPOOL_TT = "/mnt/archive/archive/wp/tt"; |
|
our $SPOOL_JPEG = "/mnt/archive/archive/wp/jpeg"; |
our $SPOOL_TMPDIR = "/mnt/archive/archive/temp"; |
our $SPOOL_TMPDIR = "/mnt/archive/archive/temp"; |
|
|
# temp variables for map table lookup |
# temp variables for map table lookup |
|
|
$remotepaths[$i] =~ s/\/mnt\/maket/\/mnt\/rmt_maket/; |
$remotepaths[$i] =~ s/\/mnt\/maket/\/mnt\/rmt_maket/; |
} |
} |
|
|
if(-e $remotepaths[$i] || -e $remotepaths[$i] . '.rar') |
# if(-e $remotepaths[$i] || -e $remotepaths[$i] . '.rar') |
{ |
# { |
log::error("Remote file $remotepaths[$i] or $remotepaths[$i].rar already exists"); |
# log::error("Remote file $remotepaths[$i] or $remotepaths[$i].rar already exists"); |
db::change_status($dbids[$i], 1); |
# db::change_status($dbids[$i], 1); |
} |
# } |
else |
# else |
{ |
# { |
# In this place we must be sure that local file is ok |
# In this place we must be sure that local file is ok |
if( -e $localpaths[$i] ) |
if( -e $localpaths[$i] ) |
{ |
{ |
|
|
|
|
log::zayavki("compressing '$localpaths[$i]' -> '$spool/$curfile'"); |
log::zayavki("compressing '$localpaths[$i]' -> '$spool/$curfile'"); |
|
|
`/usr/local/bin/rar a -rr10% -ep '$spool/$curfile' '$localpaths[$i]'`; |
`/usr/bin/rar a -rr10% -ep '$spool/$curfile' '$localpaths[$i]'`; |
if( ($? >> 8) == 0) |
if( ($? >> 8) == 0) |
{ |
{ |
# rar exited successfully |
# rar exited successfully |
|
|
log::zayavki("Can not open local file $localpaths[$i]"); |
log::zayavki("Can not open local file $localpaths[$i]"); |
|
|
} |
} |
} |
# } |
|
|
# next iteration of 'while' and increment of $i |
# next iteration of 'while' and increment of $i |
$i++; |
$i++; |
|
|
else |
else |
{ |
{ |
# /mnt/maket/proba/* goes on /mnt/rmt_maket/proba/ |
# /mnt/maket/proba/* goes on /mnt/rmt_maket/proba/ |
substr($remotepaths[$i], 1, 2, 'mnt/rmt_maket'); |
# substr($remotepaths[$i], 1, 2, 'mnt/rmt_maket'); |
|
$remotepaths[$i] =~ s/\/mnt\/maket/\/mnt\/rmt_maket/; |
} |
} |
|
|
if(-e $remotepaths[$i] || -e $remotepaths[$i] . '.rar') |
if(-e $remotepaths[$i] || -e $remotepaths[$i] . '.rar') |
|
|
|
|
log::probas("compressing '$localpaths[$i]' -> '$spool/$curfile'"); |
log::probas("compressing '$localpaths[$i]' -> '$spool/$curfile'"); |
|
|
`/usr/local/bin/rar a -rr10% -ep '$spool/$curfile' '$localpaths[$i]'`; |
`/usr/bin/rar a -rr10% -ep '$spool/$curfile' '$localpaths[$i]'`; |
if( ($? >> 8) == 0) |
if( ($? >> 8) == 0) |
{ |
{ |
# rar exited successfully |
# rar exited successfully |
|
|
log::main("Saved $okay probas on remote host"); |
log::main("Saved $okay probas on remote host"); |
log::probas("<< End transfer process >>"); |
log::probas("<< End transfer process >>"); |
} |
} |
|
|
|
sub tt() |
|
{ |
|
my @dbids; |
|
my @localpaths; |
|
my @remotepaths; |
|
my $dbids_ref; |
|
my $localpaths_ref; |
|
my $i = 0; |
|
my $okay = 0; |
|
|
|
my $size_orig; |
|
|
|
($dbids_ref, $localpaths_ref) = fetch::tt_list(); |
|
|
|
@dbids = @$dbids_ref; |
|
@localpaths = @$localpaths_ref; |
|
log::main("Fetched " . scalar(@localpaths) . " tt from database"); |
|
log::tt("<< Starting transfer process >>"); |
|
|
|
@remotepaths = @localpaths; # clone |
|
|
|
while($localpaths[$i]) |
|
{ |
|
# lookup in table first |
|
chomp( $tmpf = `basename $remotepaths[$i]` ); |
|
chomp( $_ = `dirname $remotepaths[$i]` ); |
|
$tmpd = hash::lookup($_); |
|
if ( $tmpd ne '' ) |
|
{ |
|
$remotepaths[$i] = $tmpd. "/". $tmpf; |
|
} |
|
else |
|
{ |
|
# hardcoded |
|
$remotepaths[$i] =~ s/\/mnt\/maket/\/mnt\/rmt_maket/; |
|
} |
|
|
|
if(-e $remotepaths[$i]) |
|
{ |
|
log::error("Remote file $remotefile[$i] already exists"); |
|
db::change_status($dbids[$i], 1); |
|
} |
|
else |
|
{ |
|
if( -e $localpaths[$i] ) |
|
{ |
|
fileops::checkdir($remotepaths[$i]); |
|
# set $size_orig |
|
$size_orig = -s "$localpaths[$i]"; |
|
|
|
log::tt("transferring $localpaths[$i] -> $remotepaths[$i]"); |
|
if( system("cp '$localpaths[$i]' '$remotepaths[$i]'") == 0 ) |
|
{ |
|
log::tt("saved $localpaths[$i] -> $remotepaths[$i] [size_orig=$size_orig]"); |
|
# update database |
|
db::change_status($dbids[$i], 1); |
|
db::write_size_orig($dbids[$i], $size_orig); |
|
|
|
# |
|
# WE SHOULD NOT FILL ux_rpath FIELD FOR tpp-types |
|
# |
|
# XXX Please explain me why? |
|
# |
|
# db::write_ux_rpath($dbids[$i], "$remotepaths[$i]"); |
|
|
|
$okay++; |
|
|
|
} |
|
else |
|
{ |
|
# error in the copy process |
|
log::tt("error in copy process (see error log)"); |
|
log::error("error in copy process: $?"); |
|
} |
|
} |
|
else |
|
{ |
|
# error, local file doesn't exists |
|
log::error("Can not open local file $localpaths[$i]"); |
|
log::tt("Can not open local file $localpaths[$i]"); |
|
} |
|
} |
|
|
|
# next iteration of 'while' and increment of $i |
|
$i++; |
|
} |
|
|
|
log::main("Saved $okay tt on remote host"); |
|
log::tt("<< End transfer process >>"); |
|
} |
|
|
|
|
|
sub jpeg() |
|
{ |
|
my @dbids; |
|
my @localpaths; |
|
my @remotepaths; |
|
my $dbids_ref; |
|
my $localpaths_ref; |
|
my $i = 0; |
|
my $okay = 0; |
|
|
|
my $size_orig; |
|
|
|
($dbids_ref, $localpaths_ref) = fetch::jpeg_list(); |
|
|
|
@dbids = @$dbids_ref; |
|
@localpaths = @$localpaths_ref; |
|
log::main("Fetched " . scalar(@localpaths) . " jpeg from database"); |
|
log::jpeg("<< Starting transfer process >>"); |
|
|
|
@remotepaths = @localpaths; # clone |
|
|
|
while($localpaths[$i]) |
|
{ |
|
# lookup in table first |
|
chomp( $tmpf = `basename $remotepaths[$i]` ); |
|
chomp( $_ = `dirname $remotepaths[$i]` ); |
|
$tmpd = hash::lookup($_); |
|
if ( $tmpd ne '' ) |
|
{ |
|
$remotepaths[$i] = $tmpd. "/". $tmpf; |
|
} |
|
else |
|
{ |
|
# hardcoded |
|
$remotepaths[$i] =~ s/\/mnt\/maket/\/mnt\/rmt_maket/; |
|
} |
|
|
|
if(-e $remotepaths[$i]) |
|
{ |
|
log::error("Remote file $remotefile[$i] already exists"); |
|
db::change_status($dbids[$i], 1); |
|
} |
|
else |
|
{ |
|
if( -e $localpaths[$i] ) |
|
{ |
|
fileops::checkdir($remotepaths[$i]); |
|
# set $size_orig |
|
$size_orig = -s "$localpaths[$i]"; |
|
|
|
log::tt("transferring $localpaths[$i] -> $remotepaths[$i]"); |
|
if( system("cp '$localpaths[$i]' '$remotepaths[$i]'") == 0 ) |
|
{ |
|
log::jpeg("saved $localpaths[$i] -> $remotepaths[$i] [size_orig=$size_orig]"); |
|
# update database |
|
db::change_status($dbids[$i], 1); |
|
db::write_size_orig($dbids[$i], $size_orig); |
|
|
|
|
|
$okay++; |
|
|
|
} |
|
else |
|
{ |
|
# error in the copy process |
|
log::jpeg("error in copy process (see error log)"); |
|
log::error("error in copy process: $?"); |
|
} |
|
} |
|
else |
|
{ |
|
# error, local file doesn't exists |
|
log::error("Can not open local file $localpaths[$i]"); |
|
log::jpeg("Can not open local file $localpaths[$i]"); |
|
} |
|
} |
|
|
|
# next iteration of 'while' and increment of $i |
|
$i++; |
|
} |
|
|
|
log::main("Saved $okay jpeg on remote host"); |
|
log::jpeg("<< End transfer process >>"); |
|
} |
|
|
return(1); |
return(1); |