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
2021-11-19 19:49:44 +01:00

49 lines
1 KiB
Go

package main
import (
"os"
"scabiosa/Logging"
"scabiosa/StorageTypes"
"time"
)
func main(){
config := GetConfig()
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)
}
}
}
func getTimeSuffix() string{
currTime := time.Now()
return "_" + currTime.Format("02-01-2006_15-04")
}
func checkTmpPath(config 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
}