You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

  1. package shell
  2. import (
  3. "fmt"
  4. "io"
  5. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  6. )
  7. func init() {
  8. Commands = append(Commands, &commandVolumeCopy{})
  9. }
  10. type commandVolumeCopy struct {
  11. }
  12. func (c *commandVolumeCopy) Name() string {
  13. return "volume.copy"
  14. }
  15. func (c *commandVolumeCopy) Help() string {
  16. return `copy a volume from one volume server to another volume server
  17. volume.copy <source volume server host:port> <target volume server host:port> <volume id>
  18. This command copies a volume from one volume server to another volume server.
  19. Usually you will want to unmount the volume first before copying.
  20. `
  21. }
  22. func (c *commandVolumeCopy) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  23. if len(args) != 3 {
  24. fmt.Fprintf(writer, "received args: %+v\n", args)
  25. return fmt.Errorf("need 3 args of <source volume server host:port> <target volume server host:port> <volume id>")
  26. }
  27. sourceVolumeServer, targetVolumeServer, volumeIdString := args[0], args[1], args[2]
  28. volumeId, err := needle.NewVolumeId(volumeIdString)
  29. if err != nil {
  30. return fmt.Errorf("wrong volume id format %s: %v", volumeId, err)
  31. }
  32. if sourceVolumeServer == targetVolumeServer {
  33. return fmt.Errorf("source and target volume servers are the same!")
  34. }
  35. _, err = copyVolume(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer, targetVolumeServer)
  36. return
  37. }