Index: /branches/haf_branches/ipp.rsync.20101015/ippScripts/Build.PL
===================================================================
--- /branches/haf_branches/ipp.rsync.20101015/ippScripts/Build.PL	(revision 29525)
+++ /branches/haf_branches/ipp.rsync.20101015/ippScripts/Build.PL	(revision 29526)
@@ -64,4 +64,5 @@
         scripts/minidvodb_createdb.pl
         scripts/minidvodb_merge.pl
+        scripts/minidvodb_copy.pl
         scripts/ippdb.pl
         scripts/ipp_cleanup.pl
Index: /branches/haf_branches/ipp.rsync.20101015/ippScripts/scripts/minidvodb_copy.pl
===================================================================
--- /branches/haf_branches/ipp.rsync.20101015/ippScripts/scripts/minidvodb_copy.pl	(revision 29526)
+++ /branches/haf_branches/ipp.rsync.20101015/ippScripts/scripts/minidvodb_copy.pl	(revision 29526)
@@ -0,0 +1,219 @@
+#!/usr/bin/env perl
+
+use warnings;
+use strict;
+use Carp;
+ 
+## report the program and machine
+use Sys::Hostname;
+my $host = hostname();
+print "\n\n";
+print "Starting script $0 on $host\n\n";
+
+use DateTime;
+my $mjd_start = DateTime->now->mjd;   
+
+my $dtime;
+use IPC::Cmd 0.36 qw( can_run run );
+use PS::IPP::Metadata::Config;
+use PS::IPP::Metadata::List qw( parse_md_list );
+use PS::IPP::Config 1.01 qw( :standard );
+use File::Temp qw( tempfile );
+
+use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
+use Pod::Usage qw( pod2usage );
+
+# Look for programs we need
+my $missing_tools;
+my $rsync = can_run('rsync') or (warn "Can't find rsync" and $missing_tools = 1);
+my $minidvodbtool = can_run('minidvodbtool') or (warn "Can't find minidvodbtool" and $missing_tools = 1);
+my $ssh = can_run('ssh') or (warn "Can't find ssh" and $missing_tools = 1);
+my $df = can_run('df') or (warn "Can't find df" and $missing_tools = 1);
+
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
+
+
+
+my ( $minidvodbcopy_id, $minidvodb_id, $minidvodbrun_path, $minidvodb_rsync_path, $destination_host, $dbname,$verbose, $logfile, $no_op, $redirect, $save_temps);
+GetOptions(
+    'minidvodbcopy_id|w=s'     => \$minidvodbcopy_id, #minidvodb database
+    'minidvodb_id|w=s'  => \$minidvodb_id, #minidvodb_id
+    'minidvodbrun_path|w=s'  => \$minidvodbrun_path, #minidvodb_id
+    'minidvodb_rsync_path|w=s' => \$minidvodb_rsync_path,
+    'destination_host|w=s' => \$destination_host, 
+    'dbname|d=s'        => \$dbname, # Database name
+    'verbose'           => \$verbose,   # Print to stdout
+    'no-op'             => \$no_op, # Don't do any operations?
+    'logfile=s'         => \$logfile,
+    'save-temps'        => \$save_temps, # Save temporary files?
+    ) or pod2usage( 2 );
+
+pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
+pod2usage(
+          -msg => "Required options: --minidvodbcopy_id --minidvodb_rsync_path --minidvodbrun_path --destination_host",
+          -exitval => 3,
+          ) unless
+    defined $minidvodbcopy_id and
+    defined $minidvodb_rsync_path and
+    defined $minidvodbrun_path and
+    defined $destination_host;
+
+
+
+my $ipprc = PS::IPP::Config->new();
+
+my @df;
+
+
+if ($logfile) {
+    $ipprc->redirect_output($logfile) or my_die( "Unable to redirect output", $minidvodbcopy_id, $PS_EXIT_SYS_ERROR );
+    print "\n\n";
+    print "Starting script $0 on $host\n\n";
+    print "COMMAND IS: @ARGV\n\n";
+}
+
+
+{ #can we rsync?
+
+    my $sizes = `du -sk $minidvodbrun_path`;
+    my $total = 0;
+    for(split /[\r\n]+/,$sizes) # split on one or more newline characters
+    { 
+	my($number,$file) = split /\t/,$_,2; # split on tab ($file not used here)
+	$total += $number; 
+    }
+#print 'Total: '.$total;
+{    
+    print "Checking available diskspace on $destination_host\n\n";
+
+    my $command = "$ssh $destination_host df $minidvodb_rsync_path";
+    print "$command\n\n";
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+	run(command => $command, verbose => $verbose);
+    unless ($success) {
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to perform '$ssh $destination_host df $minidvodb_rsync_path' $error_code", $minidvodbcopy_id, $error_code);
+    }
+
+    my @fullbuf= split(/\n/, @{$stdout_buf}[0]);
+    #   print $#{$stdout_buf};
+#     print "xx $#df xx";
+#    print $fullbuf[0];
+    if ($#fullbuf ==1 ) {
+#	print $fullbuf[1];
+ 	@df = split /\s+/, $fullbuf[1];
+	if ($#df == 5) {
+#	    
+	    #print $df[3], $df[4];
+	    
+	    $df[4]=~ s/\%//;
+
+	    if ($df[4] <  97 && $df[3]-$total) {
+		print "\nThere is enough available space ($total < $df[3]) for the rsync\n";
+	    } else {
+		&my_die("Not enough available disk space: $df[4]% available, $df[3] on destination, $total free required for copy", $minidvodbcopy_id, $PS_EXIT_PROG_ERROR);
+	    }
+#	    
+
+	} else {
+	    &my_die("Cannot parse df:\n@{$full_buf}[0]\nCan't figure out %free or available", $minidvodbcopy_id, $PS_EXIT_PROG_ERROR); 
+	} 
+    } else {
+	&my_die("Cannot parse df:\n@{$full_buf}[0]\nToo many lines ($#fullbuf) vs 1", $minidvodbcopy_id, $PS_EXIT_PROG_ERROR);
+    }
+}
+}
+
+{#do the rsync
+    my $command = "$rsync -rvuaq";
+    $command .= " $minidvodbrun_path";
+    $command .= " $destination_host";
+    $command .= "2:$minidvodb_rsync_path";
+    print "\nPerforming rsync:\n";
+    print "$command\n\n";
+my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbose);
+    unless ($success) {
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to perform rsync: $error_code", $minidvodbcopy_id, $error_code);
+    }
+    
+    print "Rsync complete..\n";
+
+}
+
+{#update the database
+    $dtime = 86400.0*(DateTime->now->mjd - $mjd_start);
+
+    my $command = "$minidvodbtool -updateminidvodbcopy -minidvodbcopy_id $minidvodbcopy_id";
+    $command .= " -set_state full -set_dtime $dtime";
+    $command .= " -dbname $dbname" if defined $dbname;
+    print "$command\n";
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+	run(command => $command, verbose => $verbose);
+    unless ($success) {
+        $error_code = 20;
+        &my_die("Unable to update database - rsync completed without error' $error_code", $minidvodbcopy_id, $error_code);
+    }
+
+}
+
+
+
+
+
+
+
+
+
+#if ($logfile) {
+#    $ipprc->redirect_output($logfile) or my_die( "Unable to redirect output", $minidvodbcopy_id, $PS_EXIT_SYS_ERROR );
+#    print "\n\n";
+#    print "Starting script $0 on $host\n\n";
+#    print "COMMAND IS: @ARGV\n\n";
+#}
+
+
+
+
+exit 0;
+
+
+
+sub my_die
+{
+    my $msg = shift; # Warning message on die
+    my $minidbvodbcopy_id = shift;
+    my $exit_code = shift; # Exit code to add
+
+    print STDERR "$msg $minidvodbcopy_id\n";
+
+if (defined $minidvodb_id ) {
+
+    my $command = "minidvodbtool  -updateminidvodbcopy -minidvodbcopy_id $minidvodbcopy_id";
+   
+        $command .= " -set_fault $exit_code";
+        $command .= " -set_dtime $dtime" if defined $dtime;
+        $command .= " -dbname $dbname" if defined $dbname;
+
+
+
+    print $command;
+    system ($command);
+    }
+
+
+
+
+
+
+
+    $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code;
+
+    exit $exit_code;
+}
+
+__END__
Index: /branches/haf_branches/ipp.rsync.20101015/ippTasks/Makefile.am
===================================================================
--- /branches/haf_branches/ipp.rsync.20101015/ippTasks/Makefile.am	(revision 29525)
+++ /branches/haf_branches/ipp.rsync.20101015/ippTasks/Makefile.am	(revision 29526)
@@ -34,4 +34,5 @@
 	science.cleanup.pro \
 	minidvodb.pro \
