Started implementing SQL Logs.
Only MariaDB yet. Interface usage comes soon.
This commit is contained in:
parent
077459c6e0
commit
33b44a6ea5
3 changed files with 27 additions and 4 deletions
|
|
@ -6,10 +6,13 @@ import (
|
|||
"compress/flate"
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"scabiosa/Logging"
|
||||
"scabiosa/SQL"
|
||||
"time"
|
||||
)
|
||||
|
||||
func CreateBakFile(filename string, folderPath string, destinationPath string) string {
|
||||
|
|
@ -29,6 +32,10 @@ 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())
|
||||
|
||||
|
||||
return fileName
|
||||
}
|
||||
|
||||
|
|
@ -40,7 +47,8 @@ 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())
|
||||
filepath.Walk(folderPath, func(file string, fi os.FileInfo, err error) error {
|
||||
header, err := tar.FileInfoHeader(fi, file)
|
||||
if err != nil {
|
||||
|
|
@ -78,4 +86,6 @@ 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())
|
||||
}
|
||||
|
|
@ -5,11 +5,14 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/Azure/azure-storage-file-go/azfile"
|
||||
"github.com/google/uuid"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"scabiosa/Logging"
|
||||
"scabiosa/SQL"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type AzureFileStorage struct{
|
||||
|
|
@ -46,6 +49,8 @@ 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())
|
||||
|
||||
err = azfile.UploadFileToAzureFile(ctx, file, fileURL,
|
||||
azfile.UploadToAzureFileOptions{
|
||||
|
|
@ -58,6 +63,8 @@ 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())
|
||||
}
|
||||
|
||||
func readConfig() []byte {
|
||||
|
|
|
|||
12
main.go
12
main.go
|
|
@ -1,25 +1,31 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"os"
|
||||
"scabiosa/Logging"
|
||||
"scabiosa/SQL"
|
||||
"scabiosa/StorageTypes"
|
||||
"scabiosa/Tools"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main(){
|
||||
config := GetConfig()
|
||||
config := Tools.GetConfig()
|
||||
|
||||
SQL.CreateDefaultTables(SQL.GetMariaDBInstance())
|
||||
|
||||
for _, backupItem := range config.FolderToBackup{
|
||||
storage := StorageTypes.CheckStorageType(backupItem.StorageType)
|
||||
destPath := checkTmpPath(config, backupItem.CreateLocalBackup)
|
||||
|
||||
bakFile := 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())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -33,7 +39,7 @@ func getTimeSuffix() string{
|
|||
return "_" + currTime.Format("02-01-2006_15-04")
|
||||
}
|
||||
|
||||
func checkTmpPath(config Config, createLocalBackup bool) string{
|
||||
func checkTmpPath(config Tools.Config, createLocalBackup bool) string{
|
||||
logger := Logging.DetailedLogger("mainThread", "checkTmpPath")
|
||||
if !createLocalBackup{
|
||||
if _, err := os.Stat("tmp"); os.IsNotExist(err) {
|
||||
|
|
|
|||
Reference in a new issue