/[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 174 by dpavlin, Tue Oct 11 16:59:16 2005 UTC revision 189 by dpavlin, Wed Oct 12 16:49:03 2005 UTC
# Line 34  my $dbh = DBI->connect($dsn, $user, "", Line 34  my $dbh = DBI->connect($dsn, $user, "",
34  my $tar_dir = $Conf{InstallDir}.'/';  my $tar_dir = $Conf{InstallDir}.'/';
35  $tar_dir .= $Conf{GzipTempDir} || die "GzipTempDir isn't defined in configuration";  $tar_dir .= $Conf{GzipTempDir} || die "GzipTempDir isn't defined in configuration";
36    
37  die "problem with $tar_dir, check GzipTempDir in configuration\n" unless (-d $tar_dir && -w $tar_dir);  die "problem with $tar_dir, check GzipTempDir in configuration\n" unless (-d $tar_dir);
38    
39  my $iso_dir = $Conf{InstallDir}.'/';  my $iso_dir = $Conf{InstallDir}.'/';
40  $iso_dir .= $Conf{ISOTempDir} || die "ISOTempDir isn't defined in configuration";  $iso_dir .= $Conf{ISOTempDir} || die "ISOTempDir isn't defined in configuration";
# Line 55  sub curr_time { Line 55  sub curr_time {
55          return strftime($t_fmt,localtime());          return strftime($t_fmt,localtime());
56  }  }
57    
58    sub dumpArchive2XML($$$)
59    {
60            my ($dbh, $dvd_nr, $filename) = @_;
61            my %archive;    
62            my $output = new IO::File(">$filename");
63            my $writer = new XML::Writer(OUTPUT=>$output, NEWLINES => 1);
64    
65            $writer->pi('xml-stylesheet', 'href="archive.css" type="text/css"');
66    
67            my $files_sql = q{
68                    SELECT
69                            files.path AS path,
70                            files.date AS date,
71                            files.type AS type,
72                            files.size AS size
73                    FROM files, backups, shares
74                    WHERE files.backupnum=backups.num AND
75                            files.shareid=shares.id AND
76                            shares.hostid=backups.hostid AND
77                            backups.id=?
78            };
79    
80            my $backups_sql = q{
81                    SELECT
82                            backups.id   AS backup_id,
83                            hosts.name   AS host,
84                            backups.num  AS num,
85                            backups.date AS date,
86                            shares.name  AS share,
87                            backups.size AS backup_size,
88                            backups.inc_size AS compress_size
89                    FROM backups, archive_backup, hosts, shares
90                    WHERE archive_backup.backup_id = backups.id
91                            AND hosts.id=backups.hostid
92                            AND shares.id=backups.shareid
93                            AND archive_backup.archive_id = ?
94            };
95    
96            my $sth = $dbh->prepare("SELECT dvd_nr, total_size, note, username, date,id FROM archive WHERE dvd_nr=?");
97            $sth->execute($dvd_nr);
98            my $row = $sth->fetchrow_hashref();
99    
100            my $row_h;
101            foreach my $hide (qw/id note/) {
102                    $row_h->{$hide} = $row->{$hide} || die "no $hide";
103                    delete $row->{$hide};
104            }
105    
106            $writer->startTag("archive", %{$row});
107    
108            $writer->startTag("note");
109            $writer->characters( $row_h->{'note'} );
110            $writer->endTag("note");
111    
112            my $sth_backups = $dbh->prepare( $backups_sql );
113            $sth_backups->execute( $row_h->{'id'} );
114    
115            while (my $row = $sth_backups->fetchrow_hashref()) {
116    
117                    my $sth_files = $dbh->prepare( $files_sql);
118                    $sth_files->execute($row->{'backup_id'});
119    
120                    delete($row->{'backup_id'});
121                    $row->{'date'} = strftime($t_fmt,gmtime($row->{'date'}));
122    
123                    $writer->startTag( "backup", %{$row} );
124    
125                    while (my $row = $sth_files->fetchrow_hashref()) {
126                            # convert filetype to string
127                            $row->{'type'} = BackupPC::Attrib::fileType2Text(undef, $row->{'type'});
128                            $row->{'date'} = strftime($t_fmt,gmtime($row->{'date'}));
129                            my $path = $row->{'path'}; delete $row->{'path'};
130    
131                            $writer->startTag("file", %{$row});
132                            $writer->characters( $path );
133                            $writer->endTag("file");
134                    }
135                    $writer->endTag("backup");
136            }      
137                            
138            $writer->endTag("archive");
139            $writer->end();
140            
141    }
142    
143    
144    
145  #----- main  #----- main
146    
147  my $sth = $dbh->prepare( qq{  my $sth = $dbh->prepare( qq{
# Line 123  my @archives_to_burn = Menu(\%Menu_archi Line 210  my @archives_to_burn = Menu(\%Menu_archi
210    
211  print "\n";  print "\n";
212    
213    sub skip($) {
214            my $msg = shift;
215            print "WARNING: $msg, skipping...\n";
216            goto SKIP;
217    }
218    
219    my $sth_archive_backup = $dbh->prepare( qq{
220            select
221                    backup_id,
222                    archive_id,
223                    hosts.name as host,
224                    shares.name as share,
225                    backups.num as num
226            from archive_backup
227            join archive on archive_id = archive.id
228            join backups on backup_id = backups.id
229            join hosts on hostid = hosts.id
230            join shares on shareid = shares.id
231            where archive.dvd_nr = ?
232    });
233    
234    my $sth_archive_burned = $dbh->prepare( qq{
235            insert into archive_burned
236                    (archive_id, iso_size)
237            values ( (select id from archive where dvd_nr =?), ?)
238    });
239    
240  foreach my $arc (@archives_to_burn) {  foreach my $arc (@archives_to_burn) {
241          exit if ($arc eq ']quit[');          exit if ($arc eq ']quit[');
242    
243          my $dvd_nr = $1 if ($arc =~ m/DVD #(\d+)/);          my $dvd_nr = $1 if ($arc =~ m/DVD #(\d+)/);
244          die "BUG: can't find dvd_nr in $arc\n" unless ($dvd_nr);          die "BUG: can't find dvd_nr in $arc\n" unless ($dvd_nr);
245    
246          print "Working on DVD #$dvd_nr\n";          my $tmp_dir = "/$iso_dir/$dvd_nr";
247    
248            my $t = time();
249    
250            print "Working on DVD #$dvd_nr in $tmp_dir\n";
251    
252            my $list_file = my $iso_file = my $xml_file = "${iso_dir}/${dvd_nr}";
253            $list_file .= '.list';
254            $iso_file .= '.iso';
255            $xml_file .= '.xml';
256    
257            if (-e $iso_file) {
258                    print "ISO $iso_file allready exists\n";
259                    goto BURN;
260            }
261    
262            $sth_archive_backup->execute($dvd_nr);
263    
264            open(my $list, "> $list_file") || skip "can't open $list_file: $!";
265    
266            my $inc = 0;
267    
268            while (my $row = $sth_archive_backup->fetchrow_hashref) {
269                    my $tar_file = BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'});
270                    skip "can't find increment $tar_file: $!" unless (-r "$tar_dir/$tar_file");
271                    print $list "$tar_dir/$tar_file\n";
272                    $inc++;
273    
274            }
275    
276            # add file list and note in xml
277            dumpArchive2XML($dbh, $dvd_nr, $xml_file);
278            print $list "$xml_file\n";
279    
280            # add css file for archive
281            my $css_file = $Conf{CgiImageDir} . '/archive.css';
282            if (-r $css_file) {
283                    print $list "$css_file\n";
284            } else {
285                    print "WARNING: missing $css_file, not added to iso image!\n";
286            }
287    
288            close($list);
289    
290            print "Running mkisofs now for $inc increments...\n";
291    
292            my $cmd = qq{ mkisofs -A BackupPC -gui -J -r -T --input-charset ISO-8859-2 -V $dvd_nr -o $iso_file -path-list $list_file };
293    
294            system($cmd) == 0 or skip "can't run $cmd: $?";
295    
296            my $size = (stat($iso_file))[7];
297    
298            print "Created $iso_file [$size bytes] in ", fmt_time(time() - $t), "\n";
299    
300    BURN:
301            # FIXME add call to cdrecord here!
302            $sth_archive_burned->execute($dvd_nr, $size);
303            print "Media burn for $dvd_nr recorded\n";
304    
305    SKIP:
306    
307  }  }
308    

Legend:
Removed from v.174  
changed lines
  Added in v.189

  ViewVC Help
Powered by ViewVC 1.1.26