+	minidvodbcopy.pro \
 	nightly_stacks.pro \
 	burntool.pro \
Index: /branches/haf_branches/ipp.rsync.20101015/ippTasks/minidvodbcopy.pro
===================================================================
--- /branches/haf_branches/ipp.rsync.20101015/ippTasks/minidvodbcopy.pro	(revision 29526)
+++ /branches/haf_branches/ipp.rsync.20101015/ippTasks/minidvodbcopy.pro	(revision 29526)
@@ -0,0 +1,430 @@
+## addstar.pro : globals and support macros : -*- sh -*-
+## this file contains the tasks for running the addstar analysis stage
+## these tasks use the book addPendingExp
+
+# test for required global variables
+check.globals
+
+
+#There is a book for each task, because I don't use labels. 
+
+if (not($?haveBooks))
+ book create MINIDVODB_COPY
+ book create MINIDVODB_HOST
+ $haveBooks = TRUE
+end
+
+$MINIDVODBCOPY_DB = 0
+$MINIDVODB_HOSTS_DB = 0
+
+book init minidvodbCopylist
+
+macro minidvodb.copy.status
+  book listbook minidvodbCopylist
+end
+
+macro minidvodb.copy.reset
+  book init minidvodbCopylist
+end
+
+#this is the task that manages the copying of minidvodbs to another machine
+macro minidvodb.copy.on
+    task minidvodb.copy.load
+    active true
+  end
+    task minidvodb.copy.run
+    active true
+  end
+    task minidvodb.copy.queue
+    active true
+  end
+end
+
+macro minidvodb.copy.queue.on
+    task minidvodb.copy.queue
+    active true
+  end
+end
+
+macro minidvodb.copy.queue.off   
+    task minidvodb.copy.queue
+    active false
+   end
+end
+
+macro minidvodb.copy.load.on
+    task minidvodb.copy.load
+    active true
+    end
+end
+
+macro minidvodb.copy.load.off
+    task minidvodb.copy.load
+    active false
+    end
+end
+
+macro minidvodb.copy.run.on
+    task minidvodb.copy.run
+    active true
+    end
+end
+
+macro minidvodb.copy.run.off
+    task minidvodb.copy.run
+    active false
+    end
+end
+
+macro minidvodb.copy.off
+   task minidvodb.copy.load
+    active false
+  end
+   task minidvodb.copy.run
+    active false
+  end
+   task minidvodb.copy.queue
+    active false
+  end
+end
+
+
+## you get no choice - you add all of them in at the same time. you can always turn off the tasks you don't want to run.
+macro add.minidvodb.copy
+  if ($0 != 4)
+    echo "USAGE: add.minidvodb.copy (minidvodb_group) (host) (minidvodbcopy_path)"
+    break
+  end
+  $hostandgroup = $2.$1
+  #wait - shoudl be renamed MINIDVODB_WAIT
+  book newpage MINIDVODB_COPY $hostandgroup
+  book setword MINIDVODB_COPY $hostandgroup MINIDVODBHOSTANDGROUP $hostandgroup
+  book setword MINIDVODB_COPY $hostandgroup MINIDVODB_GROUP $1
+  book setword MINIDVODB_COPY $hostandgroup HOST $2
+  book setword MINIDVODB_COPY $hostandgroup MINIDVODB_COPY_PATH $3
+  book setword MINIDVODB_COPY $hostandgroup STATE PENDING
+  book setword MINIDVODB_COPY $hostandgroup QUEUE_STATE PENDING
+end 
+
+macro del.minidvodb.copy
+  if ($0 != 3)
+    echo "USAGE: del.minidvodb.copy (host) (minidvodb_group)"
+    break
+  end
+  book delpage MINIDVODB_COPY $1.$2
+end
+
+macro show.minidvodb.copy
+  if ($0 != 1)
+    echo "USAGE: show.minidvodb.copy"
+    break
+  end
+  echo "minidvodb copy"
+  book listbook MINIDVODB_COPY
+end
+
+macro add.minidvodb.host
+  if ($0 != 2)
+    echo "USAGE: add.minidvodb.host (host)"
+    break
+  end
+    #wait - shoudl be renamed MINIDVODB_WAIT
+  book newpage MINIDVODB_HOST $1
+  book setword MINIDVODB_HOST $1 HOST $1
+  
+end 
+
+macro del.minidvodb.host
+  if ($0 != 2)
+    echo "USAGE: del.minidvodb.host (host)"
+    break
+  end
+  book delpage MINIDVODB_HOST $1
+end
+
+macro show.minidvodb.host
+  if ($0 != 1)
+    echo "USAGE: show.minidvodb.host"
+    break
+  end
+  echo "minidvodb hosts"
+  book listbook MINIDVODB_HOST
+end
+
+task           minidvodb.copy.queue
+  host         local
+
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 300
+  npending     1
+
+  stdout NULL
+  stderr $LOGDIR/minidvodb.copy.queue.log
+
+  task.exec
+    book npages MINIDVODB_COPY -var N
+    if ($N == 0)
+#      echo "No labels for processing"
+      break
+    endif
+
+    book getpage MINIDVODB_COPY 0 -var minidvodbhostandgroup -key QUEUE_STATE NEW
+    if ("$minidvodbhostandgroup" == "NULL")
+      # All labels have been done --- reset
+#      echo "Resetting labels"
+      for i 0 $N
+        book getpage MINIDVODB_COPY $i -var minidvodbhostandgroup
+        book setword MINIDVODB_COPY $minidvodbhostandgroup QUEUE_STATE NEW
+      end
+      book getpage MINIDVODB_COPY 0 -var minidvodbhostandgroup -key QUEUE_STATE NEW
+      book getword MINIDVODB_COPY $minidvodbhostandgroup HOST -var host 
+      book getword MINIDVODB_COPY $minidvodbhostandgroup MINIDVODB_GROUP -var minidvodb_group   
+      book getword MINIDVODB_COPY $minidvodbhostandgroup MINIDVODB_COPY_PATH -var minidvodb_copy_path
+      
+
+   #   echo $minidvodb_group $minidvodb_copy_path 
+   #   book getword MINIDVODB_COPY 0 minidvodb_copy_path -var MINIDVODB_COPY_PATH
+      #this needs work - it is setting everything to null
+      #also, I want the database (I think?)
+
+      # Select different database
+      $MINIDVODB_COPY_DB ++
+      if ($MINIDVODB_COPY_DB >= $DB:n) set MINIDVODB_COPY_DB = 0
+    end
+#using check as opposed to list because it sees if it is done with the addRun state yet.  
+    book setword MINIDVODB_COPY $minidvodbhostandgroup QUEUE_STATE DONE
+    
+    book npages MINIDVODB_HOST -var NUM
+    if ($N ==0)
+         break
+    endif
+
+    book getpage MINIDVODB_HOST $host -var host2 -key HOST $host
+    if ($host2 != $host)
+        break
+    end
+
+    #echo $host $host2
+
+    
+    $run = minidvodbtool -definebyquery -set_destination_host $host -set_minidvodb_rsync_path $minidvodb_copy_path
+    $run = $run -minidvodb_group $minidvodb_group
+       if ($DB:n == 0)
+      option DEFAULT
+    else
+      # save the DB name for the exit tasks
+      option $DB:$MINIDVODB_COPY_DB
+      $run = $run -dbname $DB:$MINIDVODB_COPY_DB
+      $MINIDVODB_COPY_DB ++
+      if ($MINIDVODB_COPY_DB >= $DB:n) set MINIDVODB_COPY_DB = 0
+    end
+    #add_poll_args run
+    #echo $run
+    command $run
+  end
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    #ipptool2book stdout minidvodCopylist -key minidvodbcopy_id -uniq -setword dbname $options:0 -setword pantaskState INIT
+    #if ($VERBOSE > 2)
+    #  book listbook minidvodbCopylist
+    #end
+    # delete existing entries in the appropriate pantaskStates
+    #process_cleanup minidvodbCopylist
+  end
+
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+
+  task.exit    crash
+    showcommand crash
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+
+
+
+
+
+
+
+
+
+task           minidvodb.copy.load
+  host         local
+
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 30
+  npending     1
+
+  stdout NULL
+  stderr $LOGDIR/minidvodb.copy.load.log
+
+  task.exec
+    book npages MINIDVODB_COPY -var N
+    if ($N == 0)
+#      echo "No labels for processing"
+      break
+    endif
+
+    book getpage MINIDVODB_COPY 0 -var minidvodbhostandgroup -key STATE NEW
+    if ("$minidvodbhostandgroup" == "NULL")
+      # All labels have been done --- reset
+#      echo "Resetting labels"
+      for i 0 $N
+        book getpage MINIDVODB_COPY $i -var minidvodbhostandgroup
+        book setword MINIDVODB_COPY $minidvodbhostandgroup STATE NEW
+      end
+      book getpage MINIDVODB_COPY 0 -var minidvodbhostandgroup -key STATE NEW
+      book getword MINIDVODB_COPY $minidvodbhostandgroup HOST -var host 
+      book getword MINIDVODB_COPY $minidvodbhostandgroup MINIDVODB_GROUP -var minidvodb_group   
+
+      
+   #   book getword MINIDVODB_COPY 0 minidvodb_copy_path -var MINIDVODB_COPY_PATH
+      #this needs work - it is setting everything to null
+      #also, I want the database (I think?)
+
+      # Select different database
+      $MINIDVODB_COPY_DB ++
+      if ($MINIDVODB_COPY_DB >= $DB:n) set MINIDVODB_COPY_DB = 0
+    end
+#using check as opposed to list because it sees if it is done with the addRun state yet.  
+    book setword MINIDVODB_COPY $minidvodbhostandgroup STATE DONE
+    
+    book npages MINIDVODB_HOST -var NUM
+    if ($N ==0)
+	 break
+    endif
+
+    book getpage MINIDVODB_HOST $host -var host2 -key HOST $host
+    if ($host2 != $host)
+	break
+    end
+
+    #echo $host $host2
+
+    
+    $run = minidvodbtool -listminidvodbcopy -destination_host $host
+    $run = $run -minidvodb_group $minidvodb_group -pending
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      # save the DB name for the exit tasks
+      option $DB:$MINIDVODB_COPY_DB
+      $run = $run -dbname $DB:$MINIDVODB_COPY_DB
+      $MINIDVODB_COPY_DB ++
+      if ($MINIDVODB_COPY_DB >= $DB:n) set MINIDVODB_COPY_DB = 0
+    end
+    add_poll_args run
+    #echo $run
+    command $run
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout minidvodbCopylist -key minidvodbcopy_id -uniq -setword dbname $options:0 -setword pantaskState INIT
+    if ($VERBOSE > 2)
+      book listbook minidvodbCopylist
+    end
+    # delete existing entries in the appropriate pantaskStates
+    process_cleanup minidvodbCopylist
+  end
+
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+
+  task.exit    crash
+    showcommand crash
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+
+
+
+task           minidvodb.copy.run
+  periods      -poll $RUNPOLL
+  periods      -exec $RUNEXEC
+  periods      -timeout 17280 
+ #if rsync is slow I want to make sure it doesn't time out
+
+  task.exec
+    # if we are unable to run the 'exec', use a long retry time
+    periods -exec $RUNEXEC
+
+    book npages minidvodbCopylist -var N
+    if ($N == 0) break
+   
+    # look for new images in minidvodbWaitlist (pantaskState == INIT)
+    book getpage minidvodbCopylist 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+    echo "got here"
+    book setword minidvodbCopylist $pageName pantaskState RUN
+    book getword minidvodbCopylist $pageName minidvodbcopy_id -var MINIDVODB_COPY_ID
+    book getword minidvodbCopylist $pageName minidvodb_path -var MINIDVODBRUN_PATH
+    book getword minidvodbCopylist $pageName minidvodb_id -var MINIDVODB_ID
+    book getword minidvodbCopylist $pageName minidvodb_rsync_path -var MINIDVODB_RSYNC_PATH
+    book getword minidvodbCopylist $pageName destination_host -var DESTINATION_HOST
+    book getword minidvodbCopylist $pageName state -var STATE
+    stdout $LOGDIR/minidvodb.copy.run.log
+    stderr $LOGDIR/minidvodb.copy.run.log
+    
+    $run = minidvodb_copy.pl --minidvodbcopy_id $MINIDVODB_COPY_ID --minidvodb_id $MINIDVODB_ID  
+# and more things
+    $run = $run --minidvodbrun_path $MINIDVODBRUN_PATH --minidvodb_rsync_path $MINIDVODB_RSYNC_PATH
+    $run = $run --destination_host $DESTINATION_HOST
+   
+if ($DB:n == 0)
+      option DEFAULT
+    else
+      # save the DB name for the exit tasks
+      option $DB:$MINIDVODB_COPY_DB
+      $run = $run --dbname $DB:$MINIDVODB_COPY_DB
+      $MINIDVODB_COPY_DB ++
+      if ($MINIDVODB_COPY_DB >= $DB:n) set MINIDVODB_COPY_DB = 0
+    end
+    # save the pageName for future reference below
+    options $pageName
+    echo command $run
+    # create the command line
+    if ($VERBOSE > 1)
+      echo command $run
+    end
+    # if we are unable to run the 'exec', use a long retry time
+    periods -exec 0.05
+    command $run
+  end
+  # default exit status
+    task.exit    default
+    process_exit minidvodbCopylist $options:0 $JOB_STATUS
+  end
+
+  # locked list
+  task.exit    crash
+    echo "hostname: $JOB_HOSTNAME"
+    process_exit minidvodbCopylist $options:0 $EXIT_CRASH_ERR
+  end
+
+  # operation timed out?
+    task.exit    timeout
+	showcommand timeout
+    book setword minidvodbCopylist $options:0 pantaskState TIMEOUT
+  end
+end
+
Index: /branches/haf_branches/ipp.rsync.20101015/ippTools/src/minidvodbtool.c
===================================================================
--- /branches/haf_branches/ipp.rsync.20101015/ippTools/src/minidvodbtool.c	(revision 29525)
+++ /branches/haf_branches/ipp.rsync.20101015/ippTools/src/minidvodbtool.c	(revision 29526)
@@ -255,6 +255,8 @@
   PXOPT_COPY_STR(config->args, where, "-minidvodbcopy_id", "minidvodbCopy.minidvodbcopy_id", "==");
   PXOPT_COPY_STR(config->args, where, "-destination_host", "minidvodbCopy.destination_host", "==");
