Skip to content

Commit

Permalink
mssql backup minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LobbyLobster committed Dec 11, 2024
1 parent 4a19290 commit 5e47667
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"monodb-backup/notify"
"os"
"runtime"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -103,7 +104,12 @@ func Backup() {
return
}
for _, db := range params.Databases {
dst := strings.TrimSuffix(params.BackupDestination, "/") + "/" + db
var dst string
if runtime.GOOS == "windows" {
dst = strings.TrimSuffix(params.BackupDestination, "/") + db
} else {
dst = strings.TrimSuffix(params.BackupDestination, "/") + "/" + db
}
if params.BackupAsTables && db != "mysql" {
dumpPaths, names, err := dumpDBWithTables(db, dst)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions backup/mssql_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func InitializeMSSQL() {
logger.Fatal("Remote should be enabled when backing up MSSQL databases.")
return
}
connString := fmt.Sprintf("server=%s;user id=%s;password=%s;port=%s;encrypt=disable;trustServerCertificate=true",
connString := fmt.Sprintf("server=%s;user id=%s;password=%s;port=%s;encrypt=disable;trustServerCertificate=true;trusted_connection=yes",
host, user, password, port)

// Create connection pool
Expand Down Expand Up @@ -83,7 +83,7 @@ func dumpMSSQLDB(dbName, dst string) (string, string, error) {

logger.Info("MSSQL backup started. DB: " + dbName + " - Encrypted: " + strconv.FormatBool(encrypted))
name = dumpName(dbName, params.Rotation, "") + ".bak"
dumpPath := dst + filepath.FromSlash(name)
dumpPath := dst + "\\" + filepath.FromSlash(name)

if err := os.MkdirAll(filepath.Dir(dumpPath), 0770); err != nil {
logger.Error("Couldn't create parent directories at backup destination " + dst + ". Name: " + name + " - Error: " + err.Error())
Expand All @@ -103,7 +103,7 @@ func dumpMSSQLDB(dbName, dst string) (string, string, error) {
_, err := mssqlDB.ExecContext(ctx,
"BACKUP DATABASE "+dbName+
" TO DISK = '"+dumpPath+"'"+
" WITH COMPRESSION;") /* `
" WITH FORMAT, INIT, NAME = 'Full Backup of "+dbName+"';") /* `
BACKUP DATABASE `+dbName+`
TO DISK = '`+dumpPath+`'
WITH FORMAT, INIT, NAME = 'Full Backup of `+dbName+`';
Expand Down

0 comments on commit 5e47667

Please sign in to comment.