From a23791daa5d245b39d15c8f516eedfd0c506e21d Mon Sep 17 00:00:00 2001 From: netbenix Date: Tue, 23 Nov 2021 08:23:18 +0100 Subject: [PATCH] Chaged static sql instance to dynamic instance --- StorageTypes/AzureFileStorage.go | 6 ++---- Tools/Compression.go | 11 ++++------- main.go | 5 ++--- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/StorageTypes/AzureFileStorage.go b/StorageTypes/AzureFileStorage.go index bfcb84f..73837e1 100644 --- a/StorageTypes/AzureFileStorage.go +++ b/StorageTypes/AzureFileStorage.go @@ -49,8 +49,7 @@ func (azure AzureFileStorage) upload(fileName string){ ctx := context.Background() fmt.Printf("[%s] Starting upload to Azure File Share...\n", strings.Trim(filepath.Base(fileName), ".bak")) - //TODO Remove Hardcoded SQL Instance - SQL.NewLogEntry(SQL.GetMariaDBInstance(), uuid.New(), SQL.LogInfo, filepath.Base(fileName), SQL.SQLStage_Upload, SQL.REMOTE_AZURE_FILE, "Starting upload.", time.Now()) + SQL.NewLogEntry(SQL.GetSQLInstance(), uuid.New(), SQL.LogInfo, filepath.Base(fileName), SQL.SQLStage_Upload, SQL.REMOTE_AZURE_FILE, "Starting upload.", time.Now()) err = azfile.UploadFileToAzureFile(ctx, file, fileURL, azfile.UploadToAzureFileOptions{ @@ -63,8 +62,7 @@ func (azure AzureFileStorage) upload(fileName string){ }}) fmt.Printf("[%s] Upload finished.\n", strings.Trim(filepath.Base(fileName), ".bak")) - //TODO Remove Hardcoded SQL Instance - SQL.NewLogEntry(SQL.GetMariaDBInstance(), uuid.New(), SQL.LogInfo, filepath.Base(fileName), SQL.SQLStage_Upload, SQL.REMOTE_AZURE_FILE, "Finished upload.", time.Now()) + SQL.NewLogEntry(SQL.GetSQLInstance(), uuid.New(), SQL.LogInfo, filepath.Base(fileName), SQL.SQLStage_Upload, SQL.REMOTE_AZURE_FILE, "Finished upload.", time.Now()) } func readConfig() []byte { diff --git a/Tools/Compression.go b/Tools/Compression.go index 957d66d..0a9cd27 100644 --- a/Tools/Compression.go +++ b/Tools/Compression.go @@ -1,4 +1,4 @@ -package main +package Tools import ( "archive/tar" @@ -32,8 +32,7 @@ func CreateBakFile(filename string, folderPath string, destinationPath string) s logger.Fatal(err) } - //TODO Remove Hardcoded SQL Instance - SQL.NewLogEntry(SQL.GetMariaDBInstance(), uuid.New(), SQL.LogInfo, filepath.Base(folderPath), SQL.SQLStage_Compress, SQL.REMOTE_NONE, "File successfully written.", time.Now()) + SQL.NewLogEntry(SQL.GetSQLInstance(), uuid.New(), SQL.LogInfo, filepath.Base(folderPath), SQL.SQLStage_Compress, SQL.REMOTE_NONE, "File successfully written.", time.Now()) return fileName @@ -47,8 +46,7 @@ func compress(folderPath string, buf io.Writer){ tw := tar.NewWriter(zr) fmt.Printf("[%s] Start compression...\n", filepath.Base(folderPath)) - //TODO Remove Hardcoded SQL Instance - SQL.NewLogEntry(SQL.GetMariaDBInstance(), uuid.New(), SQL.LogInfo, filepath.Base(folderPath), SQL.SQLStage_Compress, SQL.REMOTE_NONE, "Start compression", time.Now()) + SQL.NewLogEntry(SQL.GetSQLInstance(), uuid.New(), SQL.LogInfo, filepath.Base(folderPath), SQL.SQLStage_Compress, SQL.REMOTE_NONE, "Start compression", time.Now()) filepath.Walk(folderPath, func(file string, fi os.FileInfo, err error) error { header, err := tar.FileInfoHeader(fi, file) if err != nil { @@ -86,6 +84,5 @@ func compress(folderPath string, buf io.Writer){ fmt.Printf("[%s] Compression Done.\n", filepath.Base(folderPath)) - //TODO Remove Hardcoded SQL Instance - SQL.NewLogEntry(SQL.GetMariaDBInstance(), uuid.New(), SQL.LogInfo, filepath.Base(folderPath), SQL.SQLStage_Compress, SQL.REMOTE_NONE, "Compression complete.", time.Now()) + SQL.NewLogEntry(SQL.GetSQLInstance(), uuid.New(), SQL.LogInfo, filepath.Base(folderPath), SQL.SQLStage_Compress, SQL.REMOTE_NONE, "Compression complete.", time.Now()) } \ No newline at end of file diff --git a/main.go b/main.go index 3a82cbc..a675089 100644 --- a/main.go +++ b/main.go @@ -19,13 +19,12 @@ func main(){ storage := StorageTypes.CheckStorageType(backupItem.StorageType) destPath := checkTmpPath(config, backupItem.CreateLocalBackup) - bakFile := CreateBakFile(backupItem.BackupName + getTimeSuffix(), backupItem.FolderPath, destPath) + bakFile := Tools.CreateBakFile(backupItem.BackupName + getTimeSuffix(), backupItem.FolderPath, destPath) StorageTypes.UploadFile(storage, destPath + string(os.PathSeparator) + bakFile) if !backupItem.CreateLocalBackup { _ = os.Remove(destPath + string(os.PathSeparator) + bakFile) - //TODO Remove Hardcoded SQL Instance - SQL.NewLogEntry(SQL.GetMariaDBInstance(), uuid.New(), SQL.LogInfo, backupItem.BackupName, SQL.SQLStage_DeleteTmp, SQL.REMOTE_NONE, "Deleted tmp file" ,time.Now()) + SQL.NewLogEntry(SQL.GetSQLInstance(), uuid.New(), SQL.LogInfo, backupItem.BackupName, SQL.SQLStage_DeleteTmp, SQL.REMOTE_NONE, "Deleted tmp file" ,time.Now()) } }