show status in ps output by modifing $0
[BackupPC.git] / bin / BackupPC_ASA_SearchUpdate
index 2ce01fc..5615abb 100755 (executable)
@@ -78,6 +78,19 @@ warn "hosts: ",dump( $opt->host );
 
 #---- subs ----
 
+sub status {
+       my $text = shift;
+       $text =~ s{\s+$}{};
+       my $new = $0;
+       $new =~ s{^[\w\/]+/(\w+) }{$1 }; # strip path from process name
+       if ( $text =~ m/^\|/ ) {
+               $new =~ s/\|.*/$text/ or $new .= " $text";
+       } else {
+               $new =~ s/\s+.*/ $text/ or $new .= " $text";
+       }
+       $0 = $new;
+}
+
 sub fmt_time {
        my $t = shift || return;
        my $out = "";
@@ -170,6 +183,7 @@ sub hest_update {
                }
 
                print "$added";
+               status "| $added";
 
                $offset += EST_CHUNK;
 
@@ -440,7 +454,7 @@ INSERT INTO hosts (name, IP) VALUES (?,?)
 });
 
 $sth->{hosts_by_name} = $dbh->prepare(qq{
-SELECT ID FROM hosts WHERE name=?
+SELECT id FROM hosts WHERE name=?
 });
 
 $sth->{backups_count} = $dbh->prepare(qq{
@@ -518,6 +532,7 @@ foreach my $host_key (@hosts) {
                        fmt_time($backup->{endTime} - $backup->{startTime})
                );
                print $share_header unless $opt->quiet;
+               status "$hostname $backupNum $share_header";
 
                my $files = BackupPC::View->new($bpc, $hostname, \@backups, { only_first => 1 });
 
@@ -572,14 +587,17 @@ foreach my $host_key (@hosts) {
                        }
 
                        my $dur = (time() - $t) || 1;
-                       printf(" %d/%d files %d/%d dirs %0.2f MB [%.2f/s dur: %s]\n",
+                       my $status = sprintf("%d/%d files %d/%d dirs %0.2f MB [%.2f/s dur: %s]",
                                $nf, $f, $nd, $d,
                                ($size / 1024 / 1024),
                                ( ($f+$d) / $dur ),
                                fmt_time($dur)
                        );
+                       print " $status\n";
+                       status "$hostname $backupNum $status";
 
                        if ($nf + $nd > 0) {
+                               status "$hostname $backupNum full-text | indexing";
                                eval { hest_update($hostID, $shareID, $backupNum) };
                                warn "ERROR: $@" if $@;
                        }