+  PXOPT_COPY_STR(config->args, where, "-minidvodb_group", "minidvodbRun.minidvodb_group", "==");
   PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
   PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
+  PXOPT_LOOKUP_BOOL(pending, config->args, "-pending", false);
   PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
   if (!psListLength(where->list)) {
@@ -294,4 +296,10 @@
     }
     psFree(where);
+
+    if (pending) {
+       //add the cuts for pending (state new, no faults)
+      psStringAppend(&query, " %s", " AND minidvodbCopy.state = 'new' AND minidvodbCopy.fault = 0 AND minidvodbCopy.destination_host IS NOT NULL AND minidvodbCopy.minidvodb_rsync_path IS NOT NULL");
+    }
+
 
     // order by epoch
@@ -343,4 +351,5 @@
   PXOPT_COPY_S64(config->args, where, "-minidvodb_id", "minidvodbCopy.minidvodb_id", "==");
   PXOPT_COPY_STR(config->args, where, "-destination_host", "destination_host", "==");
+  PXOPT_COPY_S16(config->args, where, "-fault", "minidvodbCopy.fault", "==");
 
   if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) {
@@ -472,9 +481,8 @@
   }
 
- 
-
-  psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
+    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
   psStringAppend(&query, " WHERE %s", whereClause);
 
