added -q option to supress output for hosts which aren't changed
authordpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Sun, 29 Jan 2006 14:54:17 +0000 (14:54 +0000)
committerdpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Sun, 29 Jan 2006 14:54:17 +0000 (14:54 +0000)
(useful for invocation from cron -- this produces report of hosts
processed)

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

bin/BackupPC_updatedb

index 074d4da..309bcd5 100755 (executable)
@@ -58,7 +58,7 @@ my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 });
 
 my %opt;
 
-if ( !getopts("cdm:v:ijf", \%opt ) ) {
+if ( !getopts("cdm:v:ijfq", \%opt ) ) {
        print STDERR <<EOF;
 usage: $0 [-c|-d] [-m num] [-v|-v level] [-i|-j|-f]
 
@@ -70,6 +70,7 @@ Options:
        -i      update Hyper Estraier full text index
        -j      update full text, don't check existing files
        -f      don't do anything with full text index
+       -q      be quiet for hosts without changes
 
 Option -j is variation on -i. It will allow faster initial creation
 of full-text index from existing database.
@@ -462,14 +463,18 @@ foreach my $host_key (@hosts) {
        }
 
        $host_nr++;
-       print "host ", $hosts->{$host_key}->{'host'}, " [", 
-               $host_nr, "/", ($#hosts + 1), "]: ";
        # get backups for a host
        my @backups = $bpc->BackupInfoRead($hostname);
        my $incs = scalar @backups;
-       print  "$incs increments\n";
 
+       my $host_header = sprintf("host %s [%d/%d]: %d increments\n",
+               $hosts->{$host_key}->{'host'},
+               $host_nr,
+               ($#hosts + 1),
+               $incs
+       );
+       print $host_header unless ($opt{q});
        my $inc_nr = 0;
        $beenThere = {};
 
@@ -481,7 +486,7 @@ foreach my $host_key (@hosts) {
                my $backupNum = $backup->{'num'};
                my @backupShares = ();
 
-               printf("%-10s %2d/%-2d #%-2d %s %5s/%5s files (date: %s dur: %s)\n", 
+               my $share_header = sprintf("%-10s %2d/%-2d #%-2d %s %5s/%5s files (date: %s dur: %s)\n", 
                        $hosts->{$host_key}->{'host'},
                        $inc_nr, $incs, $backupNum, 
                        $backup->{type} || '?',
@@ -489,6 +494,7 @@ foreach my $host_key (@hosts) {
                        strftime($t_fmt,localtime($backup->{startTime})),
                        fmt_time($backup->{endTime} - $backup->{startTime})
                );
+               print $share_header unless ($opt{q});
 
                my $files = BackupPC::View->new($bpc, $hostname, \@backups, 1);
                foreach my $share ($files->shareList($backupNum)) {
@@ -502,6 +508,15 @@ foreach my $host_key (@hosts) {
                        # skip if allready in database!
                        next if ($count > 0);
 
+                       # dump host and share header for -q
+                       if ($opt{q}) {
+                               if ($host_header) {
+                                       print $host_header;
+                                       $host_header = undef;
+                               }
+                               print $share_header;
+                       }
+
                        # dump some log
                        print curr_time," ", $share;