Browse Source

Test copying of a snapshot works

master zfs_backup_tool_part_5
Robert R. Russell 1 year ago
parent
commit
95160e1023
Signed by: robert GPG Key ID: 5F49E26CC6B3E4B6
  1. 29
      main.go
  2. 32
      snapshot.go

29
main.go

@ -4,16 +4,15 @@ import (
"bufio"
"bytes"
"fmt"
"io"
"os/exec"
"regexp"
"strings"
)
var _ = exec.Cmd{}
var _ = bufio.Reader{}
var zfsRegex = regexp.MustCompile(ZfsSnapshotNameRegex)
var snapshotLineRegex = regexp.MustCompile("^" + PoolNameRegex + "@" + ZfsSnapshotNameRegex + ".*$")
var snapshotLineRegex = regexp.MustCompile("^" + PoolNameRegex + "@" +
ZfsSnapshotNameRegex + ".*$")
func main() {
var listCommand = exec.Command("zfs", "list", "-Hrt", "snapshot", "dpool")
@ -31,7 +30,27 @@ func main() {
var temp = strings.SplitN(snapScanner.Text(), "\t", 2)
var snapshot = ParseSnapshot(temp[0])
if snapshot != nil {
fmt.Println("I found snapshot", snapshot.Name(), "at", snapshot.Path())
var sender = exec.Command("zfs", "send", "-c",
snapshot.String())
var inData, err = sender.StdoutPipe()
if err != nil {
break
}
var receiver = exec.Command("zfs", "receive", "-x",
"mountpoint", "backups/test/"+snapshot.Path())
var outData io.WriteCloser
outData, err = receiver.StdinPipe()
if err != nil {
break
}
fmt.Println("Writing ", snapshot.String(), " to backups/test")
buf := make([]byte, 4*1024*1024)
sender.Start()
receiver.Start()
io.CopyBuffer(outData, inData, buf)
sender.Wait()
receiver.Wait()
break
}
}
}

32
snapshot.go

@ -3,13 +3,15 @@ package main
import (
"errors"
"fmt"
"io"
"os/exec"
"regexp"
"strconv"
"strings"
"time"
)
var _ = time.Time{}
var _ = exec.Command("echo", "hi")
/*
Snapshot represents a snapshot on a zfs pool and filesystem.
@ -190,6 +192,34 @@ func CompareSnapshotDates(x Snapshot, y Snapshot) (int, error) {
return 0, nil
}
/*
IncrementalSender sets up a zfs send command which will send an incremental snapshot starting
at from and including through. Sender will be overwritten.
*/
func IncrementalSender(from, through Snapshot, sender *exec.Cmd) (snapData io.ReadCloser, err error) {
sender = exec.Command("zfs", "send", "-c", "-i", from.Name(), through.Name())
snapData, err = sender.StdoutPipe()
return
}
/*
Sender sets up a zfs send command which will send a full snapshot. Sender will be overwritten.
*/
func Sender(through Snapshot, sender *exec.Cmd) (snapdata io.ReadCloser, err error) {
sender = exec.Command("zfs", "send", "-c", through.Name())
snapdata, err = sender.StdoutPipe()
return
}
/*
Receiver sets up a zfs receive command which will receive a snapshot
*/
func Receiver(backupPath string, snap Snapshot, receiver *exec.Cmd) (snapdata io.WriteCloser, err error) {
receiver = exec.Command("zfs", "receive", "-x", "mountpoint", backupPath+snap.Path())
snapdata, err = receiver.StdinPipe()
return
}
/*
func testSnapshot(possible string, increment string) (bool, bool) {
var matches = zfsRegex.FindStringSubmatch(possible)

Loading…
Cancel
Save