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 |
160 |
my $sth_inc_size = $dbh->prepare(qq{ |
my $sth_inc_size = $dbh->prepare(qq{ |
161 |
update backups set |
update backups set |
162 |
inc_size = ?, |
inc_size = ?, |
|
parts = ?, |
|
163 |
inc_deleted = false |
inc_deleted = false |
164 |
where id = ? |
where id = ? |
165 |
}); |
}); |
198 |
# |
# |
199 |
|
|
200 |
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; |
|
201 |
|
|
202 |
my $tar_dir = $Conf{InstallDir}.'/'.$Conf{GzipTempDir}; |
my $tar_dir = $Conf{InstallDir}.'/'.$Conf{GzipTempDir}; |
203 |
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); |
221 |
my ($backup_id) = $sth->fetchrow_array; |
my ($backup_id) = $sth->fetchrow_array; |
222 |
$sth->finish; |
$sth->finish; |
223 |
|
|
224 |
|
|
225 |
|
# delete exising backup_parts |
226 |
|
my $sth_delete_backup_parts = $dbh->prepare(qq{ |
227 |
|
delete from backup_parts |
228 |
|
where backup_id = ? |
229 |
|
}); |
230 |
|
$sth_delete_backup_parts->execute($backup_id); |
231 |
|
|
232 |
|
|
233 |
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}); |
234 |
|
|
235 |
|
if (-e $tar_path_final) { |
236 |
|
if ($opts{f}) { |
237 |
|
rmtree $tar_path_final || die "can't remove $tar_path_final: $!"; |
238 |
|
} else { |
239 |
|
die "$tar_path_final allready exists\n"; |
240 |
|
} |
241 |
|
} |
242 |
|
|
243 |
my $fh; |
my $fh; |
244 |
my $part = 0; |
my $part = 0; |
251 |
if ($fh) { |
if ($fh) { |
252 |
return if ($current_tar_size == 0); |
return if ($current_tar_size == 0); |
253 |
|
|
254 |
print STDERR " $part" if ($opts{v}); |
print STDERR "\n\t+ $part:"; |
255 |
|
|
256 |
# |
# |
257 |
# Finish with two null 512 byte headers, |
# Finish with two null 512 byte headers, |
270 |
|
|
271 |
my $size = (stat( $file . '.tar.gz' ))[7] || die "can't stat ${file}.tar.gz"; |
my $size = (stat( $file . '.tar.gz' ))[7] || die "can't stat ${file}.tar.gz"; |
272 |
|
|
273 |
|
print "$file, $size bytes, $items_in_part items"; |
274 |
|
|
275 |
$sth_backup_parts->execute( |
$sth_backup_parts->execute( |
276 |
$backup_id, |
$backup_id, |
277 |
$part, |
$part, |
281 |
$items_in_part, |
$items_in_part, |
282 |
); |
); |
283 |
|
|
284 |
$total_increment_size += int( ( $size + 1023 ) / 1024 ) * 1024; |
$total_increment_size += $size; |
285 |
|
|
286 |
if ($arg->{close}) { |
if ($arg->{close}) { |
287 |
|
|
288 |
|
sub move($$) { |
289 |
|
my ($from,$to) = @_; |
290 |
|
print STDERR "# rename $from -> $to\n" if ($opts{d}); |
291 |
|
rename $from, $to || die "can't move $from -> $to: $!\n"; |
292 |
|
} |
293 |
|
|
294 |
if ($part == 1) { |
if ($part == 1) { |
295 |
print STDERR " single"; |
print STDERR " single" if ($opts{v}); |
296 |
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"); |
297 |
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"); |
298 |
|
rmtree $tar_path or die "can't remove temporary dir $tar_path: $!"; |
299 |
} else { |
} else { |
300 |
print STDERR " [last]"; |
print STDERR " [last]" if ($opts{v}); |
301 |
rename "${tar_path}", "${tar_path_final}" || die "can't move tar ${tar_path}: $! "; |
move("${tar_path}", "${tar_path_final}"); |
302 |
|
|
303 |
|
# if this archive was single part, remove it |
304 |
|
foreach my $suffix (qw/.tar.gz .md5/) { |
305 |
|
my $path = $tar_path_final . $suffix; |
306 |
|
unlink $path if (-e $path); |
307 |
|
} |
308 |
} |
} |
309 |
|
|
310 |
$sth_inc_size->execute( |
$sth_inc_size->execute( |
311 |
$total_increment_size, |
$total_increment_size, |
|
$part, |
|
312 |
$backup_id |
$backup_id |
313 |
); |
); |
314 |
|
|
315 |
print STDERR ", $total_increment_size bytes\n" if ($opts{v}); |
print "\n\ttotal $total_increment_size bytes"; |
316 |
|
|
317 |
return; |
return; |
318 |
} |
} |
324 |
# if this is first part, create directory |
# if this is first part, create directory |
325 |
|
|
326 |
if ($part == 1) { |
if ($part == 1) { |
327 |
if (-d $tar_path) { |
if (-e $tar_path) { |
328 |
print STDERR "# deleting existing $tar_path\n" if ($opts{d}); |
print STDERR "# deleting existing $tar_path\n" if ($opts{d}); |
329 |
rmtree($tar_path); |
rmtree($tar_path); |
330 |
} |
} |
331 |
mkdir($tar_path) || die "can't create directory $tar_path: $!"; |
mkdir($tar_path) || die "can't create directory $tar_path: $!"; |
332 |
|
|
333 |
sub abort_cleanup { |
sub abort_cleanup { |
334 |
print STDERR "ABORTED: cleanup temp dir"; |
print STDERR "ABORTED: cleanup temp dir "; |
335 |
rmtree($tar_path); |
rmtree($tar_path); |
336 |
$dbh->rollback; |
$dbh->rollback; |
337 |
exit 1; |
exit 1; |
369 |
if (seedCache($Host, $ShareName, $Num)) { |
if (seedCache($Host, $ShareName, $Num)) { |
370 |
archiveWrite($fh, '/'); |
archiveWrite($fh, '/'); |
371 |
archiveWriteHardLinks($fh); |
archiveWriteHardLinks($fh); |
372 |
|
new_tar_part( close => 1 ); |
373 |
} else { |
} else { |
374 |
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}); |
375 |
$no_files = 1; |
# remove temporary files if there are no files |
376 |
} |
rmtree($tar_path); |
377 |
|
|
378 |
new_tar_part( close => 1 ); |
my $sth = $dbh->prepare(qq{ |
379 |
|
update backups set inc_size = 0, inc_deleted = true |
380 |
|
where id = ? |
381 |
|
}); |
382 |
|
$sth->execute($backup_id); |
383 |
|
|
|
# remove temporary files if there are no files |
|
|
if ($no_files) { |
|
|
rmtree($tar_path); |
|
|
} elsif ($part == 1) { |
|
|
warn "FIXME: if there is only one part move to parent directory and rename"; |
|
384 |
} |
} |
385 |
|
|
386 |
# |
# |