/[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 380 - (show annotations)
Wed May 9 07:07:02 2007 UTC (17 years ago) by iklaric
File size: 3052 byte(s)
- fixed problem with determining file size of tgz on disk: if there is no file, it's size is declared as zero than

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 print LOG "doing $key...";
46 if ($key =~ m/^fcb([0-9]+)_([0-9]+)_([0-9]+)$/gi) {
47
48 my ($host_id, $backup_num, $backup_id) = ($1,$2,$3);
49 push @selected_backup_ids, $backup_id;
50 my $currSize = BackupPC::SearchLib::getGzipSize($host_id, $backup_num);
51 if ($currSize > 0) {
52 $total_size += currSize;
53 }
54 $selected++;
55
56 my ($this_part) = $dbh->selectrow_array("select parts from backups where id = ?", undef, $backup_id);
57 $this_part--;
58 $parts += $this_part;
59 } }
60
61 if ($total_size > ($Conf{MaxArchiveSize} * $parts)) {
62 $cont .= eval( q{ ${h2(Error)}});
63 $cont .= "Selected backups size " . sprintf("%1.2f", $total_size / 1024) ." Kb exceed max archive size " . sprintf("%1.2f", $Conf{MaxArchiveSize} / 1024) ." Kb.";
64 } elsif ($total_size == 0) {
65 $cont .= eval( q{ ${h2(Error)}});
66 $cont .= "No backups selected.";
67 } else {
68
69 # create new archive
70 my $sth = $dbh->prepare(q{
71 INSERT INTO archive (
72 id,
73 dvd_nr,
74 note,
75 username,
76 date,
77 total_size
78 ) VALUES (
79 nextVal('archive_id_seq'),
80 nextVal('dvd_nr'),
81 ?,
82 ?,
83 NOW(),
84 ?
85 )
86 });
87
88 $sth->execute($In{'note'}, $User, $total_size);
89
90 foreach my $backup_id (@selected_backup_ids) {
91
92 # link backups with archive
93 my $sth = $dbh->prepare(q{
94 INSERT INTO archive_backup (
95 archive_id, backup_id
96 ) VALUES (
97 (SELECT last_value FROM archive_id_seq), ?
98 )
99 });
100
101 $sth->execute($backup_id);
102
103 $dbh->commit();
104
105 }
106
107 my ($dvd_nr) = $dbh->selectrow_array(qq{
108 select last_value from dvd_nr
109 });
110
111 $dvd_nr ||= 'error';
112
113 $dbh->commit();
114
115 $cont .= q{
116 Archived following backups:
117 } . join(", ", @selected_backup_ids) . q{
118 <br/>with total size of
119 <b>} . sprintf("%1.2f Mb", $total_size / 1024 / 1024) . q{</b>
120 to media <b>} . $dvd_nr . q{</b>
121 with following message:
122 <div style="background-color: #e0e0e0; display: inline; padding: 2px;">
123 } . $In{'note'} . q{
124 </div>
125 };
126 }
127 }
128
129 Header($Lang->{Burn_media}, "", 1, "", $cont);
130
131 Trailer();
132 $dbh->disconnect();
133 }
134
135 1;

  ViewVC Help
Powered by ViewVC 1.1.26