command_volume_copy.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package shell
  2. import (
  3. "flag"
  4. "fmt"
  5. "github.com/seaweedfs/seaweedfs/weed/pb"
  6. "io"
  7. "github.com/seaweedfs/seaweedfs/weed/storage/needle"
  8. )
  9. func init() {
  10. Commands = append(Commands, &commandVolumeCopy{})
  11. }
  12. type commandVolumeCopy struct {
  13. }
  14. func (c *commandVolumeCopy) Name() string {
  15. return "volume.copy"
  16. }
  17. func (c *commandVolumeCopy) Help() string {
  18. return `copy a volume from one volume server to another volume server
  19. volume.copy -source <source volume server host:port> -target <target volume server host:port> -volumeId <volume id>
  20. This command copies a volume from one volume server to another volume server.
  21. Usually you will want to unmount the volume first before copying.
  22. `
  23. }
  24. func (c *commandVolumeCopy) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  25. volCopyCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  26. volumeIdInt := volCopyCommand.Int("volumeId", 0, "the volume id")
  27. sourceNodeStr := volCopyCommand.String("source", "", "the source volume server <host>:<port>")
  28. targetNodeStr := volCopyCommand.String("target", "", "the target volume server <host>:<port>")
  29. if err = volCopyCommand.Parse(args); err != nil {
  30. return nil
  31. }
  32. if err = commandEnv.confirmIsLocked(args); err != nil {
  33. return
  34. }
  35. sourceVolumeServer, targetVolumeServer := pb.ServerAddress(*sourceNodeStr), pb.ServerAddress(*targetNodeStr)
  36. volumeId := needle.VolumeId(*volumeIdInt)
  37. if sourceVolumeServer == targetVolumeServer {
  38. return fmt.Errorf("source and target volume servers are the same!")
  39. }
  40. _, err = copyVolume(commandEnv.option.GrpcDialOption, writer, volumeId, sourceVolumeServer, targetVolumeServer, "", 0)
  41. return
  42. }