86 |
my $in_backup_increment; |
my $in_backup_increment; |
87 |
|
|
88 |
|
|
89 |
if ( !getopts("th:n:p:r:s:b:w:vd", \%opts) ) { |
if ( !getopts("th:n:p:r:s:b:w:vdf", \%opts) ) { |
90 |
print STDERR <<EOF; |
print STDERR <<EOF; |
91 |
usage: $0 [options] |
usage: $0 [options] |
92 |
Required options: |
Required options: |
102 |
-p pathAdd new path prefix |
-p pathAdd new path prefix |
103 |
-b BLOCKS BLOCKS x 512 bytes per record (default 20; same as tar) |
-b BLOCKS BLOCKS x 512 bytes per record (default 20; same as tar) |
104 |
-w writeBufSz write buffer size (default 1048576 = 1MB) |
-w writeBufSz write buffer size (default 1048576 = 1MB) |
105 |
|
-f overwrite existing parts |
106 |
-v verbose output |
-v verbose output |
107 |
-d debug output |
-d debug output |
108 |
EOF |
EOF |
199 |
# |
# |
200 |
|
|
201 |
my $max_file_size = $Conf{'MaxArchiveFileSize'} || die "problem with MaxArchiveFileSize parametar"; |
my $max_file_size = $Conf{'MaxArchiveFileSize'} || die "problem with MaxArchiveFileSize parametar"; |
|
$max_file_size *= 1024; |
|
202 |
|
|
203 |
my $tar_dir = $Conf{InstallDir}.'/'.$Conf{GzipTempDir}; |
my $tar_dir = $Conf{InstallDir}.'/'.$Conf{GzipTempDir}; |
204 |
die "problem with $tar_dir, check GzipTempDir in configuration\n" unless (-d $tar_dir && -w $tar_dir); |
die "problem with $tar_dir, check GzipTempDir in configuration\n" unless (-d $tar_dir && -w $tar_dir); |
222 |
my ($backup_id) = $sth->fetchrow_array; |
my ($backup_id) = $sth->fetchrow_array; |
223 |
$sth->finish; |
$sth->finish; |
224 |
|
|
225 |
|
|
226 |
|
# delete exising backup_parts |
227 |
|
my $sth_delete_backup_parts = $dbh->prepare(qq{ |
228 |
|
delete from backup_parts |
229 |
|
where backup_id = ? |
230 |
|
}); |
231 |
|
$sth_delete_backup_parts->execute($backup_id); |
232 |
|
|
233 |
|
|
234 |
print STDERR "backup_id: $backup_id working dir: $tar_dir, max uncompressed size $max_file_size bytes, tar $tar_file\n" if ($opts{d}); |
print STDERR "backup_id: $backup_id working dir: $tar_dir, max uncompressed size $max_file_size bytes, tar $tar_file\n" if ($opts{d}); |
235 |
|
|
236 |
|
if (-e $tar_path_final) { |
237 |
|
if ($opts{f}) { |
238 |
|
rmtree $tar_path_final || die "can't remove $tar_path_final: $!"; |
239 |
|
} else { |
240 |
|
die "$tar_path_final allready exists\n"; |
241 |
|
} |
242 |
|
} |
243 |
|
|
244 |
my $fh; |
my $fh; |
245 |
my $part = 0; |
my $part = 0; |
252 |
if ($fh) { |
if ($fh) { |
253 |
return if ($current_tar_size == 0); |
return if ($current_tar_size == 0); |
254 |
|
|
255 |
print STDERR " $part" if ($opts{v}); |
print STDERR " $part"; |
256 |
|
|
257 |
# |
# |
258 |
# Finish with two null 512 byte headers, |
# Finish with two null 512 byte headers, |
280 |
$items_in_part, |
$items_in_part, |
281 |
); |
); |
282 |
|
|
283 |
$total_increment_size += int( ( $size + 1023 ) / 1024 ) * 1024; |
$total_increment_size += $size; |
284 |
|
|
285 |
if ($arg->{close}) { |
if ($arg->{close}) { |
286 |
|
|
287 |
|
sub move($$) { |
288 |
|
my ($from,$to) = @_; |
289 |
|
print STDERR "# rename $from -> $to\n" if ($opts{d}); |
290 |
|
rename $from, $to || die "can't move $from -> $to: $!\n"; |
291 |
|
} |
292 |
|
|
293 |
if ($part == 1) { |
if ($part == 1) { |
294 |
print STDERR " single"; |
print STDERR " single" if ($opts{v}); |
295 |
rename "${tar_path}/1.tar.gz", "${tar_path_final}/.tar.gz" || die "can't move tar ${tar_path}: $! "; |
move("${tar_path}/1.tar.gz", "${tar_path_final}.tar.gz"); |
296 |
rename "${tar_path}/1.md5", "${tar_path_final}/.md5" || die "can't move md5 ${tar_path}: $! "; |
move("${tar_path}/1.md5", "${tar_path_final}.md5"); |
297 |
|
rmtree $tar_path or die "can't remove temporary dir $tar_path: $!"; |
298 |
} else { |
} else { |
299 |
print STDERR " [last]"; |
print STDERR " [last]" if ($opts{v}); |
300 |
rename "${tar_path}", "${tar_path_final}" || die "can't move tar ${tar_path}: $! "; |
move("${tar_path}", "${tar_path_final}"); |
301 |
} |
} |
302 |
|
|
303 |
$sth_inc_size->execute( |
$sth_inc_size->execute( |
318 |
# if this is first part, create directory |
# if this is first part, create directory |
319 |
|
|
320 |
if ($part == 1) { |
if ($part == 1) { |
321 |
if (-d $tar_path) { |
if (-e $tar_path) { |
322 |
print STDERR "# deleting existing $tar_path\n" if ($opts{d}); |
print STDERR "# deleting existing $tar_path\n" if ($opts{d}); |
323 |
rmtree($tar_path); |
rmtree($tar_path); |
324 |
} |
} |
363 |
if (seedCache($Host, $ShareName, $Num)) { |
if (seedCache($Host, $ShareName, $Num)) { |
364 |
archiveWrite($fh, '/'); |
archiveWrite($fh, '/'); |
365 |
archiveWriteHardLinks($fh); |
archiveWriteHardLinks($fh); |
366 |
|
new_tar_part( close => 1 ); |
367 |
} else { |
} else { |
368 |
print STDERR "NOTE: no files found for $Host:$ShareName, increment $Num\n" if ($opts{v}); |
print STDERR "NOTE: no files found for $Host:$ShareName, increment $Num\n" if ($opts{v}); |
369 |
$no_files = 1; |
# remove temporary files if there are no files |
|
} |
|
|
|
|
|
new_tar_part( close => 1 ); |
|
|
|
|
|
# remove temporary files if there are no files |
|
|
if ($no_files) { |
|
370 |
rmtree($tar_path); |
rmtree($tar_path); |
|
} elsif ($part == 1) { |
|
|
warn "FIXME: if there is only one part move to parent directory and rename"; |
|
371 |
} |
} |
372 |
|
|
373 |
# |
# |