/[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 286 by dpavlin, Sun Jan 15 13:41:23 2006 UTC revision 319 by dpavlin, Mon Jan 30 14:58:46 2006 UTC
# Line 15  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 109  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 162  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 253  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 275  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 295  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) {          if ($sth_archive_backup_parts->rows == 0) {
357                  warn "ERROR: no backup parts found for $dvd_nr. You should re-create that DVD.\n";                  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;
# Line 333  foreach my $arc (@archives_to_burn) { Line 396  foreach my $arc (@archives_to_burn) {
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 459  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.286  
changed lines
  Added in v.319

  ViewVC Help
Powered by ViewVC 1.1.26