2019-04-21 03:31:35 +00:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
2020-09-20 16:27:34 +00:00
|
|
|
"flag"
|
2019-04-21 03:31:35 +00:00
|
|
|
"fmt"
|
2021-09-13 05:47:52 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb"
|
2019-04-21 03:31:35 +00:00
|
|
|
"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
|
|
|
|
|
2020-09-20 16:27:34 +00:00
|
|
|
volume.copy -source <source volume server host:port> -target <target volume server host:port> -volumeId <volume id>
|
2019-04-21 03:31:35 +00: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 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-09-20 16:27:34 +00: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 03:31:35 +00:00
|
|
|
}
|
|
|
|
|
2021-09-14 05:13:34 +00:00
|
|
|
if err = commandEnv.confirmIsLocked(); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-09-13 05:47:52 +00:00
|
|
|
sourceVolumeServer, targetVolumeServer := pb.ServerAddress(*sourceNodeStr), pb.ServerAddress(*targetNodeStr)
|
2020-09-20 16:27:34 +00:00
|
|
|
|
|
|
|
volumeId := needle.VolumeId(*volumeIdInt)
|
2019-04-21 03:31:35 +00:00
|
|
|
|
|
|
|
if sourceVolumeServer == targetVolumeServer {
|
|
|
|
return fmt.Errorf("source and target volume servers are the same!")
|
|
|
|
}
|
|
|
|
|
2021-10-24 09:52:56 +00:00
|
|
|
_, err = copyVolume(commandEnv.option.GrpcDialOption, writer, volumeId, sourceVolumeServer, targetVolumeServer, "")
|
2019-04-21 03:31:35 +00:00
|
|
|
return
|
|
|
|
}
|