--- trunk/bin/BackupPC_burnArchiveCLI 2005/10/11 18:32:27 176 +++ trunk/bin/BackupPC_burnArchiveCLI 2005/10/13 15:11:58 193 @@ -1,9 +1,7 @@ -#!/usr/local/bin/perl +#!/usr/bin/perl use strict; -#use lib "__INSTALLDIR__/lib"; -# FIXME -use lib "/data/backuppc/lib"; +use lib "__INSTALLDIR__/lib"; use DBI; use BackupPC::Lib; @@ -55,6 +53,93 @@ return strftime($t_fmt,localtime()); } +sub dumpArchive2XML($$$) +{ + my ($dbh, $dvd_nr, $filename) = @_; + my %archive; + my $output = new IO::File(">$filename"); + my $writer = new XML::Writer(OUTPUT=>$output, NEWLINES => 1); + + $writer->pi('xml-stylesheet', 'href="archive.css" type="text/css"'); + + my $files_sql = q{ + SELECT + files.path AS path, + files.date AS date, + files.type AS type, + files.size AS size + FROM files, backups, shares + WHERE files.backupnum=backups.num AND + files.shareid=shares.id AND + shares.hostid=backups.hostid AND + backups.id=? + }; + + my $backups_sql = q{ + SELECT + backups.id AS backup_id, + hosts.name AS host, + backups.num AS num, + backups.date AS date, + shares.name AS share, + backups.size AS backup_size, + backups.inc_size AS compress_size + FROM backups, archive_backup, hosts, shares + WHERE archive_backup.backup_id = backups.id + AND hosts.id=backups.hostid + AND shares.id=backups.shareid + AND archive_backup.archive_id = ? + }; + + my $sth = $dbh->prepare("SELECT dvd_nr, total_size, note, username, date,id FROM archive WHERE dvd_nr=?"); + $sth->execute($dvd_nr); + my $row = $sth->fetchrow_hashref(); + + my $row_h; + foreach my $hide (qw/id note/) { + $row_h->{$hide} = $row->{$hide} || die "no $hide"; + delete $row->{$hide}; + } + + $writer->startTag("archive", %{$row}); + + $writer->startTag("note"); + $writer->characters( $row_h->{'note'} ); + $writer->endTag("note"); + + my $sth_backups = $dbh->prepare( $backups_sql ); + $sth_backups->execute( $row_h->{'id'} ); + + while (my $row = $sth_backups->fetchrow_hashref()) { + + my $sth_files = $dbh->prepare( $files_sql); + $sth_files->execute($row->{'backup_id'}); + + delete($row->{'backup_id'}); + $row->{'date'} = strftime($t_fmt,gmtime($row->{'date'})); + + $writer->startTag( "backup", %{$row} ); + + while (my $row = $sth_files->fetchrow_hashref()) { + # convert filetype to string + $row->{'type'} = BackupPC::Attrib::fileType2Text(undef, $row->{'type'}); + $row->{'date'} = strftime($t_fmt,gmtime($row->{'date'})); + my $path = $row->{'path'}; delete $row->{'path'}; + + $writer->startTag("file", %{$row}); + $writer->characters( $path ); + $writer->endTag("file"); + } + $writer->endTag("backup"); + } + + $writer->endTag("archive"); + $writer->end(); + +} + + + #----- main my $sth = $dbh->prepare( qq{ @@ -135,7 +220,7 @@ archive_id, hosts.name as host, shares.name as share, - backups.num as num, + backups.num as num from archive_backup join archive on archive_id = archive.id join backups on backup_id = backups.id @@ -162,9 +247,10 @@ print "Working on DVD #$dvd_nr in $tmp_dir\n"; - my $list_file = my $iso_file = "${iso_dir}/${dvd_nr}"; + my $list_file = my $iso_file = my $xml_file = "${iso_dir}/${dvd_nr}"; $list_file .= '.list'; $iso_file .= '.iso'; + $xml_file .= '.xml'; if (-e $iso_file) { print "ISO $iso_file allready exists\n"; @@ -185,6 +271,20 @@ } + # add file list and note in xml + dumpArchive2XML($dbh, $dvd_nr, $xml_file); + print $list "$xml_file\n"; + + # add css file for archive + my $css_file = $Conf{CgiImageDir} . '/archive.css'; + if (-r $css_file) { + print $list "$css_file\n"; + } else { + print "WARNING: missing $css_file, not added to iso image!\n"; + } + + close($list); + print "Running mkisofs now for $inc increments...\n"; 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 };