/[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 201 by dpavlin, Fri Oct 14 14:02:51 2005 UTC revision 207 by dpavlin, Sat Oct 15 13:40:04 2005 UTC
# Line 16  use Data::Dumper; Line 16  use Data::Dumper;
16  my $debug = 0;  my $debug = 0;
17  $|=1;  $|=1;
18    
19  my $cdr_opts = 'dev=/dev/hdc blank=fast -v -eject';  # don't check for user
20    my $bpc = BackupPC::Lib->new(undef, undef, 1) || die;
21    my %Conf = $bpc->Conf();
22    %BackupPC::SearchLib::Conf = %Conf;
23    
24    my $conf_bin;
25    
26    $conf_bin->{'cdrecord'} = $Conf{CDRecordBin} || die "Need CDRecordBin in config.pl\n";
27    my $cdr_opts = $Conf{CDRecordOpts} || die "Need CDRecordOpts in config.pl\n";
28    $conf_bin->{'eject'} = $Conf{ejectBin} || die "Need ejectBin in config.pl\n";
29    my $eject_opts = $Conf{ejectOpts} || die "Need ejectOpts in config.pl\n";
30    $conf_bin->{'mkisofs'} = $Conf{mkisofsBin} || die "Need mkisofsBin in config.pl\n";
31    
32    
33  my $bin;  my $bin;
34  foreach my $c (qw/mkisofs cdrecord eject/) {  foreach my $c (qw/cdrecord eject mkisofs/) {
35          $bin->{$c} = which($c) || die "$0 needs $c, install it\n";          $bin->{$c} = which($conf_bin->{$c}) || die "$0 needs $c ($conf_bin->{$c}), install it\n";
36  }  }
37    
38  my $start_t = time();  my $start_t = time();
39    
40  my $t_fmt = '%Y-%m-%d %H:%M:%S';  my $t_fmt = '%Y-%m-%d %H:%M:%S';
41    
 # don't check for user  
 my $bpc = BackupPC::Lib->new(undef, undef, 1) || die;  
 my %Conf = $bpc->Conf();  
 %BackupPC::SearchLib::Conf = %Conf;  
42    
43  my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n";  my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n";
44  my $user = $Conf{SearchUser} || '';  my $user = $Conf{SearchUser} || '';
# Line 64  sub curr_time { Line 72  sub curr_time {
72  sub dumpArchive2XML($$$)  sub dumpArchive2XML($$$)
73  {  {
74          my ($dbh, $dvd_nr, $filename) = @_;          my ($dbh, $dvd_nr, $filename) = @_;
75          my %archive;              my %archive;
76          my $output = new IO::File(">$filename");  
77            my $output = new IO::File('> '.$filename.'.tmp');
78          my $writer = new XML::Writer(OUTPUT=>$output, NEWLINES => 1);          my $writer = new XML::Writer(OUTPUT=>$output, NEWLINES => 1);
79    
80            print "Dumping file list for DVD $dvd_nr, countdown:";
81    
82          $writer->pi('xml-stylesheet', 'href="archive.css" type="text/css"');          $writer->pi('xml-stylesheet', 'href="archive.css" type="text/css"');
83    
84          my $files_sql = q{          my $files_sql = q{
# Line 91  sub dumpArchive2XML($$$) Line 102  sub dumpArchive2XML($$$)
102                          backups.date AS date,                          backups.date AS date,
103                          shares.name  AS share,                          shares.name  AS share,
104                          backups.size AS backup_size,                          backups.size AS backup_size,
105                          backups.inc_size AS compress_size,                          backups.inc_size AS compress_size
                         backups.parts AS parts  
106                  FROM backups, archive_backup, hosts, shares                  FROM backups, archive_backup, hosts, shares
107                  WHERE archive_backup.backup_id = backups.id                  WHERE archive_backup.backup_id = backups.id
108                          AND hosts.id=backups.hostid                          AND hosts.id=backups.hostid
# Line 119  sub dumpArchive2XML($$$) Line 129  sub dumpArchive2XML($$$)
129          my $sth_backups = $dbh->prepare( $backups_sql );          my $sth_backups = $dbh->prepare( $backups_sql );
130          $sth_backups->execute( $row_h->{'id'} );          $sth_backups->execute( $row_h->{'id'} );
131    
132            my $total_backups = $sth_backups->rows;
133            my $curr_backup = 0;
134            my $last_pcnt = 0;
135    
136          while (my $row = $sth_backups->fetchrow_hashref()) {          while (my $row = $sth_backups->fetchrow_hashref()) {
137    
138                    $curr_backup++;
139                    my $pcnt = int(($curr_backup * 10) / $total_backups);
140                    if ($pcnt > $last_pcnt) {
141                            print " ",(10 - $pcnt);
142                            $last_pcnt = $pcnt;
143                    }
144    
145                  my $sth_files = $dbh->prepare( $files_sql);                  my $sth_files = $dbh->prepare( $files_sql);
146                  $sth_files->execute($row->{'backup_id'});                  $sth_files->execute($row->{'backup_id'});
147    
# Line 144  sub dumpArchive2XML($$$) Line 165  sub dumpArchive2XML($$$)
165                                                    
166          $writer->endTag("archive");          $writer->endTag("archive");
167          $writer->end();          $writer->end();
168            
169            rename $filename.'.tmp', $filename || die "can't rename $filename: $!";
170    
171            print "\n";
172  }  }
173    
174    
# Line 171  sub fmt_archive($) { Line 195  sub fmt_archive($) {
195          $row->{'copies'} =~ s/^\s*0+\s*$/no/;          $row->{'copies'} =~ s/^\s*0+\s*$/no/;
196          $row->{'total_size'} /= (1024*1024);          $row->{'total_size'} /= (1024*1024);
197    
198          my $copies = $row->{'copies'};          my $copies = 'copies';
199          if ($row->{'parts'} > 1) {          $copies = 'copy' if ($row->{'copies'} == 1);
                 $copies .= '/' . $row->{'parts'};  
         }  
   
         my $copies_dest = 'copies';  
         $copies_dest = 'copy' if ($row->{'copies'} == 1);  
200    
201          return          return
202                  sprintf("%d by %s on %s, %s %s [%.2f Mb]",                  sprintf("%d by %s on %s, %s %s [%.2f Mb]",
203                          $row->{'dvd_nr'},                          $row->{'dvd_nr'},
204                          $row->{'username'},                          $row->{'username'},
205                          $row->{'date'},                          $row->{'date'},
206                          $copies, $copies_dest,                          $row->{'copies'}, $copies,
207                          $row->{'total_size'},                          $row->{'total_size'},
208                  );                  );
209  }  }
# Line 246  my $sth_archive_backup = $dbh->prepare( Line 265  my $sth_archive_backup = $dbh->prepare(
265    
266  my $sth_archive_burned = $dbh->prepare( qq{  my $sth_archive_burned = $dbh->prepare( qq{
267          insert into archive_burned          insert into archive_burned
268                  (archive_id, iso_size, part)                  (archive_id, iso_size, part, copy)
269          values ( (select id from archive where dvd_nr =?), ?, ?)          values ( (select id from archive where dvd_nr =?), ?, ?, ?)
270  });  });
271    
272  foreach my $arc (@archives_to_burn) {  foreach my $arc (@archives_to_burn) {
# Line 334  foreach my $arc (@archives_to_burn) { Line 353  foreach my $arc (@archives_to_burn) {
353    
354                          print "Running mkisofs now for $inc increments, disk $disk_name\n";                          print "Running mkisofs now for $inc increments, disk $disk_name\n";
355    
356                          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 };                          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 };
357    
358                          system($cmd) == 0 or skip "can't run $cmd: $?";                          system($cmd) == 0 or skip "can't run $cmd: $?";
359    
360                            rename $iso_file.'.tmp', $iso_file || skip "can't rename $iso_file: $!";
361    
362                          $iso_size = (stat($iso_file))[7];                          $iso_size = (stat($iso_file))[7];
363    
364                          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";
# Line 346  foreach my $arc (@archives_to_burn) { Line 367  foreach my $arc (@archives_to_burn) {
367                          print "ISO $iso_file allready exists\n";                          print "ISO $iso_file allready exists\n";
368                  }                  }
369    
370                  print "\nREADY TO BURN MEDIA $disk_name please insert blank media and press ENTER\n\n";                  my $copies = $Conf{BurnMultipleCopies} || 1;
371    
372                    foreach my $copy_nr ( 1 .. $copies ) {
373    
374                  system($bin->{'eject'}) == 0 or skip "can't run eject: $?";                          print "\nREADY TO BURN MEDIA $disk_name copy $copy_nr\n\nPlease insert blank media and press ENTER\n\n";
375    
376                  my $wait = <STDIN>;                          system($bin->{'eject'}.' '.$eject_opts) == 0 or skip "can't run eject: $?";
377    
378                  my $cmd = $bin->{'cdrecord'} . ' ' . $cdr_opts . ' ' . $iso_file;                          my $wait = <STDIN>;
379    
380  #               system($cmd) == 0 or skip "can't run $cmd: $?";                          my $cmd = $bin->{'cdrecord'} . ' ' . $cdr_opts . ' ' . $iso_file;
                 print "## $cmd\n";  
381    
382                  print "\n\nPLEASE REMOVE DVD MEDIA AND LABEL IT WITH $disk_name\n\n";                          # FIXME
383                            print "## $cmd\n";
384                            system($cmd) == 0 or skip "can't run $cmd: $?";
385    
386                            print "\n\nPLEASE REMOVE DVD MEDIA AND LABEL IT WITH $disk_name\n\n";
387    
388                  $sth_archive_burned->execute($dvd_nr, $iso_size, $part_nr);                          $sth_archive_burned->execute($dvd_nr, $iso_size, $part_nr, $copy_nr);
389    
390                  print "Media burn for $disk_name recorded\n";                          print "Media burn for $disk_name copy $copy_nr recorded\n";
391                    }
392    
393                  $part_nr++;                  $part_nr++;
394          } until ($part_nr > $parts);          } until ($part_nr > $parts);

Legend:
Removed from v.201  
changed lines
  Added in v.207

  ViewVC Help
Powered by ViewVC 1.1.26