2019-04-21 03:31:35 +00:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-06-05 08:30:24 +00:00
|
|
|
Commands = append(Commands, &commandVolumeCopy{})
|
2019-04-21 03:31:35 +00: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 08:30:24 +00:00
|
|
|
func (c *commandVolumeCopy) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
2019-04-21 03:31:35 +00:00
|
|
|
|
2020-04-23 20:37:31 +00:00
|
|
|
if err = commandEnv.confirmIsLocked(); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-04-21 03:48:07 +00:00
|
|
|
if len(args) != 3 {
|
2019-04-21 03:31:35 +00:00
|
|
|
fmt.Fprintf(writer, "received args: %+v\n", args)
|
2019-04-21 03:48:07 +00:00
|
|
|
return fmt.Errorf("need 3 args of <source volume server host:port> <target volume server host:port> <volume id>")
|
2019-04-21 03:31:35 +00: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!")
|
|
|
|
}
|
|
|
|
|
2020-02-26 05:50:12 +00:00
|
|
|
_, err = copyVolume(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer, targetVolumeServer)
|
2019-04-21 03:31:35 +00:00
|
|
|
return
|
|
|
|
}
|