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"
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
2019-04-21 11:31:35 +08:00
|
|
|
"io"
|
|
|
|
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/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
|
|
|
|
|
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-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
|
|
|
}
|
|
|
|
|
2021-12-11 05:24:38 +08:00
|
|
|
if err = commandEnv.confirmIsLocked(args); err != nil {
|
2021-09-14 13:13:34 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-09-13 13:47:52 +08:00
|
|
|
sourceVolumeServer, targetVolumeServer := pb.ServerAddress(*sourceNodeStr), pb.ServerAddress(*targetNodeStr)
|
2020-09-21 00:27:34 +08:00
|
|
|
|
|
|
|
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!")
|
|
|
|
}
|
|
|
|
|
2021-10-24 17:52:56 +08:00
|
|
|
_, err = copyVolume(commandEnv.option.GrpcDialOption, writer, volumeId, sourceVolumeServer, targetVolumeServer, "")
|
2019-04-21 11:31:35 +08:00
|
|
|
return
|
|
|
|
}
|