display all backups which we don't know state of in web interface
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 28 Jan 2011 21:40:17 +0000 (22:40 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 28 Jan 2011 21:40:17 +0000 (22:40 +0100)
lib/BackupPC/CGI/Archive.pm

index cbf5f63..6be934c 100644 (file)
@@ -61,6 +61,8 @@ sub action
             my($fullDur, $incrCnt, $fullSize, $fullRate);
             my @Backups = $bpc->BackupInfoRead($host);
             my $fullCnt = $incrCnt = 0;
             my($fullDur, $incrCnt, $fullSize, $fullRate);
             my @Backups = $bpc->BackupInfoRead($host);
             my $fullCnt = $incrCnt = 0;
+            my $all_backup_numbers;
+
             for ( my $i = 0 ; $i < @Backups ; $i++ ) {
                 if ( $Backups[$i]{type} eq "full" ) {
                     $fullSize = $Backups[$i]{size} / (1024 * 1024);
             for ( my $i = 0 ; $i < @Backups ; $i++ ) {
                 if ( $Backups[$i]{type} eq "full" ) {
                     $fullSize = $Backups[$i]{size} / (1024 * 1024);
@@ -69,6 +71,7 @@ sub action
                     $incrSizeTot = $Backups[$i]{size} / (1024 * 1024);
                 }
                 $backupnumber = $Backups[$i]{num};
                     $incrSizeTot = $Backups[$i]{size} / (1024 * 1024);
                 }
                 $backupnumber = $Backups[$i]{num};
+               $all_backup_numbers->{$backupnumber}++;
             }
             $fullSizeTot += $fullSize + $incrSizeTot;
             $fullSize = sprintf("%.2f", ($fullSize + $incrSizeTot) / 1000);
             }
             $fullSizeTot += $fullSize + $incrSizeTot;
             $fullSize = sprintf("%.2f", ($fullSize + $incrSizeTot) / 1000);
@@ -76,17 +79,39 @@ sub action
                $bpc->ConfigRead($archHost);
                %Conf = $bpc->Conf();
 
                $bpc->ConfigRead($archHost);
                %Conf = $bpc->Conf();
 
+use Data::Dump qw(dump);
+
                my $dbh = DBI->connect($Conf{SearchDSN}, $Conf{SearchUser}, "", { RaiseError => 1, AutoCommit => 0 });
                my $dbh = DBI->connect($Conf{SearchDSN}, $Conf{SearchUser}, "", { RaiseError => 1, AutoCommit => 0 });
-               my $backup_nums = $dbh->selectcol_arrayref(qq{
+               my $sth = $dbh->prepare(qq{
                        select
                        select
-                               backups.num as num
+                               backups.num as num,
+                               inc_size,
+                               size,
+                               inc_deleted
                        from backups
                        join hosts on hosts.id = hostid
                        from backups
                        join hosts on hosts.id = hostid
-                       where hosts.name = ? and inc_size < 0 and size > 0 and not inc_deleted
-               }, {}, $host);
+                       where hosts.name = ?
+               });
+               $sth->execute($host);
+               # and inc_size < 0 and size > 0 and not inc_deleted
+               while( my $row = $sth->fetchrow_hashref ) {
+warn "# row ",dump $row;
+                       $all_backup_numbers->{ $row->{num} } =
+                       $row->{inc_deleted}  ? 0 :
+                       $row->{size}    == 0 ? 0 :
+                       $row->{inc_size} < 0 ? 1 :
+                       $row->{size}     > 0 ? 1 :
+                       0;
+               }
+
+warn dump($all_backup_numbers);
+               my @backup_nums = 
+                       sort
+                       grep { $all_backup_numbers->{$_} }
+                       keys %$all_backup_numbers;
 
                my $checkboxes;
 
                my $checkboxes;
-               foreach my $backupnumber ( sort @$backup_nums ) {
+               foreach my $backupnumber ( @backup_nums ) {
                        $checkboxes .= qq|
 <input type="hidden" name="fcb$checkBoxCnt" value="$host">
 <input type="checkbox" name="backup$checkBoxCnt" value="$backupnumber">$backupnumber
                        $checkboxes .= qq|
 <input type="hidden" name="fcb$checkBoxCnt" value="$host">
 <input type="checkbox" name="backup$checkBoxCnt" value="$backupnumber">$backupnumber