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"; |
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{ |
219 |
my $sth_archive_backup = $dbh->prepare( qq{ |
my $sth_archive_backup = $dbh->prepare( qq{ |
220 |
select |
select |
221 |
backup_id, |
backup_id, |
222 |
|
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 |
231 |
where archive.dvd_nr = ? |
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 |
|
|
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 $iso_file = "${iso_dir}/${dvd_nr}.iso"; |
my $list_file = my $iso_file = my $xml_file = "${iso_dir}/${dvd_nr}"; |
253 |
|
$list_file .= '.list'; |
254 |
skip "ISO $iso_file allready exists" if (-e $iso_file); |
$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); |
$sth_archive_backup->execute($dvd_nr); |
263 |
|
|
264 |
print "Running mkisofs now...\n"; |
open(my $list, "> $list_file") || skip "can't open $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 - }; |
|
265 |
|
|
266 |
open(my $mkisofs, "| $cmd 2>&1") || skip "can't run $cmd: $!"; |
my $inc = 0; |
267 |
|
|
268 |
while (my $row = $sth_archive_backup->fetchrow_hashref) { |
while (my $row = $sth_archive_backup->fetchrow_hashref) { |
269 |
my $tar_file = BackupPC::SearchLib::getGzipName($row->{'host'}, $row->{'share'}, $row->{'num'}); |
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"); |
skip "can't find increment $tar_file: $!" unless (-r "$tar_dir/$tar_file"); |
271 |
print $mkisofs "$tar_dir/$tar_file\n"; |
print $list "$tar_dir/$tar_file\n"; |
272 |
|
$inc++; |
273 |
|
|
274 |
} |
} |
275 |
|
|
276 |
while(! -e $iso_file) { |
# add file list and note in xml |
277 |
sleep 1; |
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 |
print "Created $iso_file in ", fmt_time(time() - $t), "\n"; |
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: |
SKIP: |
306 |
|
|