code.vegaprotocol.io/vega@v0.79.0/cmd/data-node/commands/networkhistory/copy.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package networkhistory 17 18 import ( 19 "context" 20 "errors" 21 "fmt" 22 23 "code.vegaprotocol.io/vega/datanode/config" 24 "code.vegaprotocol.io/vega/logging" 25 ) 26 27 type copyCmd struct { 28 config.VegaHomeFlag 29 config.Config 30 } 31 32 func (cmd *copyCmd) Execute(args []string) error { 33 ctx, cfunc := context.WithCancel(context.Background()) 34 defer cfunc() 35 cfg := logging.NewDefaultConfig() 36 cfg.Custom.Zap.Level = logging.InfoLevel 37 cfg.Environment = "custom" 38 log := logging.NewLoggerFromConfig( 39 cfg, 40 ) 41 defer log.AtExit() 42 43 if len(args) != 2 { 44 return errors.New("expected <history-segment-id> <output-file>") 45 } 46 47 segmentID := args[0] 48 outputPath := args[1] 49 50 client := getDatanodeAdminClient(log, cmd.Config) 51 reply, err := client.CopyHistorySegmentToFile(ctx, segmentID, outputPath) 52 if err != nil { 53 return fmt.Errorf("failed to copy history segment to file: %w", err) 54 } 55 56 if reply.Err != nil { 57 return reply.Err 58 } 59 60 log.Info(reply.Reply) 61 62 return nil 63 }