Skip to content

Commit

Permalink
changed SSH_AUTH_SOCK
Browse files Browse the repository at this point in the history
  • Loading branch information
LobbyLobster committed Mar 20, 2024
1 parent d2b85d8 commit 4cc69af
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions backup/sftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"monodb-backup/notify"
"net"
"os"
"os/user"
"strings"

"github.com/pkg/sftp"
Expand All @@ -15,10 +16,18 @@ import (
func SendSFTP(srcPath, dstPath, db string, target config.Target) {
dstPath = target.Path + "/" + nameWithPath(dstPath)
logger.Info("SFTP transfer started.\n Source: " + srcPath + " - Destination: " + target.Host + ":" + dstPath)
sock, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK"))

currentUser, err := user.Current()
if err != nil {
logger.Error("Couldn't get current user's id to get SSH socket" + err.Error())
notify.SendAlarm("Couldn't upload backup "+srcPath+" to "+target.Host+":"+dstPath+"\nCouldn't get current user's id to get SSH socket - Error: "+err.Error(), true)
return
}

sock, err := net.Dial("unix", "/run/user/"+currentUser.Uid+"/keyring/ssh")
if err != nil {
logger.Error("Couldn't get environment variable SSH_AUTH_SOCK - Error: " + err.Error())
notify.SendAlarm("Couldn't upload backup "+srcPath+" to "+target.Host+":"+dstPath+"\nCouldn't get environment variable SSH_AUTH_SOCK - Error: "+err.Error(), true)
logger.Error("Couldn't connect to SSH socket - Error: " + err.Error())
notify.SendAlarm("Couldn't upload backup "+srcPath+" to "+target.Host+":"+dstPath+"\nCouldn't connect to SSH socket - Error: "+err.Error(), true)
return
}

Expand Down

0 comments on commit 4cc69af

Please sign in to comment.