command_volume_copy.go 1.5 KB

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