1 package BackupPC::CGI::BurnMedia;
4 use BackupPC::CGI::Lib qw(:all);
5 use BackupPC::SearchLib;
7 use vars qw($Cgi %In $MyURL $User %Conf $TopDir $BinDir $bpc);
9 my $dsn = $Conf{SearchDSN};
10 my $db_user = $Conf{SearchUser} || '';
18 my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 0 } );
20 BackupPC::CGI::Lib::NewRequest();
21 # $cont = Dumper(%In);
22 if (!defined($In{submitBurner})) {
23 $title = eval(q{ ${h1($Lang->{Burn_media})}});
25 $subtitle = eval(q{ ${h2($Lang->{Burn_media_select})}});
33 $cont .= "Backups that have not been archived:<br>";
34 $cont .= BackupPC::SearchLib::displayBackupsGrid( \%In );
38 my @selected_backup_ids;
44 foreach my $key(keys(%In)) {
45 if ($key =~ m/^fcb([0-9]+)_([0-9]+)_([0-9]+)$/gi) {
47 my ($host_id, $backup_num, $backup_id) = ($1,$2,$3);
48 push @selected_backup_ids, $backup_id;
49 my $currSize = BackupPC::SearchLib::getGzipSizeFromBackupID($backup_id);
50 my $sth_size = $dbh->prepare(q{select inc_size from backups where id = ?});
51 $sth_size -> execute( $backup_id );
52 my $db_size = $sth_size->fetchrow_hashref()->{inc_size};
54 if ($db_size != $currSize) {
55 $cont .= "NOT EQUAL!: [fs_size:$currSize, db_size:$db_size, backup_id:$backup_id] <br />";
59 $total_size += $currSize;
63 my ($this_part) = $dbh->selectrow_array("select parts from backups where id = ?", undef, $backup_id);
69 if ($total_size > ($Conf{MaxArchiveSize} * $parts)) {
70 $cont .= eval( q{ ${h2(Error)}});
71 $cont .= "Selected backups size " . sprintf("%1.2f", $total_size / 1024) ." Kb exceed max archive size " . sprintf("%1.2f", $Conf{MaxArchiveSize} / 1024) ." Kb.";
72 } elsif ($total_size == 0) {
73 $cont .= eval( q{ ${h2(Error)}});
74 $cont .= "No backups selected.";
78 my $sth = $dbh->prepare(q{
87 nextVal('archive_id_seq'),
96 $sth->execute($In{'note'}, $User, $total_size);
98 foreach my $backup_id (@selected_backup_ids) {
100 # link backups with archive
101 my $sth = $dbh->prepare(q{
102 INSERT INTO archive_backup (
103 archive_id, backup_id
105 (SELECT last_value FROM archive_id_seq), ?
109 $sth->execute($backup_id);
115 my ($dvd_nr) = $dbh->selectrow_array(qq{
116 select last_value from dvd_nr
124 $sth = $dbh->prepare('SELECT SUM(gzip_size) AS suma FROM backups_on_dvds WHERE dvd_nr=?');
125 $sth->execute($dvd_nr);
126 $db_size = $sth->fetchrow_hashref()->{suma};
130 Archived following backups:
131 } . join(", ", @selected_backup_ids) . q{
132 <br/>with total size of
133 <b>} . sprintf("%1.2f Mb", $total_size / 1024 / 1024)
135 to media <b>} . $dvd_nr . q{</b>
136 with following message:
137 <div style="background-color: #e0e0e0; display: inline; padding: 2px;">
144 Header($Lang->{Burn_media}, "", 1, "", $cont);