Added core functionality
This commit is contained in:
parent
badc3955d7
commit
a9bc6a088a
1 changed files with 43 additions and 3 deletions
46
main.go
46
main.go
|
|
@ -1,9 +1,49 @@
|
|||
package main
|
||||
|
||||
import "scabiosa/StorageTypes"
|
||||
import (
|
||||
"os"
|
||||
"scabiosa/Logging"
|
||||
"scabiosa/StorageTypes"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main(){
|
||||
azure := StorageTypes.GetAzureStorage()
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
StorageTypes.UploadFile(azure)
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue