Index: /trunk/Nebulous/bin/neb-cull
===================================================================
--- /trunk/Nebulous/bin/neb-cull	(revision 25120)
+++ /trunk/Nebulous/bin/neb-cull	(revision 25121)
@@ -16,9 +16,10 @@
 use Pod::Usage qw( pod2usage );
 
-my ($server, $volume, $one_only);
+my ($min_copies, $server, $volume, $one_only);
 
 $server = $ENV{'NEB_SERVER'} unless $server;
 
 GetOptions(
+    'min_copies|m=i'=> \$min_copies,
     'server|s=s'    => \$server,
     'volume|v=s'    => \$volume,
@@ -41,9 +42,10 @@
     unless defined $neb;
 
+$volume ||= "any";
+$min_copies ||= 2;
+
 my @cull_args;    
 push @cull_args, $key;
-if (defined $volume) {
-    push @cull_args, $volume;
-}
+push @cull_args, $volume;
 
 if ($one_only) {
@@ -58,4 +60,5 @@
     }
 } else {
+    push @cull_args, $min_copies;
     unless (defined $neb->cull(@cull_args)) {
         die "failed to cull Nebulous key: $key - " . $neb->err;
Index: /trunk/Nebulous/lib/Nebulous/Client.pm
===================================================================
--- /trunk/Nebulous/lib/Nebulous/Client.pm	(revision 25120)
+++ /trunk/Nebulous/lib/Nebulous/Client.pm	(revision 25121)
@@ -275,5 +275,5 @@
     my $self = shift;
 
-    my ($key, $vol_name) = validate_pos(@_,
+    my ($key, $vol_name, $min_copies) = validate_pos(@_,
         {
             type => SCALAR,
@@ -284,45 +284,45 @@
             optional    => 1,
         },
-    );
-
-    $log->debug( "entered - @_" );
-
-    my $locations;
+        {
+            # min copies
+            type        => SCALAR,
+            optional    => 1,
+        },
+    );
+
+    $min_copies ||= 1;
+
+    $log->debug( "entered - @_" );
+
+    my $stats = $self->stat($key);
+    my $instances = $stats->[6];
+    if ((not defined $instances) or ($instances == 0)) {
+        $self->set_err("can not cull - no instances");
+        $log->debug("leaving");
+        return;
+    }
+    if ($instances < $min_copies) {
+        $self->set_err("can not cull - not enough instances");
+        $log->debug("leaving");
+
+        return;
+    }
+
     # if vol_name is specified we need to stat the file to find out how many
     # instances there are on all volumes.  Otherwise we wouldn't know if it's
     # safe to remove the last instance on the specified volume.
     # XXX We need some way to determine which is the best instance to remove
+    my $locations;
     if (defined $vol_name) {
-        my @stats = $self->stat($key);
-        my $instances = $stats[6];
-        if (defined $instances and $instances < 2) {
-            $self->set_err("can not cull - not enough instances");
-            $log->debug("leaving");
-
-            return;
-        }
-
         $locations = $self->find_instances($key, $vol_name);
-        unless (defined $locations) {
-            $self->set_err( "no instances" );
-            $log->debug( "leaving" );
-
-            return;
-        }
     } else {
         $locations = $self->find_instances($key);
-        unless ($locations) {
-            $self->set_err( "no instances" );
-            $log->debug("leaving");
-
-            return;
-        }
-
-        if (scalar @{ $locations } < 2) {
-            $self->set_err("can not cull - not enough instances");
-            $log->debug("leaving");
-
-            return;
-        }
+    }
+
+    unless (defined $locations) {
+        $self->set_err( "no instances" );
+        $log->debug( "leaving" );
+
+        return;
     }
 
@@ -393,5 +393,5 @@
             }
             for (my $i = 1; $i < $stats->[6]; $i++) {
-                $self->cull($key);
+                $self->cull($key, "any", 1);
                 $removed++;
             }
Index: /trunk/Nebulous/t/53_client_cull.t
===================================================================
--- /trunk/Nebulous/t/53_client_cull.t	(revision 25120)
+++ /trunk/Nebulous/t/53_client_cull.t	(revision 25121)
@@ -114,5 +114,5 @@
     $neb->cull();
 };
-like( $@, qr/1 - 2 were expected/, "no params" );
+like( $@, qr/1 - 3 were expected/, "no params" );
 
 Test::Nebulous->setup;
@@ -122,7 +122,7 @@
         proxy => "http://$hostport/nebulous",
     );
-    $neb->cull( 1, 2, 3 );
+    $neb->cull( 1, 2, 3, 4 );
 };
-like( $@, qr/1 - 2 were expected/, "too many params" );
+like( $@, qr/1 - 3 were expected/, "too many params" );
 
 Test::Nebulous->cleanup;
Index: /trunk/Nebulous/t/72_neb-cull.t
===================================================================
--- /trunk/Nebulous/t/72_neb-cull.t	(revision 25120)
+++ /trunk/Nebulous/t/72_neb-cull.t	(revision 25121)
@@ -17,5 +17,5 @@
 
 use Apache::Test qw( -withtestmore );
-plan tests => 29;
+plan tests => 41;
 
 use lib qw( ./lib ./t );
@@ -71,4 +71,61 @@
     is($? >> 8, 255, "exit code");
     like($test->stdout, qr/^$/, "stdout");
