The zfs backup tool
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
958 B

package main
import (
"bufio"
"bytes"
"fmt"
"os/exec"
"regexp"
"strings"
)
var _ = exec.Cmd{}
var _ = bufio.Reader{}
var zfsRegex = regexp.MustCompile(ZfsSnapshotNameRegex)
var snapshotLineRegex = regexp.MustCompile("^" + PoolNameRegex + "@" + ZfsSnapshotNameRegex + ".*$")
func main() {
var listCommand = exec.Command("zfs", "list", "-Hrt", "snapshot", "dpool")
var snapList, err = listCommand.CombinedOutput()
var snapScanner = bufio.NewScanner(bytes.NewReader(snapList))
if err != nil {
fmt.Println(listCommand)
fmt.Println("Error trying to list snapshots:", err.Error())
for snapScanner.Scan() {
fmt.Println(snapScanner.Text())
}
}
for snapScanner.Scan() {
if snapshotLineRegex.MatchString(snapScanner.Text()) {
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())
}
}
}
}