This commit is contained in:
2026-02-15 13:13:11 +01:00
parent 8b592db3dd
commit 08f9f5ab0a
7 changed files with 234 additions and 35 deletions

View File

@@ -6,7 +6,9 @@ import (
"io"
"log"
"net/http"
"os"
"os/exec"
"strings"
"time"
"github.com/minio/minio-go/v7"
@@ -138,6 +140,33 @@ func (l *LocalBackend) Upload(ctx context.Context, key string, data io.Reader, s
return fmt.Errorf("local backend upload not supported via storage interface, use zfs receive endpoint")
}
// Receive receives a ZFS snapshot stream and restores it to the local dataset
func (l *LocalBackend) Receive(snapshotName string, data io.Reader) error {
// Extract the target dataset from the snapshot name
// snapshotName format: dataset@name -> we want just the dataset part
parts := strings.Split(snapshotName, "@")
if len(parts) != 2 {
return fmt.Errorf("invalid snapshot name format: %s", snapshotName)
}
targetDataset := parts[0]
log.Printf("Receiving ZFS snapshot to %s", targetDataset)
// Use zfs recv to receive the snapshot
cmd := exec.Command("zfs", "recv", targetDataset)
cmd.Stdin = data
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("zfs recv failed: %v", err)
}
log.Printf("Successfully received snapshot: %s", snapshotName)
return nil
}
// Download creates a zfs send stream
func (l *LocalBackend) Download(ctx context.Context, key string) (io.ReadCloser, error) {
cmd := exec.CommandContext(ctx, "zfs", "send", key)