2019-04-21 11:31:35 +08:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
|
2019-09-02 18:28:40 +08:00
|
|
|
"github.com/joeslay/seaweedfs/weed/storage/needle"
|
2019-04-21 11:31:35 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-06-05 16:30:24 +08:00
|
|
|
Commands = append(Commands, &commandVolumeCopy{})
|
2019-04-21 11:31:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type commandVolumeCopy struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandVolumeCopy) Name() string {
|
|
|
|
return "volume.copy"
|
|
|
|
}
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
|
|
|
This command copies a volume from one volume server to another volume server.
|
|
|
|
Usually you will want to unmount the volume first before copying.
|
|
|
|
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
2019-06-05 16:30:24 +08:00
|
|
|
func (c *commandVolumeCopy) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
2019-04-21 11:31:35 +08:00
|
|
|
|
2019-04-21 11:48:07 +08:00
|
|
|
if len(args) != 3 {
|
2019-04-21 11:31:35 +08:00
|
|
|
fmt.Fprintf(writer, "received args: %+v\n", args)
|
2019-04-21 11:48:07 +08:00
|
|
|
return fmt.Errorf("need 3 args of <source volume server host:port> <target volume server host:port> <volume id>")
|
2019-04-21 11:31:35 +08:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
return
|
|
|
|
}
|