Index: trunk/Nebulous/bin/neb-replicate
===================================================================
--- trunk/Nebulous/bin/neb-replicate	(revision 20132)
+++ trunk/Nebulous/bin/neb-replicate	(revision 23696)
@@ -25,4 +25,5 @@
     'volume|v=s'    => \$volume,
     'copies|c=i'    => \$copies,
+    'set_copies=i'  => \$set_copies,
 ) || pod2usage( 2 );
 
@@ -44,14 +45,28 @@
     unless defined $neb;
 
-for (my $i = 0; $i < $copies; $i++) {
-    if (defined $volume) {
-        $neb->replicate($key, $volume)
-            or die "failed to replicate Nebulous key: $key";
-    } else {
-        $neb->replicate($key)
-            or die "failed to replicate Nebulous key: $key";
+# if replicate fails, we should still set user.copies (if requested)
+my $replication_problem;
+eval {
+    for (my $i = 0; $i < $copies; $i++) {
+        if (defined $volume) {
+            $neb->replicate($key, $volume)
+                or die "failed to replicate Nebulous key: $key";
+        } else {
+            $neb->replicate($key)
+                or die "failed to replicate Nebulous key: $key";
+        }
     }
+};
+if ($@) {
+    warn $@;
+    $replication_problem = 1;
 }
 
+if ($set_copies) {
+    $neb->setxattr($key, "user.copies", $copies, "replace")
+        or die $neb->err;
+}
+
+exit(32) if defined $replication_problem;
 
 __END__
@@ -66,5 +81,5 @@
 
     neb-replicate [--server <URL>] [--volume <volume name>]
-                  [--copies <n>] <key>
+                  [--copies <n>] [--set_copies <n>] <key>
 
 =head1 DESCRIPTION
@@ -93,5 +108,11 @@
 The number of new replications to create.
 
-Optional.  Defaults to 0.
+Optional.  Defaults to 1.
+
+=item * --set_copies|c <n>
+
+Set the C<user.copies> xattr for this storage object to C<<n>>.
+
+Optional.
 
 =back
