9 |
use Time::HiRes qw/time/; |
use Time::HiRes qw/time/; |
10 |
use POSIX qw/strftime/; |
use POSIX qw/strftime/; |
11 |
use Term::Menus; |
use Term::Menus; |
12 |
|
use File::Which; |
13 |
|
|
14 |
use Data::Dumper; |
use Data::Dumper; |
15 |
|
|
16 |
my $debug = 0; |
my $debug = 0; |
17 |
$|=1; |
$|=1; |
18 |
|
|
19 |
|
my $cdr_opts = 'dev=/dev/hdc blank=fast -v -eject'; |
20 |
|
|
21 |
|
my $bin; |
22 |
|
foreach my $c (qw/mkisofs cdrecord eject/) { |
23 |
|
$bin->{$c} = which($c) || die "$0 needs $c, install it\n"; |
24 |
|
} |
25 |
|
|
26 |
my $start_t = time(); |
my $start_t = time(); |
27 |
|
|
28 |
my $t_fmt = '%Y-%m-%d %H:%M:%S'; |
my $t_fmt = '%Y-%m-%d %H:%M:%S'; |
105 |
|
|
106 |
my $row_h; |
my $row_h; |
107 |
foreach my $hide (qw/id note/) { |
foreach my $hide (qw/id note/) { |
108 |
$row_h->{$hide} = $row->{$hide} || die "no $hide"; |
$row_h->{$hide} = $row->{$hide} || ''; |
109 |
delete $row->{$hide}; |
delete $row->{$hide}; |
110 |
} |
} |
111 |
|
|
228 |
archive_id, |
archive_id, |
229 |
hosts.name as host, |
hosts.name as host, |
230 |
shares.name as share, |
shares.name as share, |
231 |
backups.num as num |
backups.num as num, |
232 |
|
backups.parts as parts |
233 |
from archive_backup |
from archive_backup |
234 |
join archive on archive_id = archive.id |
join archive on archive_id = archive.id |
235 |
join backups on backup_id = backups.id |
join backups on backup_id = backups.id |
240 |
|
|
241 |
my $sth_archive_burned = $dbh->prepare( qq{ |
my $sth_archive_burned = $dbh->prepare( qq{ |
242 |
insert into archive_burned |
insert into archive_burned |
243 |
(archive_id, iso_size) |
(archive_id, iso_size, part) |
244 |
values ( (select id from archive where dvd_nr =?), ?) |
values ( (select id from archive where dvd_nr =?), ?, ?) |
245 |
}); |
}); |
246 |
|
|
247 |
foreach my $arc (@archives_to_burn) { |
foreach my $arc (@archives_to_burn) { |
256 |
|
|
257 |
print "Working on DVD #$dvd_nr in $tmp_dir\n"; |
print "Working on DVD #$dvd_nr in $tmp_dir\n"; |
258 |
|
|
259 |
my $list_file = my $iso_file = my $xml_file = "${iso_dir}/${dvd_nr}"; |
my $part_path = ''; |
260 |
$list_file .= '.list'; |
my $part_nr = 1; |
261 |
$iso_file .= '.iso'; |
my $parts = 0; |
262 |
$xml_file .= '.xml'; |
|
|
|
|
|
if (-e $iso_file) { |
|
|
print "ISO $iso_file allready exists\n"; |
|
|
goto BURN; |
|
|
} |
|
|
|
|
263 |
$sth_archive_backup->execute($dvd_nr); |
$sth_archive_backup->execute($dvd_nr); |
264 |
|
|
265 |
open(my $list, "> $list_file") || skip "can't open $list_file: $!"; |
my $disk_name = 'unknown disk'; |
266 |
|
my $iso_size = 0; |
267 |
|
|
268 |
my $inc = 0; |
do { |
269 |
|
|
270 |
while (my $row = $sth_archive_backup->fetchrow_hashref) { |
# do we need to re-execute query for multi-part increments? |
271 |
my $tar_file = BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'}); |
$sth_archive_backup->execute($dvd_nr) if ($parts > 1); |
|
skip "can't find increment $tar_file: $!" unless (-r "$tar_dir/$tar_file"); |
|
|
print $list "$tar_dir/$tar_file\n"; |
|
|
$inc++; |
|
272 |
|
|
273 |
} |
my $row = $sth_archive_backup->fetchrow_hashref || die "can't fetch row"; |
274 |
|
|
|
# add file list and note in xml |
|
|
dumpArchive2XML($dbh, $dvd_nr, $xml_file); |
|
|
print $list "$xml_file\n"; |
|
|
|
|
|
# add css file for archive |
|
|
my $css_file = $Conf{CgiImageDir} . '/archive.css'; |
|
|
if (-r $css_file) { |
|
|
print $list "$css_file\n"; |
|
|
} else { |
|
|
print "WARNING: missing $css_file, not added to iso image!\n"; |
|
|
} |
|
275 |
|
|
276 |
close($list); |
$parts = $row->{'parts'} || die "no parts?"; |
277 |
|
$disk_name = $dvd_nr; |
278 |
|
|
279 |
|
if ($parts > 1) { |
280 |
|
# parts start with 0, so we have -1 here |
281 |
|
$part_path = '.' . ($part_nr - 1); |
282 |
|
$disk_name .= '.' . $part_nr; |
283 |
|
} |
284 |
|
|
285 |
|
print "Processing part $part_nr/$parts\n"; |
286 |
|
|
287 |
|
my $list_file = my $iso_file = my $xml_file = "${iso_dir}/${dvd_nr}"; |
288 |
|
$list_file .= '.list'; |
289 |
|
$iso_file .= $part_path . '.iso'; |
290 |
|
$xml_file .= '.xml'; |
291 |
|
|
292 |
|
# |
293 |
|
# check if ISO file exists |
294 |
|
# |
295 |
|
|
296 |
|
if (! -e $iso_file) { |
297 |
|
|
298 |
|
open(my $list, "> $list_file") || skip "can't open $list_file: $!"; |
299 |
|
|
300 |
|
my $inc = 0; |
301 |
|
|
302 |
print "Running mkisofs now for $inc increments...\n"; |
do { |
303 |
|
my $tar_file = BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'}); |
304 |
|
if (-f "$tar_dir/$tar_file") { |
305 |
|
skip "can't find increment $tar_file: $!" unless (-r "$tar_dir/$tar_file"); |
306 |
|
print $list "$tar_dir/$tar_file\n"; |
307 |
|
} else { |
308 |
|
my $len = length("$parts"); |
309 |
|
my $nr = sprintf("%0${len}d", $part_nr); |
310 |
|
print $list "$tar_dir/$tar_file/part$nr\n"; |
311 |
|
} |
312 |
|
$inc++; |
313 |
|
} while ($row = $sth_archive_backup->fetchrow_hashref); |
314 |
|
|
315 |
my $cmd = qq{ mkisofs -A BackupPC -gui -J -r -T --input-charset ISO-8859-2 -V $dvd_nr -o $iso_file -path-list $list_file }; |
# add file list and note in xml |
316 |
|
dumpArchive2XML($dbh, $dvd_nr, $xml_file) unless (-f $xml_file); |
317 |
|
print $list "$xml_file\n"; |
318 |
|
|
319 |
system($cmd) == 0 or skip "can't run $cmd: $?"; |
# add css file for archive |
320 |
|
my $css_file = $Conf{CgiImageDir} . '/archive.css'; |
321 |
|
if (-r $css_file) { |
322 |
|
print $list "$css_file\n"; |
323 |
|
} else { |
324 |
|
print "WARNING: missing $css_file, not added to iso image!\n"; |
325 |
|
} |
326 |
|
|
327 |
my $size = (stat($iso_file))[7]; |
close($list); |
328 |
|
|
329 |
print "Created $iso_file [$size bytes] in ", fmt_time(time() - $t), "\n"; |
print "Running mkisofs now for $inc increments, disk $disk_name\n"; |
330 |
|
|
331 |
BURN: |
my $cmd = $bin->{'mkisofs'} . qq{ -A BackupPC -gui -J -r -T --input-charset ISO-8859-2 -V $disk_name -o $iso_file -path-list $list_file }; |
332 |
# FIXME add call to cdrecord here! |
|
333 |
$sth_archive_burned->execute($dvd_nr, $size); |
system($cmd) == 0 or skip "can't run $cmd: $?"; |
334 |
print "Media burn for $dvd_nr recorded\n"; |
|
335 |
|
$iso_size = (stat($iso_file))[7]; |
336 |
|
|
337 |
|
print "Created $iso_file [$iso_size bytes] in ", fmt_time(time() - $t), "\n"; |
338 |
|
|
339 |
|
} else { |
340 |
|
print "ISO $iso_file allready exists\n"; |
341 |
|
} |
342 |
|
|
343 |
|
print "\nREADY TO BURN MEDIA $disk_name please insert blank media and press ENTER\n\n"; |
344 |
|
|
345 |
|
system($bin->{'eject'}) == 0 or skip "can't run eject: $?"; |
346 |
|
|
347 |
|
my $wait = <STDIN>; |
348 |
|
|
349 |
|
my $cmd = $bin->{'cdrecord'} . ' ' . $cdr_opts . ' ' . $iso_file; |
350 |
|
|
351 |
|
# system($cmd) == 0 or skip "can't run $cmd: $?"; |
352 |
|
print "## $cmd\n"; |
353 |
|
|
354 |
|
print "\n\nPLEASE REMOVE DVD MEDIA AND LABEL IT WITH $disk_name\n\n"; |
355 |
|
|
356 |
|
$sth_archive_burned->execute($dvd_nr, $iso_size, $part_nr); |
357 |
|
|
358 |
|
print "Media burn for $disk_name recorded\n"; |
359 |
|
|
360 |
|
$part_nr++; |
361 |
|
} until ($part_nr > $parts); |
362 |
|
|
363 |
SKIP: |
SKIP: |
364 |
|
|
367 |
#my $tar_file = BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'}); |
#my $tar_file = BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'}); |
368 |
#print curr_time, sprintf(" %s:%s %-3d ", $row->{'host'}, $row->{'share'}, $row->{'num'}), " -> $tar_file "; |
#print curr_time, sprintf(" %s:%s %-3d ", $row->{'host'}, $row->{'share'}, $row->{'num'}), " -> $tar_file "; |
369 |
|
|
370 |
|
print "Recoding finished, exiting...\n"; |
371 |
|
|
372 |
$sth->finish; |
$sth->finish; |
373 |
|
$sth_archive_backup->finish; |
374 |
|
$sth_archive_burned->finish; |
375 |
|
|
376 |
$dbh->disconnect; |
$dbh->disconnect; |
377 |
|
|