/[BackupPC]/trunk/lib/BackupPC/CGI/BurnMedia.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/BackupPC/CGI/BurnMedia.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 382 - (show annotations)
Mon May 14 08:06:52 2007 UTC (17 years ago) by iklaric
File size: 3564 byte(s)
- fixed bug that occured while calculating total dvd size

1 package BackupPC::CGI::BurnMedia;
2
3 use strict;
4 use BackupPC::CGI::Lib qw(:all);
5 use BackupPC::SearchLib;
6 use Data::Dumper;
7 use vars qw($Cgi %In $MyURL $User %Conf $TopDir $BinDir $bpc);
8
9 my $dsn = $Conf{SearchDSN};
10 my $db_user = $Conf{SearchUser} || '';
11
12 sub action() {
13 my $cont = "";
14 my $title;
15 my $subtitle;
16 my @files;
17
18 my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 0 } );
19
20 BackupPC::CGI::Lib::NewRequest();
21 # $cont = Dumper(%In);
22 if (!defined($In{submitBurner})) {
23 $title = eval(q{ ${h1($Lang->{Burn_media})}});
24 $cont = Dumper(%In);
25 $subtitle = eval(q{ ${h2($Lang->{Burn_media_select})}});
26 $cont = <<EOF;
27
28 $title
29 $subtitle
30
31 EOF
32
33 $cont .= "Backups that have not been archived:<br>";
34 $cont .= BackupPC::SearchLib::displayBackupsGrid( \%In );
35
36 } else {
37
38 my @selected_backup_ids;
39
40 my $total_size = 0;
41 my $selected = 0;
42
43 my $parts = 1;
44 foreach my $key(keys(%In)) {
45 if ($key =~ m/^fcb([0-9]+)_([0-9]+)_([0-9]+)$/gi) {
46
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};
53
54 if ($db_size != $currSize) {
55 $cont .= "NOT EQUAL!: [fs_size:$currSize, db_size:$db_size, backup_id:$backup_id] <br />";
56 }
57
58 if ($currSize > 0) {
59 $total_size += $currSize;
60 }
61 $selected++;
62
63 my ($this_part) = $dbh->selectrow_array("select parts from backups where id = ?", undef, $backup_id);
64 $this_part--;
65 $parts += $this_part;
66 }
67 }
68
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.";
75 } else {
76
77 # create new archive
78 my $sth = $dbh->prepare(q{
79 INSERT INTO archive (
80 id,
81 dvd_nr,
82 note,
83 username,
84 date,
85 total_size
86 ) VALUES (
87 nextVal('archive_id_seq'),
88 nextVal('dvd_nr'),
89 ?,
90 ?,
91 NOW(),
92 ?
93 )
94 });
95
96 $sth->execute($In{'note'}, $User, $total_size);
97
98 foreach my $backup_id (@selected_backup_ids) {
99
100 # link backups with archive
101 my $sth = $dbh->prepare(q{
102 INSERT INTO archive_backup (
103 archive_id, backup_id
104 ) VALUES (
105 (SELECT last_value FROM archive_id_seq), ?
106 )
107 });
108
109 $sth->execute($backup_id);
110
111 $dbh->commit();
112
113 }
114
115 my ($dvd_nr) = $dbh->selectrow_array(qq{
116 select last_value from dvd_nr
117 });
118
119 $dvd_nr ||= 'error';
120
121 $dbh->commit();
122
123 my $db_size = 0;
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};
127 $sth->finish();
128
129 $cont .= q{
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)
134 . q{</b>
135 to media <b>} . $dvd_nr . q{</b>
136 with following message:
137 <div style="background-color: #e0e0e0; display: inline; padding: 2px;">
138 } . $In{'note'} . q{
139 </div>
140 };
141 }
142 }
143
144 Header($Lang->{Burn_media}, "", 1, "", $cont);
145
146 Trailer();
147 $dbh->disconnect();
148 }
149
150 1;

  ViewVC Help
Powered by ViewVC 1.1.26