X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=lib%2FBackupPC%2FCGI%2FBurnMedia.pm;fp=lib%2FBackupPC%2FCGI%2FBurnMedia.pm;h=8f29a079eb9a8cac45ceaf2c02431dcbcdcbc218;hp=0000000000000000000000000000000000000000;hb=ee499dda4d49dfa4d0b51e158c35a565178efde8;hpb=616bb26f808471664882eafc006751b4b68efc25 diff --git a/lib/BackupPC/CGI/BurnMedia.pm b/lib/BackupPC/CGI/BurnMedia.pm new file mode 100644 index 0000000..8f29a07 --- /dev/null +++ b/lib/BackupPC/CGI/BurnMedia.pm @@ -0,0 +1,150 @@ +package BackupPC::CGI::BurnMedia; + +use strict; +use BackupPC::CGI::Lib qw(:all); +use BackupPC::SearchLib; +use Data::Dumper; +use vars qw($Cgi %In $MyURL $User %Conf $TopDir $BinDir $bpc); + +my $dsn = $Conf{SearchDSN}; +my $db_user = $Conf{SearchUser} || ''; + +sub action() { + my $cont = ""; + my $title; + my $subtitle; + my @files; + + my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 0 } ); + + BackupPC::CGI::Lib::NewRequest(); +# $cont = Dumper(%In); + if (!defined($In{submitBurner})) { + $title = eval(q{ ${h1($Lang->{Burn_media})}}); + $cont = Dumper(%In); + $subtitle = eval(q{ ${h2($Lang->{Burn_media_select})}}); + $cont = <prepare(q{select inc_size from backups where id = ?}); + $sth_size -> execute( $backup_id ); + my $db_size = $sth_size->fetchrow_hashref()->{inc_size}; + + if ($db_size != $currSize) { + $cont .= "NOT EQUAL!: [fs_size:$currSize, db_size:$db_size, backup_id:$backup_id]
"; + } + + if ($currSize > 0) { + $total_size += $currSize; + } + $selected++; + + my ($this_part) = $dbh->selectrow_array("select parts from backups where id = ?", undef, $backup_id); + $this_part--; + $parts += $this_part; + } + } + + if ($total_size > ($Conf{MaxArchiveSize} * $parts)) { + $cont .= eval( q{ ${h2(Error)}}); + $cont .= "Selected backups size " . sprintf("%1.2f", $total_size / 1024) ." Kb exceed max archive size " . sprintf("%1.2f", $Conf{MaxArchiveSize} / 1024) ." Kb."; + } elsif ($total_size == 0) { + $cont .= eval( q{ ${h2(Error)}}); + $cont .= "No backups selected."; + } else { + + # create new archive + my $sth = $dbh->prepare(q{ + INSERT INTO archive ( + id, + dvd_nr, + note, + username, + date, + total_size + ) VALUES ( + nextVal('archive_id_seq'), + nextVal('dvd_nr'), + ?, + ?, + NOW(), + ? + ) + }); + + $sth->execute($In{'note'}, $User, $total_size); + + foreach my $backup_id (@selected_backup_ids) { + + # link backups with archive + my $sth = $dbh->prepare(q{ + INSERT INTO archive_backup ( + archive_id, backup_id + ) VALUES ( + (SELECT last_value FROM archive_id_seq), ? + ) + }); + + $sth->execute($backup_id); + + $dbh->commit(); + + } + + my ($dvd_nr) = $dbh->selectrow_array(qq{ + select last_value from dvd_nr + }); + + $dvd_nr ||= 'error'; + + $dbh->commit(); + + my $db_size = 0; + $sth = $dbh->prepare('SELECT SUM(gzip_size) AS suma FROM backups_on_dvds WHERE dvd_nr=?'); + $sth->execute($dvd_nr); + $db_size = $sth->fetchrow_hashref()->{suma}; + $sth->finish(); + + $cont .= q{ + Archived following backups: + } . join(", ", @selected_backup_ids) . q{ +
with total size of + } . sprintf("%1.2f Mb", $total_size / 1024 / 1024) + . q{ + to media } . $dvd_nr . q{ + with following message: +
+ } . $In{'note'} . q{ +
+ }; + } + } + + Header($Lang->{Burn_media}, "", 1, "", $cont); + + Trailer(); + $dbh->disconnect(); +} + +1;