-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
154 lines (132 loc) · 4.63 KB
/
Copy pathmain.go
File metadata and controls
154 lines (132 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Copyright 2026 IBM Corp.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License
package main
import (
"fmt"
"os"
"github.com/ibm-cloud/ibm-sap-hana-backint-cos/utils/backint"
"github.com/ibm-cloud/ibm-sap-hana-backint-cos/utils/config"
"github.com/ibm-cloud/ibm-sap-hana-backint-cos/utils/cos"
"github.com/ibm-cloud/ibm-sap-hana-backint-cos/utils/global"
"github.com/ibm-cloud/ibm-sap-hana-backint-cos/utils/logging"
"github.com/ibm-cloud/ibm-sap-hana-backint-cos/utils/snappy"
)
func main() {
// Reading and validating the command line arguments
argsValid := true //nolint:ineffassign
dbBackupFunction := false
global.Args, argsValid, dbBackupFunction = config.GetCommandLineArguments()
if !argsValid {
fmt.Println("Error reading command line arguments.")
os.Exit(global.WRONG_PARAMETER)
}
//Printing hdbbackint version and exit
if global.Args.Version {
config.PrintVersion()
os.Exit(global.SUCCESS)
}
// Printing info in case of -check argument
if global.Args.CheckParms {
exitCode := config.CheckParameters()
os.Exit(exitCode)
}
// Executing functions called by snappy agent and exit
if dbBackupFunction {
// Generating the configuration from the parameter file
// configuration settings and defaults.
config.BackintConfig, _ = config.GenerateConfiguration(
global.Args.ParameterFile,
)
if config.BackintConfig == nil {
// Error during generating/validating the configuration
fmt.Println("Error generating the configuration.")
os.Exit(global.WRONG_PARAMETER)
}
if !snappy.Execute(global.Args.Function) {
os.Exit(global.FAILURE)
}
os.Exit(global.SUCCESS)
}
// Reading the input file
// The input file contains information of the objects to be
// backed up / restored.
// The format of the input file contents depends on the function to be executed.
global.InputFileContent = config.ReadInputFile(global.Args.InputFile)
if global.InputFileContent == nil {
fmt.Println("Error: the input file is empty or could not be read.")
os.Exit(global.WRONG_PARAMETER)
}
// Generating the configuration from the parameter file
// configuration settings and defaults.
config.BackintConfig, _ = config.GenerateConfiguration(
global.Args.ParameterFile,
)
if config.BackintConfig == nil {
// Error during generating/validating the configuration
fmt.Println("Error generating the configuration.")
os.Exit(global.WRONG_PARAMETER)
}
// Setting up the logger
global.Logger = logging.SetupLogging()
logging.WriteBackintInfo(global.Logger)
// Checking if the input file contains TOOLOPTION
if config.InputFileContainsTooloption(global.InputFileContent) {
global.Logger.Warning(fmt.Sprintf(
"%s specified in input file."+
" Option is not supported by backint agent.", config.TOOLOPTION,
))
}
// Initializing the variable which holds the messages to print out
// These messages must have a pre-defined format for the HANA system
// to recognize the results of the functions.
logging.BackintResultMsgs = logging.InitializeBackintResultMessages()
// Setting up the connection to IBM Cloud Object Storage
s3Session, s3Client := cos.GenerateCOSSession()
// Checking the existence of the given bucket
if !cos.BucketExists(s3Client) {
global.Logger.Error(fmt.Sprintf(
"Bucket '%s' does not exist.",
config.BackintConfig.BucketName()),
)
os.Exit(global.FAILURE)
}
// Checking if versioning is enabled for given bucket
if !cos.IsBucketVersioning(s3Client, config.BackintConfig.BucketName()) {
global.Logger.Error(fmt.Sprintf(
"Versioning must be enabled for bucket '%s'.",
config.BackintConfig.BucketName()),
)
os.Exit(global.FAILURE)
}
// Executing the given function
success := true
switch global.Args.Function {
case global.BACKUP:
success = backint.Backup(s3Session, s3Client)
case global.DELETE:
success = backint.DeleteCloudObjects(s3Client)
case global.INQUIRE:
success = backint.Inquire(s3Client)
case global.RESTORE:
success = backint.Restore(s3Client)
}
// Dumping the backint result messages to the log file
logging.BackintResultMsgs.Dump()
// Closing the logfile
_ = global.Logger.Writer().Close()
if success {
os.Exit(global.SUCCESS)
}
os.Exit(global.FAILURE)
}