command_volume_copy.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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) HasTag(CommandTag) bool {
  25. return false
  26. }
  27. func (c *commandVolumeCopy) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  28. volCopyCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  29. volumeIdInt := volCopyCommand.Int("volumeId", 0, "the volume id")
  30. sourceNodeStr := volCopyCommand.String("source", "", "the source volume server <host>:<port>")
  31. targetNodeStr := volCopyCommand.String("target", "", "the target volume server <host>:<port>")
  32. if err = volCopyCommand.Parse(args); err != nil {
  33. return nil
  34. }
  35. if err = commandEnv.confirmIsLocked(args); err != nil {
  36. return
  37. }
  38. sourceVolumeServer, targetVolumeServer := pb.ServerAddress(*sourceNodeStr), pb.ServerAddress(*targetNodeStr)
  39. volumeId := needle.VolumeId(*volumeIdInt)
  40. if sourceVolumeServer == targetVolumeServer {
  41. return fmt.Errorf("source and target volume servers are the same!")
  42. }
  43. _, err = copyVolume(commandEnv.option.GrpcDialOption, writer, volumeId, sourceVolumeServer, targetVolumeServer, "", 0)
  44. return
  45. }