/[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 275 by dpavlin, Tue Dec 13 22:53:30 2005 UTC revision 319 by dpavlin, Mon Jan 30 14:58:46 2006 UTC
# Line 1  Line 1 
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;
# Line 16  use File::Path; Line 15  use File::Path;
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 = shift @ARGV;
20  $|=1;  $|=1;
21    
22  # don't check for user  # don't check for user
# Line 110  sub dumpArchive2XML($$$) Line 111  sub dumpArchive2XML($$$)
111                          AND hosts.id=backups.hostid                          AND hosts.id=backups.hostid
112                          AND shares.id=backups.shareid                          AND shares.id=backups.shareid
113                          AND archive_backup.archive_id = ?                          AND archive_backup.archive_id = ?
114                    ORDER BY
115                            hosts.name, shares.name, backups.num
116          };          };
117    
118          my $sth = $dbh->prepare("SELECT dvd_nr, total_size, note, username, date,id FROM archive WHERE dvd_nr=?");          my $sth = $dbh->prepare("SELECT dvd_nr, total_size, note, username, date,id FROM archive WHERE dvd_nr=?");
# Line 163  sub dumpArchive2XML($$$) Line 166  sub dumpArchive2XML($$$)
166                          $writer->endTag("file");                          $writer->endTag("file");
167                  }                  }
168                  $writer->endTag("backup");                  $writer->endTag("backup");
169          }                }
170                                                    
171          $writer->endTag("archive");          $writer->endTag("archive");
172          $writer->end();          $writer->end();
# Line 254  sub add_symlink($$) { Line 257  sub add_symlink($$) {
257          symlink $from, $to || skip("can't symlink $from to $to: $!");          symlink $from, $to || skip("can't symlink $from to $to: $!");
258  }  }
259    
260    sub delete_dvd($) {
261            my $dvd_nr = shift || return;
262    
263            print "Do you want to delete DVD #$dvd_nr now? [NO/yes]: ";
264            my $ok = <STDIN>;
265            chomp($ok);
266            if (lc($ok) eq 'yes') {
267                    print "Deleting DVD #$dvd_nr from database...\n";
268    
269                    $dbh->begin_work;
270    
271                    my $sth_delete_dvd = $dbh->prepare( qq{
272                            delete from archive where dvd_nr = ?
273                    } );
274                    $sth_delete_dvd->execute( $dvd_nr );
275                    $dbh->do( qq{
276                            select setval('dvd_nr', (select max(dvd_nr) from archive), true)
277                    } );
278    
279                    # remove files for this DVD
280                    map {
281                            print "\tremoving $_\n";
282                            unlink($_) || die "can't rm $_: $!";
283                    } glob ( "/$iso_dir/$dvd_nr.*" );
284    
285                    $dbh->commit;
286    
287                    return 1;
288            } else {
289                    return 0;
290            }
291    }
292    
293  my $sth_archive_backup_parts = $dbh->prepare( qq{  my $sth_archive_backup_parts = $dbh->prepare( qq{
294          select          select
295                  archive_backup.backup_id,                  archive_backup.backup_id,
# Line 276  my $sth_archive_backup_parts = $dbh->pre Line 312  my $sth_archive_backup_parts = $dbh->pre
312          order by archive_backup.backup_id, backup_parts.part_nr          order by archive_backup.backup_id, backup_parts.part_nr
313  });  });
314    
315    my $sth_archive_backup_check = $dbh->prepare( qq{
316                    SELECT
317                            count(backups.id)
318                    FROM backups
319                    JOIN archive_backup on archive_backup.backup_id = backups.id
320                    JOIN archive on archive_id = archive.id
321                    WHERE dvd_nr = ?
322    });
323    
324  my $sth_archive_burned = $dbh->prepare( qq{  my $sth_archive_burned = $dbh->prepare( qq{
325          insert into archive_burned          insert into archive_burned
326                  (archive_id, iso_size, part, copy)                  (archive_id, iso_size, part, copy)
# Line 296  foreach my $arc (@archives_to_burn) { Line 341  foreach my $arc (@archives_to_burn) {
341    
342          $sth_archive_backup_parts->execute($dvd_nr);          $sth_archive_backup_parts->execute($dvd_nr);
343    
344            $sth_archive_backup_check->execute($dvd_nr);
345    
346            my ($parts_nr, $check_nr) = ($sth_archive_backup_parts->rows, $sth_archive_backup_check->fetchrow_array);
347    
348            if ($parts_nr != $check_nr) {
349                    warn "ERROR: DVD #$dvd_nr is still not inconsistent state. Some backup parts are ",
350                            ($parts_nr < $check_nr) ? "missing ($parts_nr < $check_nr)" : "extra ($parts_nr > $check_nr)",
351                            " you should re-create this DVD after BackupPC_incPartsUpdate finish\n";
352                    delete_dvd( $dvd_nr );
353                    next;
354            }
355    
356            if ($sth_archive_backup_parts->rows == 0) {
357                    warn "ERROR: no backup parts found for $dvd_nr. You should re-create that DVD.\n";
358                    next if delete_dvd( $dvd_nr );
359            }
360    
361            if ($prompt_for_delete) {
362                    next if delete_dvd( $dvd_nr );
363            }
364    
365          my @volumes;          my @volumes;
366          my $v;  # emtpy volume          my $v;  # emtpy volume
367          my $v_size = 0;          my $v_size = 0;
# Line 318  foreach my $arc (@archives_to_burn) { Line 384  foreach my $arc (@archives_to_burn) {
384          }          }
385          push @volumes, $v if ($v);          push @volumes, $v if ($v);
386    
387            #warn "# volumes: ",Dumper(\@volumes),"\n";
388    
389          my $volumes = $#volumes + 1;          my $volumes = $#volumes + 1;
390          my $volume_nr = 1;          my $volume_nr = 1;
391    
392          foreach my $v (@volumes) {          foreach my $v (@volumes) {
393    
394                  print Dumper($v);                  #print Dumper($v);
395    
396                  my $iso_size = 0;                  my $iso_size = 0;
397                  my $disk_name = $dvd_nr;                  my $disk_name = $dvd_nr;
398                  # suffix added to multi-volume archives                  # suffix added to multi-volume archives
399                  my $volume_suffix = $dvd_nr;                  my $volume_suffix = '';
400    
401                  if ($volumes > 1) {                  if ($volumes > 1) {
402                          $volume_suffix = '_' . $volume_nr;                          $volume_suffix = '_' . $volume_nr;
# Line 369  foreach my $arc (@archives_to_burn) { Line 437  foreach my $arc (@archives_to_burn) {
437                                  my $rel_path = $tar_file;                                  my $rel_path = $tar_file;
438    
439                                  if (-d "$tar_dir/$rel_path") {                                  if (-d "$tar_dir/$rel_path") {
                                         $rel_path .= '/' . $p->{part_nr};  
440                                          mkpath("$stage/$rel_path") unless (-d "$stage/$rel_path");                                          mkpath("$stage/$rel_path") unless (-d "$stage/$rel_path");
441                                            $rel_path .= '/' . $p->{part_nr};
442                                  }                                  }
443                                  $rel_path .= '.tar.gz';                                  $rel_path .= '.tar.gz';
444    
# Line 379  foreach my $arc (@archives_to_burn) { Line 447  foreach my $arc (@archives_to_burn) {
447                                  add_symlink("$tar_dir/$rel_path", "$stage/$rel_path");                                  add_symlink("$tar_dir/$rel_path", "$stage/$rel_path");
448    
449                                  my $md5sum = $p->{md5} || die "no md5 in part ", Dumper($p);                                  my $md5sum = $p->{md5} || die "no md5 in part ", Dumper($p);
450                                  print $md5 "$md5sum\s\s$rel_path\n" || die "can't write md5sum: $!";                                  chomp($md5sum);
451                                    print $md5 "$md5sum  $rel_path\n" || die "can't write md5sum: $!";
452    
453                                  $parts_on_this_volume++;                                  $parts_on_this_volume++;
454                          }                          }
# Line 409  foreach my $arc (@archives_to_burn) { Line 478  foreach my $arc (@archives_to_burn) {
478    
479                          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";
480    
481                          # FIXME                          rmtree($stage) || warn "can't remove stage directory $stage: $!";
                         #rmtree($stage) || warn "can't remove stage directory $stage: $!";  
482    
483                  } else {                  } else {
484                          print "ISO $iso_file allready exists\n";                          print "ISO $iso_file allready exists\n";
# Line 454  print "Recoding finished, exiting...\n"; Line 522  print "Recoding finished, exiting...\n";
522  $sth->finish;  $sth->finish;
523  $sth_archive_backup_parts->finish;  $sth_archive_backup_parts->finish;
524  $sth_archive_burned->finish;  $sth_archive_burned->finish;
525    $sth_archive_backup_check->finish;
526    $sth_archive_burned->finish;
527    
528  $dbh->disconnect;  $dbh->disconnect;
529    

Legend:
Removed from v.275  
changed lines
  Added in v.319

  ViewVC Help
Powered by ViewVC 1.1.26