github.com/matrixorigin/matrixone@v1.2.0/pkg/backup/utils.go (about) 1 // Copyright 2023 Matrix Origin 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 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package backup 16 17 import ( 18 "context" 19 "strconv" 20 "strings" 21 22 "github.com/matrixorigin/matrixone/pkg/common/moerr" 23 "github.com/matrixorigin/matrixone/pkg/sql/parsers/tree" 24 "github.com/matrixorigin/matrixone/pkg/version" 25 ) 26 27 func buildInfo() string { 28 infos := []string{ 29 "GoVersion: " + version.GoVersion, 30 "BranchName: " + version.BranchName, 31 "CommitID: " + version.CommitID, 32 "BuildTime: " + version.BuildTime, 33 "Version: " + version.Version, 34 } 35 return strings.Join(infos, "|") 36 } 37 38 // SaveLaunchConfigPath saves all config file paths for the standalone config 39 func SaveLaunchConfigPath(typ string, paths []string) { 40 launchConfigPaths[typ] = paths 41 } 42 43 func getS3Config(ctx context.Context, option []string) (*s3Config, error) { 44 conf := &s3Config{} 45 for i := 0; i < len(option); i += 2 { 46 switch strings.ToLower(option[i]) { 47 case "endpoint": 48 conf.endpoint = option[i+1] 49 case "region": 50 conf.region = option[i+1] 51 case "access_key_id": 52 conf.accessKeyId = option[i+1] 53 case "secret_access_key": 54 conf.secretAccessKey = option[i+1] 55 case "bucket": 56 conf.bucket = option[i+1] 57 case "filepath": 58 conf.filepath = option[i+1] 59 case "compression": 60 conf.compression = option[i+1] 61 case "provider": 62 conf.provider = option[i+1] 63 case "role_arn": 64 conf.roleArn = option[i+1] 65 case "external_id": 66 conf.externalId = option[i+1] 67 case "format": 68 format := strings.ToLower(option[i+1]) 69 if format != tree.CSV && format != tree.JSONLINE { 70 return nil, moerr.NewBadConfig(ctx, "the format '%s' is not supported", format) 71 } 72 conf.format = format 73 case "jsondata": 74 jsondata := strings.ToLower(option[i+1]) 75 if jsondata != tree.OBJECT && jsondata != tree.ARRAY { 76 return nil, moerr.NewBadConfig(ctx, "the jsondata '%s' is not supported", jsondata) 77 } 78 conf.jsonData = jsondata 79 conf.format = tree.JSONLINE 80 case "is_minio": 81 isMinioData := strings.ToLower(option[i+1]) 82 if isMinioData != "true" && isMinioData != "false" { 83 return nil, moerr.NewBadConfig(ctx, "the is_minio '%s' is not supported", isMinioData) 84 } 85 if isMinioData == "true" { 86 conf.isMinio = true 87 } else { 88 conf.isMinio = false 89 } 90 case "parallelism": 91 parallelismData := strings.ToLower(option[i+1]) 92 parall, err := strconv.ParseUint(parallelismData, 10, 16) 93 if err != nil { 94 return nil, moerr.NewBadConfig(ctx, "the parallelism '%s' is invalid", parallelismData) 95 } 96 conf.parallelism = uint16(parall) 97 default: 98 return nil, moerr.NewBadConfig(ctx, "the keyword '%s' is not support", strings.ToLower(option[i])) 99 } 100 } 101 if conf.format == tree.JSONLINE && len(conf.jsonData) == 0 { 102 return nil, moerr.NewBadConfig(ctx, "the jsondata must be specified") 103 } 104 if len(conf.format) == 0 { 105 conf.format = tree.CSV 106 } 107 return conf, nil 108 }