From d8833e177ed820082241e12a03f655ba13f8aa77 Mon Sep 17 00:00:00 2001 From: Son Roy Almerol Date: Mon, 9 Dec 2024 09:00:39 -0500 Subject: [PATCH] revert sftp snapshot --- internal/agent/sftp/sftp.go | 15 +------ internal/agent/snapshots/windows.go | 4 +- internal/backend/backup/jobrun.go | 19 --------- internal/store/snapshot.go | 62 ----------------------------- 4 files changed, 3 insertions(+), 97 deletions(-) delete mode 100644 internal/store/snapshot.go diff --git a/internal/agent/sftp/sftp.go b/internal/agent/sftp/sftp.go index 40016ce..cb234bf 100644 --- a/internal/agent/sftp/sftp.go +++ b/internal/agent/sftp/sftp.go @@ -130,19 +130,6 @@ func handleRequests(ctx context.Context, requests <-chan *ssh.Request, sftpReque case "ping": sftpRequest <- false req.Reply(true, []byte("pong")) - case "snapshot": - sftpRequest <- false - driveLetter := string(req.Payload[1:]) - if driveLetter != "" { - _, err := snapshots.Snapshot(driveLetter, true) - if err != nil { - req.Reply(false, []byte(fmt.Sprintf("failed to initialize snapshot: %v", err))) - return - } - req.Reply(true, []byte("success")) - } else { - req.Reply(false, nil) - } default: sftpRequest <- false req.Reply(false, nil) @@ -156,7 +143,7 @@ func handleRequests(ctx context.Context, requests <-chan *ssh.Request, sftpReque func handleSFTP(ctx context.Context, errChan chan string, channel ssh.Channel, driveLetter string) { defer channel.Close() - snapshot, err := snapshots.Snapshot(driveLetter, false) + snapshot, err := snapshots.Snapshot(driveLetter) if err != nil { errChan <- fmt.Sprintf("failed to initialize snapshot: %v", err) return diff --git a/internal/agent/snapshots/windows.go b/internal/agent/snapshots/windows.go index ce07e03..3256700 100644 --- a/internal/agent/snapshots/windows.go +++ b/internal/agent/snapshots/windows.go @@ -27,7 +27,7 @@ func getVSSFolder() (string, error) { return configBasePath, nil } -func Snapshot(driveLetter string, forceNew bool) (*WinVSSSnapshot, error) { +func Snapshot(driveLetter string) (*WinVSSSnapshot, error) { knownSnaps := &KnownSnapshots{registry: "KnownSnaps"} volName := filepath.VolumeName(fmt.Sprintf("%s:", driveLetter)) @@ -40,7 +40,7 @@ func Snapshot(driveLetter string, forceNew bool) (*WinVSSSnapshot, error) { snapshotPath := filepath.Join(vssFolder, driveLetter) if knownSnap, err := knownSnaps.Get(snapshotPath); err == nil { if _, err := vss.Get(snapshotPath); err == nil { - if time.Since(knownSnap.GetTimestamp()) < 15*time.Minute && !forceNew { + if time.Since(knownSnap.GetTimestamp()) < 2*time.Minute { return knownSnap, nil } } diff --git a/internal/backend/backup/jobrun.go b/internal/backend/backup/jobrun.go index b68316a..b5deb47 100644 --- a/internal/backend/backup/jobrun.go +++ b/internal/backend/backup/jobrun.go @@ -130,25 +130,6 @@ func RunBackup(job *store.Job, storeInstance *store.Store, waitChan chan struct{ _ = FixDatastore(job, storeInstance) - if isAgent { - snapOk, err := storeInstance.AgentSnapshot(target) - if err != nil { - if agentMount != nil { - agentMount.Unmount() - } - cancel() - return nil, fmt.Errorf("RunBackup: agent snapshot error -> %w", err) - } - - if !snapOk { - if agentMount != nil { - agentMount.Unmount() - } - cancel() - return nil, fmt.Errorf("RunBackup: agent snapshot error") - } - } - cmd := exec.Command("/usr/bin/proxmox-backup-client", cmdArgs...) cmd.Env = os.Environ() cmd.Env = append(cmd.Env, fmt.Sprintf("PBS_PASSWORD=%s", storeInstance.APIToken.Value)) diff --git a/internal/store/snapshot.go b/internal/store/snapshot.go deleted file mode 100644 index 5db2f0f..0000000 --- a/internal/store/snapshot.go +++ /dev/null @@ -1,62 +0,0 @@ -//go:build linux - -package store - -import ( - "fmt" - "os" - "path/filepath" - "strings" - "time" - - "github.com/sonroyaalmerol/pbs-plus/internal/utils" - "golang.org/x/crypto/ssh" -) - -func (storeInstance *Store) AgentSnapshot(agentTarget *Target) (bool, error) { - privKeyDir := filepath.Join(DbBasePath, "agent_keys") - privKeyFile := filepath.Join(privKeyDir, strings.ReplaceAll(fmt.Sprintf("%s.key", agentTarget.Name), " ", "-")) - - pemBytes, err := os.ReadFile(privKeyFile) - if err != nil { - return false, fmt.Errorf("AgentSnapshot: error reading private key file -> %w", err) - } - - signer, err := ssh.ParsePrivateKey(pemBytes) - if err != nil { - return false, fmt.Errorf("AgentSnapshot: error parsing private key -> %w", err) - } - - agentPath := strings.TrimPrefix(agentTarget.Path, "agent://") - agentPathParts := strings.Split(agentPath, "/") - agentHost := agentPathParts[0] - agentDrive := agentPathParts[1] - agentDriveRune := []rune(agentDrive)[0] - agentPort, err := utils.DriveLetterPort(agentDriveRune) - - sshConfig := &ssh.ClientConfig{ - User: "proxmox", - Auth: []ssh.AuthMethod{ssh.PublicKeys(signer)}, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - Timeout: time.Second * 2, - } - - client, err := ssh.Dial("tcp", fmt.Sprintf("%s:%s", agentHost, agentPort), sshConfig) - if err != nil { - return false, fmt.Errorf("AgentSnapshot: error dialing ssh client -> %w", err) - } - defer client.Close() - - session, err := client.NewSession() - if err != nil { - return false, fmt.Errorf("AgentSnapshot: error creating new ssh session -> %w", err) - } - defer session.Close() - - resp, err := session.SendRequest("snapshot", true, []byte(agentDrive)) - if err != nil { - return false, fmt.Errorf("AgentSnapshot: error sending ping request -> %w", err) - } - - return resp, nil -}