github.com/pingcap/tiup@v1.15.1/components/cluster/command/transfer.go (about) 1 // Copyright 2021 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package command 15 16 import ( 17 "github.com/pingcap/tiup/pkg/cluster/manager" 18 "github.com/spf13/cobra" 19 ) 20 21 /* Add a pair of adb like commands to transfer files to or from remote 22 servers. Not using `scp` as the real implementation is not necessarily 23 SSH, not using `transfer` all-in-one command to get rid of complex 24 checking of wheather a path is remote or local, as this is supposed 25 to be only a tiny helper utility. 26 */ 27 28 func newPullCmd() *cobra.Command { 29 opt := manager.TransferOptions{Pull: true} 30 cmd := &cobra.Command{ 31 Use: "pull <cluster-name> <remote-path> <local-path>", 32 Short: "(EXPERIMENTAL) Transfer files or directories from host in the tidb cluster to local", 33 Hidden: true, 34 RunE: func(cmd *cobra.Command, args []string) error { 35 if len(args) != 3 { 36 return cmd.Help() 37 } 38 39 clusterName := args[0] 40 opt.Remote = args[1] 41 opt.Local = args[2] 42 clusterReport.ID = scrubClusterName(clusterName) 43 teleCommand = append(teleCommand, scrubClusterName(clusterName)) 44 45 return cm.Transfer(clusterName, opt, gOpt) 46 }, 47 } 48 49 cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Only exec on host with specified roles") 50 cmd.Flags().StringSliceVarP(&gOpt.Nodes, "node", "N", nil, "Only exec on host with specified nodes") 51 cmd.Flags().IntVarP(&opt.Limit, "limit", "l", 0, "Limits the used bandwidth, specified in Kbit/s") 52 cmd.Flags().BoolVar(&opt.Compress, "compress", false, "Compression enable. Passes the -C flag to ssh(1) to enable compression.") 53 54 return cmd 55 } 56 57 func newPushCmd() *cobra.Command { 58 opt := manager.TransferOptions{Pull: false} 59 cmd := &cobra.Command{ 60 Use: "push <cluster-name> <local-path> <remote-path>", 61 Short: "(EXPERIMENTAL) Transfer files or directories from local to host in the tidb cluster", 62 Hidden: true, 63 RunE: func(cmd *cobra.Command, args []string) error { 64 if len(args) != 3 { 65 return cmd.Help() 66 } 67 68 clusterName := args[0] 69 opt.Local = args[1] 70 opt.Remote = args[2] 71 clusterReport.ID = scrubClusterName(clusterName) 72 teleCommand = append(teleCommand, scrubClusterName(clusterName)) 73 74 return cm.Transfer(clusterName, opt, gOpt) 75 }, 76 } 77 78 cmd.Flags().StringSliceVarP(&gOpt.Roles, "role", "R", nil, "Only exec on host with specified roles") 79 cmd.Flags().StringSliceVarP(&gOpt.Nodes, "node", "N", nil, "Only exec on host with specified nodes") 80 81 return cmd 82 }