+    like($test->stderr, qr/failed to cull Nebulous key/, "stderr");
+}
+
+Test::Nebulous->setup;
+
+{
+    my $key = 'foo';
+
+    my $neb = Nebulous::Client->new(
+        proxy => $neb_url,
+    );
+    $neb->create($key);
+    $neb->replicate($key);
+
+    $test->run(args => $key);
+
+    is($neb->stat($key)->[6], 1, "correct # of instances");
+    is($? >> 8, 0, "exit code");
+    like($test->stdout, qr/^$/, "stdout");
+    like($test->stderr, qr/^$/, "stderr");
+}
+
+Test::Nebulous->setup;
+
+{
+    my $key = 'foo';
+
+    my $neb = Nebulous::Client->new(
+        proxy => $neb_url,
+    );
+    $neb->create($key);
+    $neb->replicate($key);
+    $neb->replicate($key);
+
+    $test->run(args => $key);
+
+    is($neb->stat($key)->[6], 2, "correct # of instances");
+    is($? >> 8, 0, "exit code");
+    like($test->stdout, qr/^$/, "stdout");
+    like($test->stderr, qr/^$/, "stderr");
+}
+
+Test::Nebulous->setup;
+
+{
+    my $key = 'foo';
+
+    my $neb = Nebulous::Client->new(
+        proxy => $neb_url,
+    );
+    $neb->create($key);
+
+    $test->run(args => "--one_only " . $key);
+
+    is($neb->stat($key)->[6], 1, "correct # of instances");
+    is($? >> 8, 255, "exit code");
+    like($test->stdout, qr/^$/, "stdout");
     like($test->stderr, qr/not enough instances/, "stderr");
 }
@@ -85,46 +142,65 @@
     $neb->replicate($key);
 
-    $test->run(args => $key);
-
-    is($neb->stat($key)->[6], 1, "correct # of instances");
-    is($? >> 8, 0, "exit code");
-    like($test->stdout, qr/^$/, "stdout");
-    like($test->stderr, qr/^$/, "stderr");
-}
-
-Test::Nebulous->setup;
-
-{
-    my $key = 'foo';
-
-    my $neb = Nebulous::Client->new(
-        proxy => $neb_url,
-    );
-    $neb->create($key);
-    $neb->replicate($key);
-    $neb->replicate($key);
-
-    $test->run(args => $key);
-
-    is($neb->stat($key)->[6], 2, "correct # of instances");
-    is($? >> 8, 0, "exit code");
-    like($test->stdout, qr/^$/, "stdout");
-    like($test->stderr, qr/^$/, "stderr");
-}
-
-Test::Nebulous->setup;
-
-{
-    my $key = 'foo';
-
-    my $neb = Nebulous::Client->new(
-        proxy => $neb_url,
-    );
-    $neb->create($key);
-
     $test->run(args => "--one_only " . $key);
 
     is($neb->stat($key)->[6], 1, "correct # of instances");
-    is($? >> 8, 255, "exit code");
+    is($? >> 8, 0, "exit code");
+    like($test->stdout, qr/^$/, "stdout");
+    like($test->stderr, qr/^$/, "stderr");
+}
+
+Test::Nebulous->setup;
+
+{
+    my $key = 'foo';
+
+    my $neb = Nebulous::Client->new(
+        proxy => $neb_url,
+    );
+    $neb->create($key);
+    $neb->replicate($key);
+    $neb->replicate($key);
+
+    $test->run(args => "--one_only " . $key);
+
+    is($neb->stat($key)->[6], 1, "correct # of instances");
+    is($? >> 8, 0, "exit code");
+    like($test->stdout, qr/^$/, "stdout");
+    like($test->stderr, qr/^$/, "stderr");
+}
+
+Test::Nebulous->setup;
+
+{
+    my $key = 'foo';
+
+    my $neb = Nebulous::Client->new(
+        proxy => $neb_url,
+    );
+    $neb->create($key);
+    $neb->replicate($key);
+
+    $test->run(args => "--min_copies 1 " . $key);
+
+    is($neb->stat($key)->[6], 1, "correct # of instances");
+    is($? >> 8, 0, "exit code");
+    like($test->stdout, qr/^$/, "stdout");
+    like($test->stderr, qr/^$/, "stderr");
+}
+
+Test::Nebulous->setup;
+
+{
+    my $key = 'foo';
+
+    my $neb = Nebulous::Client->new(
+        proxy => $neb_url,
+    );
+    $neb->create($key);
+
+    $test->run(args => "--min_copies 1 " . $key);
+
+    is($neb->stat($key)->[6], 1, "correct # of instances");
+    is($? >> 8, 0, "exit code");
     like($test->stdout, qr/^$/, "stdout");
     like($test->stderr, qr/not enough instances/, "stderr");
@@ -141,26 +217,7 @@
     $neb->create($key);
     $neb->replicate($key);
-
-    $test->run(args => "--one_only " . $key);
-
-    is($neb->stat($key)->[6], 1, "correct # of instances");
-    is($? >> 8, 0, "exit code");
-    like($test->stdout, qr/^$/, "stdout");
-    like($test->stderr, qr/^$/, "stderr");
-}
-
-Test::Nebulous->setup;
-
-{
-    my $key = 'foo';
-
-    my $neb = Nebulous::Client->new(
-        proxy => $neb_url,
-    );
-    $neb->create($key);
-    $neb->replicate($key);
-    $neb->replicate($key);
-
-    $test->run(args => "--one_only " . $key);
+    $neb->replicate($key);
+
+    $test->run(args => "--min_copies 2 " . $key);
 
     is($neb->stat($key)->[6], 1, "correct # of instances");
