aboutsummaryrefslogtreecommitdiff
path: root/weed/shell/command_volume_copy.go
diff options
context:
space:
mode:
Diffstat (limited to 'weed/shell/command_volume_copy.go')
-rw-r--r--weed/shell/command_volume_copy.go26
1 files changed, 15 insertions, 11 deletions
diff --git a/weed/shell/command_volume_copy.go b/weed/shell/command_volume_copy.go
index 1c83ba655..85b4bb095 100644
--- a/weed/shell/command_volume_copy.go
+++ b/weed/shell/command_volume_copy.go
@@ -1,7 +1,7 @@
package shell
import (
- "context"
+ "flag"
"fmt"
"io"
@@ -22,7 +22,7 @@ func (c *commandVolumeCopy) Name() string {
func (c *commandVolumeCopy) Help() string {
return `copy a volume from one volume server to another volume server
- volume.copy <source volume server host:port> <target volume server host:port> <volume id>
+ volume.copy -source <source volume server host:port> -target <target volume server host:port> -volumeId <volume id>
This command copies a volume from one volume server to another volume server.
Usually you will want to unmount the volume first before copying.
@@ -32,22 +32,26 @@ func (c *commandVolumeCopy) Help() string {
func (c *commandVolumeCopy) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
- if len(args) != 3 {
- fmt.Fprintf(writer, "received args: %+v\n", args)
- return fmt.Errorf("need 3 args of <source volume server host:port> <target volume server host:port> <volume id>")
+ if err = commandEnv.confirmIsLocked(); err != nil {
+ return
}
- sourceVolumeServer, targetVolumeServer, volumeIdString := args[0], args[1], args[2]
- volumeId, err := needle.NewVolumeId(volumeIdString)
- if err != nil {
- return fmt.Errorf("wrong volume id format %s: %v", volumeId, err)
+ volCopyCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
+ volumeIdInt := volCopyCommand.Int("volumeId", 0, "the volume id")
+ sourceNodeStr := volCopyCommand.String("source", "", "the source volume server <host>:<port>")
+ targetNodeStr := volCopyCommand.String("target", "", "the target volume server <host>:<port>")
+ if err = volCopyCommand.Parse(args); err != nil {
+ return nil
}
+ sourceVolumeServer, targetVolumeServer := *sourceNodeStr, *targetNodeStr
+
+ volumeId := needle.VolumeId(*volumeIdInt)
+
if sourceVolumeServer == targetVolumeServer {
return fmt.Errorf("source and target volume servers are the same!")
}
- ctx := context.Background()
- _, err = copyVolume(ctx, commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer, targetVolumeServer)
+ _, err = copyVolume(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer, targetVolumeServer, "")
return
}