replace use of shell w/ direct calls

This commit is contained in:
Sam Hoffman
2026-01-31 01:55:24 -05:00
parent 297c499bba
commit 7774a5b956
2 changed files with 92 additions and 46 deletions

View File

@@ -10,6 +10,8 @@ import (
"strconv"
"strings"
"time"
"git.gentoo.party/sam/thanks/internal/runner"
)
type Snapshot struct {
@@ -113,3 +115,49 @@ func Snapshots(ctx context.Context, target string) ([]Snapshot, error) {
return snaps, err
}
func FullSend(ctx context.Context, snap, sshTarget, target string) ([]byte, error) {
return runner.Pipeline(
exec.CommandContext(
ctx,
"zfs",
"send",
"-Lec",
snap,
),
exec.CommandContext(
ctx,
"ssh",
sshTarget,
"zfs",
"recv",
"-Fu",
target,
),
)
}
func IncrementalSend(ctx context.Context, prevSnapName, newSnapName, sshTarget, target string) ([]byte, error) {
return runner.Pipeline(
exec.CommandContext(
ctx,
"zfs",
"send",
fmt.Sprintf("-I@%s", prevSnapName),
newSnapName,
),
exec.CommandContext(
ctx,
"ssh",
sshTarget,
"zfs",
"recv",
target,
),
)
}
func Destroy(ctx context.Context, target string) ([]byte, error) {
cmd := exec.CommandContext(ctx, "zfs", "destroy", target)
return cmd.CombinedOutput()
}