/[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 276 by dpavlin, Tue Dec 13 22:55:59 2005 UTC revision 322 by dpavlin, Mon Jan 30 17:45:25 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                            if (-d $_) {
282                                    print "\tremoving dir $_\n";
283                                    rmtree($_) || die "can't rmtree $_: $!";
284                            } else {
285                                    print "\tremoving $_\n";
286                                    unlink($_) || die "can't rm $_: $!";
287                            }
288                    } glob ( "/$iso_dir/$dvd_nr.*" );
289    
290                    $dbh->commit;
291    
292                    return 1;
293            } else {
294                    return 0;
295            }
296    }
297    
298  my $sth_archive_backup_parts = $dbh->prepare( qq{  my $sth_archive_backup_parts = $dbh->prepare( qq{
299          select          select
300                  archive_backup.backup_id,                  archive_backup.backup_id,
# Line 276  my $sth_archive_backup_parts = $dbh->pre Line 317  my $sth_archive_backup_parts = $dbh->pre
317          order by archive_backup.backup_id, backup_parts.part_nr          order by archive_backup.backup_id, backup_parts.part_nr
318  });  });
319    
320    my $sth_archive_backup_check = $dbh->prepare( qq{
321                    SELECT
322                            sum(backups.parts)
323                    FROM backups
324                    JOIN archive_backup on archive_backup.backup_id = backups.id
325                    JOIN archive on archive_id = archive.id
326                    WHERE dvd_nr = ?
327    });
328    
329  my $sth_archive_burned = $dbh->prepare( qq{  my $sth_archive_burned = $dbh->prepare( qq{
330          insert into archive_burned          insert into archive_burned
331                  (archive_id, iso_size, part, copy)                  (archive_id, iso_size, part, copy)
# Line 296  foreach my $arc (@archives_to_burn) { Line 346  foreach my $arc (@archives_to_burn) {
346    
347          $sth_archive_backup_parts->execute($dvd_nr);          $sth_archive_backup_parts->execute($dvd_nr);
348    
349            $sth_archive_backup_check->execute($dvd_nr);
350    
351            my ($parts_nr, $check_nr) = ($sth_archive_backup_parts->rows, $sth_archive_backup_check->fetchrow_array);
352    
353            if ($parts_nr != $check_nr) {
354                    warn "ERROR: DVD #$dvd_nr is still not inconsistent state. Some backup parts are ",
355                            ($parts_nr < $check_nr) ? "missing ($parts_nr < $check_nr)" : "extra ($parts_nr > $check_nr)",
356                            " you should re-create this DVD after BackupPC_incPartsUpdate finish\n";
357                    delete_dvd( $dvd_nr );
358                    next;
359            }
360    
361            if ($sth_archive_backup_parts->rows == 0) {
362                    warn "ERROR: no backup parts found for $dvd_nr. You should re-create that DVD.\n";
363                    next if delete_dvd( $dvd_nr );
364            }
365    
366            if ($prompt_for_delete) {
367                    next if delete_dvd( $dvd_nr );
368            }
369    
370          my @volumes;          my @volumes;
371          my $v;  # emtpy volume          my $v;  # emtpy volume
372          my $v_size = 0;          my $v_size = 0;
# Line 318  foreach my $arc (@archives_to_burn) { Line 389  foreach my $arc (@archives_to_burn) {
389          }          }
390          push @volumes, $v if ($v);          push @volumes, $v if ($v);
391    
392            #warn "# volumes: ",Dumper(\@volumes),"\n";
393    
394          my $volumes = $#volumes + 1;          my $volumes = $#volumes + 1;
395          my $volume_nr = 1;          my $volume_nr = 1;
396    
397          foreach my $v (@volumes) {          foreach my $v (@volumes) {
398    
399                  print Dumper($v);                  #print Dumper($v);
400    
401                  my $iso_size = 0;                  my $iso_size = 0;
402                  my $disk_name = $dvd_nr;                  my $disk_name = $dvd_nr;
403                  # suffix added to multi-volume archives                  # suffix added to multi-volume archives
404                  my $volume_suffix = $dvd_nr;                  my $volume_suffix = '';
405    
406                  if ($volumes > 1) {                  if ($volumes > 1) {
407                          $volume_suffix = '_' . $volume_nr;                          $volume_suffix = '_' . $volume_nr;
# Line 369  foreach my $arc (@archives_to_burn) { Line 442  foreach my $arc (@archives_to_burn) {
442                                  my $rel_path = $tar_file;                                  my $rel_path = $tar_file;
443    
444                                  if (-d "$tar_dir/$rel_path") {                                  if (-d "$tar_dir/$rel_path") {
                                         $rel_path .= '/' . $p->{part_nr};  
445                                          mkpath("$stage/$rel_path") unless (-d "$stage/$rel_path");                                          mkpath("$stage/$rel_path") unless (-d "$stage/$rel_path");
446                                            $rel_path .= '/' . $p->{part_nr};
447                                  }                                  }
448                                  $rel_path .= '.tar.gz';                                  $rel_path .= '.tar.gz';
449    
# Line 410  foreach my $arc (@archives_to_burn) { Line 483  foreach my $arc (@archives_to_burn) {
483    
484                          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";
485    
486                          # FIXME                          rmtree($stage) || warn "can't remove stage directory $stage: $!";
                         #rmtree($stage) || warn "can't remove stage directory $stage: $!";  
487    
488                  } else {                  } else {
489                          print "ISO $iso_file allready exists\n";                          print "ISO $iso_file allready exists\n";
# Line 455  print "Recoding finished, exiting...\n"; Line 527  print "Recoding finished, exiting...\n";
527  $sth->finish;  $sth->finish;
528  $sth_archive_backup_parts->finish;  $sth_archive_backup_parts->finish;
529  $sth_archive_burned->finish;  $sth_archive_burned->finish;
530    $sth_archive_backup_check->finish;
531    $sth_archive_burned->finish;
532    
533  $dbh->disconnect;  $dbh->disconnect;
534    

Legend:
Removed from v.276  
changed lines
  Added in v.322

  ViewVC Help
Powered by ViewVC 1.1.26