/[BackupPC]/trunk/bin/BackupPC_burnArchiveCLI
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/bin/BackupPC_burnArchiveCLI

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 208 by dpavlin, Sat Oct 15 14:11:46 2005 UTC revision 286 by dpavlin, Sun Jan 15 13:41:23 2006 UTC
# Line 10  use Time::HiRes qw/time/; Line 10  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;  use File::Which;
13    use File::Path;
14    
15  use Data::Dumper;  use Data::Dumper;
16    
# Line 247  sub skip($) { Line 248  sub skip($) {
248          goto SKIP;          goto SKIP;
249  }  }
250    
251  my $sth_archive_backup = $dbh->prepare( qq{  sub add_symlink($$) {
252            my ($from, $to) = @_;
253            symlink $from, $to || skip("can't symlink $from to $to: $!");
254    }
255    
256    my $sth_archive_backup_parts = $dbh->prepare( qq{
257          select          select
258                  backup_id,                  archive_backup.backup_id,
259                  archive_id,                  archive_id,
260                  hosts.name as host,                  hosts.name as host,
261                  shares.name as share,                  shares.name as share,
262                  backups.num as num,                  backups.num as num,
263                  backups.parts as parts                  backups.parts as parts,
264                    backup_parts.part_nr as part_nr,
265                    backup_parts.size as part_size,
266                    backup_parts.md5 as md5,
267                    backup_parts.items
268          from archive_backup          from archive_backup
269          join archive on archive_id = archive.id          join archive on archive_id = archive.id
270          join backups on backup_id = backups.id          join backups on archive_backup.backup_id = backups.id
271          join hosts on hostid = hosts.id          join hosts on hostid = hosts.id
272          join shares on shareid = shares.id          join shares on shareid = shares.id
273            join backup_parts on archive_backup.backup_id = backup_parts.backup_id
274          where archive.dvd_nr = ?          where archive.dvd_nr = ?
275            order by archive_backup.backup_id, backup_parts.part_nr
276  });  });
277    
278  my $sth_archive_burned = $dbh->prepare( qq{  my $sth_archive_burned = $dbh->prepare( qq{
# Line 281  foreach my $arc (@archives_to_burn) { Line 293  foreach my $arc (@archives_to_burn) {
293    
294          print "Working on DVD #$dvd_nr in $tmp_dir\n";          print "Working on DVD #$dvd_nr in $tmp_dir\n";
295    
296          my $part_path = '';          $sth_archive_backup_parts->execute($dvd_nr);
         my $part_nr = 1;  
         my $parts = 0;  
                   
         $sth_archive_backup->execute($dvd_nr);  
297    
298          my $disk_name = 'unknown disk';          if ($sth_archive_backup_parts->rows == 0) {
299          my $iso_size = 0;                  warn "ERROR: no backup parts found for $dvd_nr. You should re-create that DVD.\n";
300            }
301    
302          do {          my @volumes;
303            my $v;  # emtpy volume
304            my $v_size = 0;
305    
306            my $max_archive_size = $Conf{MaxArchiveSize} || die "no MaxArchiveSize";
307            while (my $row = $sth_archive_backup_parts->fetchrow_hashref) {
308                    if (($v->{size} || 0) + $row->{part_size} > $max_archive_size) {
309                            push @volumes, $v;
310                            $v = {};
311                    }
312                    $v->{size} += $row->{part_size};
313                    # this part
314                    my $p = {
315                            filename => BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'}),
316                    };
317                    foreach my $fld (qw/part_nr md5/) {
318                            $p->{$fld} = $row->{$fld} || die "missing $fld in row!";
319                    }
320                    push @{ $v->{parts} }, $p;
321            }
322            push @volumes, $v if ($v);
323    
324                  # do we need to re-execute query for multi-part increments?          #warn "# volumes: ",Dumper(\@volumes),"\n";
                 $sth_archive_backup->execute($dvd_nr) if ($parts > 1);  
325    
326                  my $row = $sth_archive_backup->fetchrow_hashref || die "can't fetch row";          my $volumes = $#volumes + 1;
327            my $volume_nr = 1;
328    
329            foreach my $v (@volumes) {
330    
331                  $parts =  $row->{'parts'} || die "no parts?";                  #print Dumper($v);
                 $disk_name = $dvd_nr;  
332    
333                  if ($parts > 1) {                  my $iso_size = 0;
334                          # parts start with 0, so we have -1 here                  my $disk_name = $dvd_nr;
335                          $part_path = '.' . ($part_nr - 1);                  # suffix added to multi-volume archives
336                          $disk_name .= ' ' . $part_nr . '/' . $parts;                  my $volume_suffix = $dvd_nr;
337    
338                    if ($volumes > 1) {
339                            $volume_suffix = '_' . $volume_nr;
340                            $disk_name .= ' ' . $volume_nr . '/' . $volumes;
341                  }                  }
342    
343                  print "Processing part $part_nr/$parts\n";                  print "Processing DVD #$dvd_nr, volume $volume_nr/$volumes\n";
344    
345                    my $iso_file = my $xml_file = my $stage =
346                            "${iso_dir}/${dvd_nr}";
347    
348                  my $list_file = my $iso_file = my $xml_file = "${iso_dir}/${dvd_nr}";                  $iso_file .= $volume_suffix . '.iso';
                 $list_file .= $part_path . '.list';  
                 $iso_file .= $part_path . '.iso';  
349                  $xml_file .= '.xml';                  $xml_file .= '.xml';
350    
351                    $stage .= $volume_suffix . '.stage';
352    
353                    my $md5_file = "${stage}/${dvd_nr}${volume_suffix}.md5";
354    
355                  #                  #
356                  # check if ISO file exists                  # check if ISO file exists
357                  #                  #
358    
359                  if (! -e $iso_file) {                  if (! -e $iso_file) {
360    
361                          open(my $list, "> $list_file") || skip "can't open $list_file: $!";                          # create stage directory
362                            if (-e $stage) {
363                                    rmtree($stage) || die "can't remove $stage: $!";
364                            }
365                            mkpath($stage);
366    
367                            # open file for md5sums
368                            open(my $md5, "> $md5_file") || skip "can't open $md5_file: $!";
369    
370                            my $parts_on_this_volume = 0;
371    
372                          my $inc = 0;                          foreach my $p (@{ $v->{parts} }) {
373                                    my $tar_file = $p->{filename} || die "no filename in part", Dumper($p);
374                                    my $rel_path = $tar_file;
375    
376                          do {                                  if (-d "$tar_dir/$rel_path") {
377                                  my $tar_file = BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'});                                          mkpath("$stage/$rel_path") unless (-d "$stage/$rel_path");
378                                  if (-f "$tar_dir/$tar_file") {                                          $rel_path .= '/' . $p->{part_nr};
                                         skip "can't find increment $tar_file: $!" unless (-r "$tar_dir/$tar_file");  
                                         print $list "$tar_dir/$tar_file\n";  
                                 } else {  
                                         my $len = length("$parts");  
                                         my $nr = sprintf("%0${len}d", ($part_nr - 1));  
                                         print $list "$tar_dir/$tar_file/part$nr\n";  
379                                  }                                  }
380                                  $inc++;                                  $rel_path .= '.tar.gz';
381                          } while ($row = $sth_archive_backup->fetchrow_hashref);  
382                                    skip "can't find increment $rel_path: $!" unless (-r "$tar_dir/$rel_path");
383    
384                                    add_symlink("$tar_dir/$rel_path", "$stage/$rel_path");
385    
386                                    my $md5sum = $p->{md5} || die "no md5 in part ", Dumper($p);
387                                    chomp($md5sum);
388                                    print $md5 "$md5sum  $rel_path\n" || die "can't write md5sum: $!";
389    
390                                    $parts_on_this_volume++;
391                            }
392    
393                          # add file list and note in xml                          # add file list and note in xml
394                          dumpArchive2XML($dbh, $dvd_nr, $xml_file) unless (-f $xml_file);                          dumpArchive2XML($dbh, $dvd_nr, $xml_file) unless (-f $xml_file);
395                          print $list "$xml_file\n";  
396                            add_symlink($xml_file, "$stage/${dvd_nr}.xml");
397    
398                          # add css file for archive                          # add css file for archive
399                          my $css_file = $Conf{CgiImageDir} . '/archive.css';                          my $css_file = $Conf{CgiImageDir} . '/archive.css';
400                          if (-r $css_file) {                          if (-r $css_file) {
401                                  print $list "$css_file\n";                                  add_symlink($css_file, "$stage/archive.css");
402                          } else {                          } else {
403                                  print "WARNING: missing $css_file, not added to iso image!\n";                                  print "WARNING: missing $css_file, not added to iso image!\n";
404                          }                          }
405    
406                          close($list);                          print "Running mkisofs now for $parts_on_this_volume increments, disk $disk_name\n";
   
                         print "Running mkisofs now for $inc increments, disk $disk_name\n";  
407    
408                          my $cmd = $bin->{'mkisofs'} . qq{ -A BackupPC -gui -J -r -T --input-charset ISO-8859-2 -V "$disk_name" -o ${iso_file}.tmp -path-list $list_file };                          my $cmd = $bin->{'mkisofs'} . qq{ -A BackupPC -gui -J -r -T --input-charset ISO-8859-2 -V "$disk_name" -o ${iso_file}.tmp -f $stage };
409    
410                          system($cmd) == 0 or skip "can't run $cmd: $?";                          system($cmd) == 0 or skip "can't run $cmd: $?";
411    
# Line 363  foreach my $arc (@archives_to_burn) { Line 415  foreach my $arc (@archives_to_burn) {
415    
416                          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";
417    
418                            rmtree($stage) || warn "can't remove stage directory $stage: $!";
419    
420                  } else {                  } else {
421                          print "ISO $iso_file allready exists\n";                          print "ISO $iso_file allready exists\n";
422                  }                  }
# Line 385  foreach my $arc (@archives_to_burn) { Line 439  foreach my $arc (@archives_to_burn) {
439    
440                          print "\n\nPLEASE REMOVE DVD MEDIA AND LABEL IT WITH $disk_name\n\n";                          print "\n\nPLEASE REMOVE DVD MEDIA AND LABEL IT WITH $disk_name\n\n";
441    
442                          $sth_archive_burned->execute($dvd_nr, $iso_size, $part_nr, $copy_nr);                          $sth_archive_burned->execute($dvd_nr, $iso_size, $volume_nr, $copy_nr);
443    
444                          print "Media burn for $disk_name copy $copy_nr recorded\n";                          print "Media burn for $disk_name copy $copy_nr recorded\n";
445                  }                  }
446    
447                  $part_nr++;                  $volume_nr++;
448          } until ($part_nr > $parts);          }
449    
450  SKIP:  SKIP:
451    
# Line 403  SKIP: Line 457  SKIP:
457  print "Recoding finished, exiting...\n";  print "Recoding finished, exiting...\n";
458    
459  $sth->finish;  $sth->finish;
460  $sth_archive_backup->finish;  $sth_archive_backup_parts->finish;
461  $sth_archive_burned->finish;  $sth_archive_burned->finish;
462    
463  $dbh->disconnect;  $dbh->disconnect;

Legend:
Removed from v.208  
changed lines
  Added in v.286

  ViewVC Help
Powered by ViewVC 1.1.26