feat(General): Local backups now possible
Just use RemoteStorageType 'none' and insert your localpath into targetPath
This commit is contained in:
parent
057d90eb33
commit
7e4c05f411
1 changed files with 21 additions and 10 deletions
25
main.go
25
main.go
|
|
@ -17,17 +17,28 @@ func main(){
|
||||||
SQL.CreateDefaultTables(SQL.GetSQLInstance())
|
SQL.CreateDefaultTables(SQL.GetSQLInstance())
|
||||||
|
|
||||||
for _, backupItem := range config.FolderToBackup{
|
for _, backupItem := range config.FolderToBackup{
|
||||||
storage := StorageTypes.CheckStorageType(backupItem.StorageType)
|
|
||||||
destPath := checkTmpPath(config, backupItem.CreateLocalBackup, storage)
|
var storage StorageTypes.Storage
|
||||||
|
var destPath string
|
||||||
|
|
||||||
|
if backupItem.RemoteStorageType != "none"{
|
||||||
|
storage = StorageTypes.CheckStorageType(backupItem.RemoteStorageType)
|
||||||
|
destPath = checkTmpPath(backupItem.CreateLocalBackup, backupItem.TargetPath)
|
||||||
|
} else {
|
||||||
|
destPath = backupItem.TargetPath
|
||||||
|
}
|
||||||
|
|
||||||
bakFile := Compressor.CreateBakFile(backupItem.BackupName + getTimeSuffix(), backupItem.FolderPath, destPath, backupItem.BackupName)
|
bakFile := Compressor.CreateBakFile(backupItem.BackupName + getTimeSuffix(), backupItem.FolderPath, destPath, backupItem.BackupName)
|
||||||
StorageTypes.UploadFile(storage, bakFile, backupItem.BackupName, backupItem.TargetPath)
|
|
||||||
|
|
||||||
if !backupItem.CreateLocalBackup {
|
if backupItem.RemoteStorageType != "none"{
|
||||||
|
StorageTypes.UploadFile(storage, bakFile, backupItem.BackupName, backupItem.TargetPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !backupItem.CreateLocalBackup && backupItem.RemoteStorageType != "none"{
|
||||||
_ = os.Remove(bakFile)
|
_ = os.Remove(bakFile)
|
||||||
SQL.NewLogEntry(SQL.GetSQLInstance(), 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())
|
||||||
}
|
}
|
||||||
SQL.NewBackupEntry(SQL.GetSQLInstance(), backupItem.BackupName, time.Now(), backupItem.CreateLocalBackup, backupItem.FolderPath, StorageTypes.CheckRemoteStorageType(backupItem.StorageType), StorageTypes.GetAzureStorage().TargetDirectory)
|
SQL.NewBackupEntry(SQL.GetSQLInstance(), backupItem.BackupName, time.Now(), backupItem.CreateLocalBackup, backupItem.FolderPath, StorageTypes.CheckRemoteStorageType(backupItem.RemoteStorageType), StorageTypes.GetAzureStorage().TargetDirectory)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -39,7 +50,7 @@ func getTimeSuffix() string{
|
||||||
return "_" + currTime.Format("02-01-2006_15-04")
|
return "_" + currTime.Format("02-01-2006_15-04")
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkTmpPath(config Tools.Config, createLocalBackup bool, storage StorageTypes.Storage) string{
|
func checkTmpPath(createLocalBackup bool, targetPath string) string{
|
||||||
logger := Logging.DetailedLogger("mainThread", "checkTmpPath")
|
logger := Logging.DetailedLogger("mainThread", "checkTmpPath")
|
||||||
if !createLocalBackup {
|
if !createLocalBackup {
|
||||||
if _, err := os.Stat("tmp"); os.IsNotExist(err) {
|
if _, err := os.Stat("tmp"); os.IsNotExist(err) {
|
||||||
|
|
@ -51,5 +62,5 @@ func checkTmpPath(config Tools.Config, createLocalBackup bool, storage StorageTy
|
||||||
return "tmp"
|
return "tmp"
|
||||||
}
|
}
|
||||||
|
|
||||||
return config.LocalBackupPath
|
return targetPath
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue