added SearchDSN and SearchUser configuration directives. Defaults are
authordpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Sat, 20 Aug 2005 16:40:11 +0000 (16:40 +0000)
committerdpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Sat, 20 Aug 2005 16:40:11 +0000 (16:40 +0000)
probably useful only to me :-)
Added total duration display to BackupPC_updatedb

git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/BackupPC/trunk@51 8392b6e1-25fa-0310-8288-cc32f8e212ea

bin/BackupPC_updatedb
conf/config.pl
lib/BackupPC/SearchLib.pm

index f8a2865..48dcffb 100755 (executable)
@@ -17,6 +17,8 @@ use constant BPC_FTYPE_DIR => 5;
 my $debug = 0;
 $|=1;
 
+my $start_t = time();
+
 my $pidfile = new File::Pid;
 
 if (my $pid = $pidfile->running ) {
@@ -36,11 +38,8 @@ my %Conf = $bpc->Conf();
 my $TopDir = $bpc->TopDir();
 my $beenThere = {};
 
-my $dsn = "dbi:SQLite:dbname=$TopDir/$Conf{SearchDB}";
-my $user = '';
-
-# DEBUG option!
-($dsn,$user) = qw/dbi:Pg:dbname=backuppc dpavlin/;
+my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n";
+my $user = $Conf{SearchUser} || '';
 
 my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 });
 
@@ -156,7 +155,7 @@ if ($opt{d}) {
        }
        print " done...\n";
 
