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{ |
222 |
archive_id, |
archive_id, |
223 |
hosts.name as host, |
hosts.name as host, |
224 |
shares.name as share, |
shares.name as share, |
225 |
backups.num as num, |
backups.num as num |
226 |
from archive_backup |
from archive_backup |
227 |
join archive on archive_id = archive.id |
join archive on archive_id = archive.id |
228 |
join backups on backup_id = backups.id |
join backups on backup_id = backups.id |
249 |
|
|
250 |
print "Working on DVD #$dvd_nr in $tmp_dir\n"; |
print "Working on DVD #$dvd_nr in $tmp_dir\n"; |
251 |
|
|
252 |
my $list_file = my $iso_file = "${iso_dir}/${dvd_nr}"; |
my $list_file = my $iso_file = my $xml_file = "${iso_dir}/${dvd_nr}"; |
253 |
$list_file .= '.list'; |
$list_file .= '.list'; |
254 |
$iso_file .= '.iso'; |
$iso_file .= '.iso'; |
255 |
|
$xml_file .= '.xml'; |
256 |
|
|
257 |
if (-e $iso_file) { |
if (-e $iso_file) { |
258 |
print "ISO $iso_file allready exists\n"; |
print "ISO $iso_file allready exists\n"; |
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"; |
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 }; |
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 }; |