2019-04-21 11:31:35 +08:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
2020-09-21 00:27:34 +08:00
|
|
|
"flag"
|
2019-04-21 11:31:35 +08:00
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2020-09-21 00:27:34 +08:00
|
|
|
volume.copy -source <source volume server host:port> -target <target volume server host:port> -volumeId <volume id>
|
2019-04-21 11:31:35 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
2020-04-24 04:37:31 +08:00
|
|
|
if err = commandEnv.confirmIsLocked(); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-09-21 00:27:34 +08:00
|
|
|
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
|
2019-04-21 11:31:35 +08:00
|
|
|
}
|
|
|
|
|
2020-09-21 00:27:34 +08:00
|
|
|
sourceVolumeServer, targetVolumeServer := *sourceNodeStr, *targetNodeStr
|
|
|
|
|
|
|
|
volumeId := needle.VolumeId(*volumeIdInt)
|
2019-04-21 11:31:35 +08:00
|
|
|
|
|
|
|
if sourceVolumeServer == targetVolumeServer {
|
|
|
|
return fmt.Errorf("source and target volume servers are the same!")
|
|
|
|
}
|
|
|
|
|
2020-02-26 13:50:12 +08:00
|
|
|
_, err = copyVolume(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer, targetVolumeServer)
|
2019-04-21 11:31:35 +08:00
|
|
|
return
|
|
|
|
}
|