-       eval { $dbh->commit; };
+       $dbh->commit;
 }
 
 if ($opt{v}) {
@@ -279,6 +278,8 @@ undef $sth;
 $dbh->commit();
 $dbh->disconnect();
 
+print "total duration: ",fmt_time(time() - $start_t),"\n";
+
 $pidfile->remove;
 
 sub getShareID() {
index 76be330..ea7a4f2 100644 (file)
@@ -1743,6 +1743,9 @@ $Conf{CgiImageDirURL} = '';
 $Conf{CgiCSSFile} = 'BackupPC_stnd.css';
 
 #
-# add search database using DBD::SQLite which will be created in $TopDir
+# add search database dsn
 #
-$Conf{SearchDB} = 'search.db';
+#$Conf{SearchDSN} = 'dbi:SQLite:dbname=$TopDir/search.db';
+$Conf{SearchDSN} = 'dbi:Pg:dbname=backuppc';
+$Conf{SearchUser} = 'dpavlin';
+
index 3521452..b182e7d 100644 (file)
@@ -5,16 +5,19 @@ use strict;
 use BackupPC::CGI::Lib qw(:all);
 use BackupPC::Attrib qw(:all);
 use DBI;
+use DateTime;
 use vars qw(%In $MyURL);
 
 my $on_page = 100;
 my $pager_pages = 10;
 
+my $dsn = $Conf{SearchDSN};
+my $db_user = $Conf{SearchUser} || '';
+
 sub getUnits() {
     my @ret = ();
     my $tmp;
-    my $dbh = DBI->connect( "dbi:SQLite:dbname=${TopDir}/$Conf{SearchDB}",
-        "", "", { RaiseError => 1, AutoCommit => 1 } );
+    my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );
     my $st =
       $dbh->prepare(
         " SELECT shares.ID AS ID, shares.share AS name FROM shares;");
@@ -27,11 +30,18 @@ sub getUnits() {
     return @ret;
 }
 
+sub epoch_to_iso {
+       my $t = shift || return;
+       my $dt = DateTime->from_epoch( epoch => $t ) || return;
+print STDERR "$t == ",$dt->epoch,"\n";
+       return $dt->ymd . ' ' . $dt->hms;
+}
+
 sub getWhere($) {
        my ($param)    = @_;
        my @conditions;
 
-       sub mk_iso_date($$) {
+       sub mk_epoch_date($$) {
                my ($name,$suffix) = @_;
 
                my $yyyy = $param->{ $name . '_year_' . $suffix} || return;
@@ -39,18 +49,23 @@ sub getWhere($) {
                        ( $suffix eq 'from' ? 1 : 12);
                my $dd .= $param->{ $name . '_day_' . $suffix} ||
                        ( $suffix eq 'from' ? 1 : 31);
-               return sprintf("%04d-%02d-%02d", $yyyy, $mm, $dd);
+               my $dt = new DateTime(
+                       year => $yyyy,
+                       month => $mm,
+                       day => $dd
+               );
+               return $dt->epoch || 'NULL';
        }
 
-       my $backup_from = mk_iso_date('search_backup', 'from');
-       push @conditions, qq{ date(backups.date, 'unixepoch','localtime') >= '$backup_from' } if ($backup_from);
-       my $backup_to = mk_iso_date('search_backup', 'to');
-       push @conditions, qq{ date(backups.date, 'unixepoch','localtime') <= '$backup_to' } if ($backup_to);
+       my $backup_from = mk_epoch_date('search_backup', 'from');
+       push @conditions, qq{ backups.date >= $backup_from } if ($backup_from);
+       my $backup_to = mk_epoch_date('search_backup', 'to');
+       push @conditions, qq{ backups.date <= $backup_to } if ($backup_to);
 
-       my $files_from = mk_iso_date('search', 'from');
-       push @conditions, qq{ date(files.date, 'unixepoch','localtime') >= '$files_from' } if ($files_from);
-       my $files_to = mk_iso_date('search', 'to');
-       push @conditions, qq{ date(files.date, 'unixepoch','localtime') <= '$files_to' } if ($files_to);
+       my $files_from = mk_epoch_date('search', 'from');
+       push @conditions, qq{ files.date >= $files_from } if ($files_from);
+       my $files_to = mk_epoch_date('search', 'to');
+       push @conditions, qq{ files.date <= $files_to } if ($files_to);
 
        print STDERR "backup: $backup_from - $backup_to files: $files_from - $files_to cond:",join(" | ",@conditions);
     
@@ -69,8 +84,7 @@ sub getWhere($) {
 sub getFiles($$) {
        my ($where, $offset) = @_;
 
-       my $dbh = DBI->connect( "dbi:SQLite:dbname=${TopDir}/$Conf{SearchDB}",
-               "", "", { RaiseError => 1, AutoCommit => 1 } );
+       my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );
 
        my $sql_cols = qq{
                files.id                        AS fid,
@@ -81,7 +95,7 @@ sub getFiles($$) {
                files.name                      AS filename,
                files.path                      AS filepath,
                shares.share||files.fullpath    AS networkPath,
-               date(files.date, 'unixepoch', 'localtime') AS date,
+               files.date                      AS date,
                files.type                      AS filetype,
                files.size                      AS size,
                dvds.name                       AS dvd
@@ -122,10 +136,10 @@ sub getFiles($$) {
                        'hname'         => $row->{'hname'}, 
                        'sname'         => $row->{'sname'},
                        'sharename'     => $row->{'sharename'},
-                       'backupno'      => $row->{'backupNum'},
+                       'backupno'      => $row->{'backupnum'},
                        'fname'         => $row->{'filename'},
                        'fpath'         => $row->{'filepath'},
-                       'networkpath'   => $row->{'networkPath'},
+                       'networkpath'   => $row->{'networkpath'},
                        'date'          => $row->{'date'},
                        'type'          => $row->{'filetype'},
                        'size'          => $row->{'size'},
@@ -139,10 +153,9 @@ sub getFiles($$) {
        return ($results, \@ret);
 }
 
-sub getBackupsNotBurned()
-  {
-      my $dbh = DBI->connect( "dbi:SQLite:dbname=${TopDir}/$Conf{SearchDB}",
-        "", "", { RaiseError => 1, AutoCommit => 1 } );      
+sub getBackupsNotBurned() {
+
+       my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );
       my $sql = q{ 
          SELECT
            hosts.ID         AS hostID,
@@ -242,7 +255,7 @@ EOF3
                $retHTML .= '<td class="fviewborder">' . $backup->{'host'} . '</td>' .
                        '<td class="fviewborder">' . $backup->{'backupno'} . '</td>' .
                        '<td class="fviewborder">' . $backup->{'type'} . '</td>' .
-                       '<td class="fviewborder">' . $backup->{'date'} . '<td>' .
+                       '<td class="fviewborder">' . epoch_to_iso( $backup->{'date'} ) . '<td>' .
                        '</tr>';
        }
 
@@ -308,7 +321,7 @@ sub displayGrid($$$$) {
                        $typeStr,
                        restore_link( $typeStr, $file->{'hname'}, $file->{'backupno'}, $file->{'sname'}, $file->{'fpath'}, $file->{'backupno'} ),
                        $file->{'size'},
-                       $file->{'date'},
+                       epoch_to_iso( $file->{'date'} ),
                        $file->{'dvd'}
                )) {
                        $retHTML .= qq{<td class="fviewborder">$v</td>};