+  
   if (!p_psDBRunQuery(config->dbh, query)) {
     psError(PS_ERR_UNKNOWN, false, "database error %s", query);
Index: /branches/haf_branches/ipp.rsync.20101015/ippTools/src/minidvodbtoolConfig.c
===================================================================
--- /branches/haf_branches/ipp.rsync.20101015/ippTools/src/minidvodbtoolConfig.c	(revision 29525)
+++ /branches/haf_branches/ipp.rsync.20101015/ippTools/src/minidvodbtoolConfig.c	(revision 29526)
@@ -49,12 +49,12 @@
     // -definebyquery
     psMetadata *definebyqueryArgs = psMetadataAlloc();
-    psMetadataAddS64(definebyqueryArgs, PS_LIST_TAIL, "-minidvodb_id",             0, "search by cam_id", 0);
+    psMetadataAddS64(definebyqueryArgs, PS_LIST_TAIL, "-minidvodb_id",             0, "search by minidvodb_id", 0);
     pxcamSetSearchArgs(definebyqueryArgs);
-       psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-minidvodb_group", PS_META_DUPLICATE_OK, "search by camRun data_group", NULL);
+       psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-minidvodb_group", PS_META_DUPLICATE_OK, "search by minidvodbRun minidvodb_group", NULL);
 
        
     psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_minidvodb_rsync_path",        0, "define workdir", NULL);
     psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_destination_host",          0, "define label", NULL);
-    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_reduction",      0, "define reduction class", NULL);
+    //    psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_reduction",      0, "define reduction class", NULL);
    psMetadataAddBool(definebyqueryArgs, PS_LIST_TAIL, "-pretend",           0, "do not actually modify the database", false);
     psMetadataAddBool(definebyqueryArgs, PS_LIST_TAIL, "-simple",            0, "use the simple output format", false);
@@ -62,6 +62,8 @@
     psMetadata *listminidvodbcopyArgs = psMetadataAlloc();
     psMetadataAddU64(listminidvodbcopyArgs, PS_LIST_TAIL, "-minidvodb_id",        0, "search by minidvodb_id", 0);
-    psMetadataAddStr(listminidvodbcopyArgs, PS_LIST_TAIL, "-minidvodbcopy_id",        0, "search by minidvodb_name", NULL);
-    psMetadataAddStr(listminidvodbcopyArgs, PS_LIST_TAIL, "-destination_host",        0, "search by minidvodb.minidvodb_group", NULL);
+    psMetadataAddStr(listminidvodbcopyArgs, PS_LIST_TAIL, "-minidvodbcopy_id",        0, "search by minidvodbcopy_id", NULL);
+    psMetadataAddStr(listminidvodbcopyArgs, PS_LIST_TAIL, "-minidvodb_group",         0, "search by minidvodbRun.minidvodb_group", NULL);
+    psMetadataAddStr(listminidvodbcopyArgs, PS_LIST_TAIL, "-destination_host",        0, "search by minidvodbCopy.destination_host", NULL);
+    psMetadataAddBool(listminidvodbcopyArgs, PS_LIST_TAIL, "-pending",        0, "limit to pending items", false);
     psMetadataAddU64(listminidvodbcopyArgs, PS_LIST_TAIL, "-limit",        0, "limit to N items", 0);
     psMetadataAddBool(listminidvodbcopyArgs, PS_LIST_TAIL, "-simple",        0, "simple output", false);
@@ -72,5 +74,5 @@
     psMetadataAddU64(revertminidvodbcopyArgs, PS_LIST_TAIL, "-minidvodb_id",        0, "search by minidvodb_id", 0);
     psMetadataAddStr(revertminidvodbcopyArgs, PS_LIST_TAIL, "-destination_host",        0, "search by destination_host", NULL);
-
+    psMetadataAddS16(revertminidvodbcopyArgs, PS_LIST_TAIL, "-fault",        0, "search by minidvodbCopyfault", 0);
     psMetadata *updateminidvodbcopyArgs = psMetadataAlloc();
     psMetadataAddU64(updateminidvodbcopyArgs, PS_LIST_TAIL, "-minidvodbcopy_id",        0, "search by minidvodbcopy_id", 0);
