1 |
#!/usr/bin/perl |
#!/usr/bin/perl |
2 |
|
|
3 |
use strict; |
use strict; |
4 |
#use lib "__INSTALLDIR__/lib"; |
use lib "__INSTALLDIR__/lib"; |
|
use lib "/data/backuppc-agi/lib"; |
|
5 |
|
|
6 |
use DBI; |
use DBI; |
7 |
use BackupPC::Lib; |
use BackupPC::Lib; |
15 |
use Data::Dumper; |
use Data::Dumper; |
16 |
|
|
17 |
my $debug = 0; |
my $debug = 0; |
18 |
|
# set this to 1 to prompt for DVD removal for each selected item. |
19 |
|
my $prompt_for_delete = 0; |
20 |
$|=1; |
$|=1; |
21 |
|
|
22 |
# don't check for user |
# don't check for user |
255 |
symlink $from, $to || skip("can't symlink $from to $to: $!"); |
symlink $from, $to || skip("can't symlink $from to $to: $!"); |
256 |
} |
} |
257 |
|
|
258 |
|
sub delete_dvd($) { |
259 |
|
my $dvd_nr = shift || return; |
260 |
|
|
261 |
|
print "Do you want to delete DVD #$dvd_nr now? [NO/yes]: "; |
262 |
|
my $ok = <STDIN>; |
263 |
|
chomp($ok); |
264 |
|
if (lc($ok) eq 'yes') { |
265 |
|
print "Deleting DVD #$dvd_nr from database...\n"; |
266 |
|
|
267 |
|
$dbh->begin_work; |
268 |
|
|
269 |
|
my $sth_delete_dvd = $dbh->prepare( qq{ |
270 |
|
delete from archive where dvd_nr = ? |
271 |
|
} ); |
272 |
|
$sth_delete_dvd->execute( $dvd_nr ); |
273 |
|
$dbh->do( qq{ |
274 |
|
select setval('dvd_nr', (select max(dvd_nr) from archive), true) |
275 |
|
} ); |
276 |
|
|
277 |
|
# remove files for this DVD |
278 |
|
map { |
279 |
|
print "\tremoving $_\n"; |
280 |
|
unlink($_) || die "can't rm $_: $!"; |
281 |
|
} glob ( "/$iso_dir/$dvd_nr.*" ); |
282 |
|
|
283 |
|
$dbh->commit; |
284 |
|
|
285 |
|
return 1; |
286 |
|
} else { |
287 |
|
return 0; |
288 |
|
} |
289 |
|
} |
290 |
|
|
291 |
my $sth_archive_backup_parts = $dbh->prepare( qq{ |
my $sth_archive_backup_parts = $dbh->prepare( qq{ |
292 |
select |
select |
293 |
archive_backup.backup_id, |
archive_backup.backup_id, |
330 |
|
|
331 |
$sth_archive_backup_parts->execute($dvd_nr); |
$sth_archive_backup_parts->execute($dvd_nr); |
332 |
|
|
333 |
|
if ($sth_archive_backup_parts->rows == 0) { |
334 |
|
warn "ERROR: no backup parts found for $dvd_nr. You should re-create that DVD.\n"; |
335 |
|
delete_dvd( $dvd_nr ); |
336 |
|
} |
337 |
|
|
338 |
|
if ($prompt_for_delete) { |
339 |
|
next if delete_dvd( $dvd_nr ); |
340 |
|
} |
341 |
|
|
342 |
my @volumes; |
my @volumes; |
343 |
my $v; # emtpy volume |
my $v; # emtpy volume |
344 |
my $v_size = 0; |
my $v_size = 0; |
361 |
} |
} |
362 |
push @volumes, $v if ($v); |
push @volumes, $v if ($v); |
363 |
|
|
364 |
|
#warn "# volumes: ",Dumper(\@volumes),"\n"; |
365 |
|
|
366 |
my $volumes = $#volumes + 1; |
my $volumes = $#volumes + 1; |
367 |
my $volume_nr = 1; |
my $volume_nr = 1; |
368 |
|
|
369 |
foreach my $v (@volumes) { |
foreach my $v (@volumes) { |
370 |
|
|
371 |
print Dumper($v); |
#print Dumper($v); |
372 |
|
|
373 |
my $iso_size = 0; |
my $iso_size = 0; |
374 |
my $disk_name = $dvd_nr; |
my $disk_name = $dvd_nr; |
375 |
# suffix added to multi-volume archives |
# suffix added to multi-volume archives |
376 |
my $volume_suffix = $dvd_nr; |
my $volume_suffix = ''; |
377 |
|
|
378 |
if ($volumes > 1) { |
if ($volumes > 1) { |
379 |
$volume_suffix = '_' . $volume_nr; |
$volume_suffix = '_' . $volume_nr; |
414 |
my $rel_path = $tar_file; |
my $rel_path = $tar_file; |
415 |
|
|
416 |
if (-d "$tar_dir/$rel_path") { |
if (-d "$tar_dir/$rel_path") { |
|
$rel_path .= '/' . $p->{part_nr}; |
|
417 |
mkpath("$stage/$rel_path") unless (-d "$stage/$rel_path"); |
mkpath("$stage/$rel_path") unless (-d "$stage/$rel_path"); |
418 |
|
$rel_path .= '/' . $p->{part_nr}; |
419 |
} |
} |
420 |
$rel_path .= '.tar.gz'; |
$rel_path .= '.tar.gz'; |
421 |
|
|
455 |
|
|
456 |
print "Created $iso_file [$iso_size bytes] in ", fmt_time(time() - $t), "\n"; |
print "Created $iso_file [$iso_size bytes] in ", fmt_time(time() - $t), "\n"; |
457 |
|
|
458 |
# FIXME |
rmtree($stage) || warn "can't remove stage directory $stage: $!"; |
|
#rmtree($stage) || warn "can't remove stage directory $stage: $!"; |
|
459 |
|
|
460 |
} else { |
} else { |
461 |
print "ISO $iso_file allready exists\n"; |
print "ISO $iso_file allready exists\n"; |