feat(Config): Added remote target path
This commit is contained in:
parent
b8e9ddd838
commit
cad2dd18d3
5 changed files with 14 additions and 8 deletions
|
|
@ -5,8 +5,8 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/Azure/azure-storage-file-go/azfile"
|
||||
"github.com/google/uuid"
|
||||
"github.com/cheggaaa/pb/v3"
|
||||
"github.com/google/uuid"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
|
@ -24,7 +24,7 @@ type AzureFileStorage struct{
|
|||
}
|
||||
|
||||
|
||||
func (azure AzureFileStorage) upload(fileName string, backupName string){
|
||||
func (azure AzureFileStorage) upload(fileName string, backupName string, destinationPath string){
|
||||
logger := Logging.DetailedLogger("AzureFileStorage", "upload")
|
||||
|
||||
file, err := os.Open(fileName)
|
||||
|
|
@ -43,6 +43,10 @@ func (azure AzureFileStorage) upload(fileName string, backupName string){
|
|||
logger.Fatal(err)
|
||||
}
|
||||
|
||||
if destinationPath != ""{
|
||||
azure.TargetDirectory = destinationPath
|
||||
}
|
||||
|
||||
u, _ := url.Parse(fmt.Sprintf("https://%s.file.core.windows.net/%s/%s/%s", azure.StorageAccountName, azure.FileshareName ,azure.TargetDirectory, filepath.Base(fileName)))
|
||||
|
||||
fileURL := azfile.NewFileURL(*u, azfile.NewPipeline(credential, azfile.PipelineOptions{}))
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@ package StorageTypes
|
|||
import "scabiosa/SQL"
|
||||
|
||||
type Storage interface {
|
||||
upload(fileName string, backupName string)
|
||||
upload(fileName string, backupName string, destinationPath string)
|
||||
}
|
||||
|
||||
func UploadFile(storage Storage, fileName string, backupName string){
|
||||
storage.upload(fileName, backupName)
|
||||
func UploadFile(storage Storage, fileName string, backupName string, destinationPath string){
|
||||
storage.upload(fileName, backupName, destinationPath)
|
||||
}
|
||||
|
||||
func CheckStorageType(storageType string) Storage{
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ type Config struct {
|
|||
BackupName string `json:"backupName"`
|
||||
FolderPath string `json:"folderPath"`
|
||||
StorageType string `json:"storageType"`
|
||||
TargetPath string `json:"targetPath"`
|
||||
CreateLocalBackup bool `json:"createLocalBackup"`
|
||||
} `json:"foldersToBackup"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
"backupName": "",
|
||||
"folderPath": "",
|
||||
"storageType": "",
|
||||
"targetPath": "",
|
||||
"createLocalBackup": false
|
||||
}
|
||||
]
|
||||
|
|
|
|||
6
main.go
6
main.go
|
|
@ -18,10 +18,10 @@ func main(){
|
|||
|
||||
for _, backupItem := range config.FolderToBackup{
|
||||
storage := StorageTypes.CheckStorageType(backupItem.StorageType)
|
||||
destPath := checkTmpPath(config, backupItem.CreateLocalBackup)
|
||||
destPath := checkTmpPath(config, backupItem.CreateLocalBackup, storage)
|
||||
|
||||
bakFile := Compressor.CreateBakFile(backupItem.BackupName + getTimeSuffix(), backupItem.FolderPath, destPath, backupItem.BackupName)
|
||||
StorageTypes.UploadFile(storage, bakFile, backupItem.BackupName)
|
||||
StorageTypes.UploadFile(storage, bakFile, backupItem.BackupName, backupItem.TargetPath)
|
||||
|
||||
if !backupItem.CreateLocalBackup {
|
||||
_ = os.Remove(bakFile)
|
||||
|
|
@ -39,7 +39,7 @@ func getTimeSuffix() string{
|
|||
return "_" + currTime.Format("02-01-2006_15-04")
|
||||
}
|
||||
|
||||
func checkTmpPath(config Tools.Config, createLocalBackup bool) string{
|
||||
func checkTmpPath(config Tools.Config, createLocalBackup bool, storage StorageTypes.Storage) string{
|
||||
logger := Logging.DetailedLogger("mainThread", "checkTmpPath")
|
||||
if !createLocalBackup{
|
||||
if _, err := os.Stat("tmp"); os.IsNotExist(err) {
|
||||
|
|
|
|||
Reference in a new issue