This repository has been archived on 2026-03-18. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
scabiosa/main.go
netbenix 33b44a6ea5 Started implementing SQL Logs.
Only MariaDB yet. Interface usage comes soon.
2021-11-22 21:29:19 +01:00

55 lines
1.4 KiB
Go

package main
import (
"github.com/google/uuid"
"os"
"scabiosa/Logging"
"scabiosa/SQL"
"scabiosa/StorageTypes"
"scabiosa/Tools"
"time"
)
func main(){
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())
}
}
}
func getTimeSuffix() string{
currTime := time.Now()
return "_" + currTime.Format("02-01-2006_15-04")
}
func checkTmpPath(config Tools.Config, createLocalBackup bool) string{
logger := Logging.DetailedLogger("mainThread", "checkTmpPath")
if !createLocalBackup{
if _, err := os.Stat("tmp"); os.IsNotExist(err) {
dirErr := os.Mkdir("tmp", 600)
if dirErr != nil {
logger.Fatal(err)
}
}
return "tmp"
}
return config.LocalBackupPath
}