partial implementation of the support for searching.

master
Robert R. Russell 2 years ago
parent 3705d22d0e
commit 844f8ada57
Signed by: robert
GPG Key ID: 5F49E26CC6B3E4B6
  1. 46
      main.go

@ -3,6 +3,7 @@ package main
import (
"bufio"
"bytes"
"container/list"
"fmt"
"os/exec"
"regexp"
@ -15,13 +16,9 @@ var snapshotLineRegex = regexp.MustCompile("^" + PoolNameRegex + "@" +
ZfsSnapshotNameRegex + ".*$")
func main() {
var listCommand = exec.Command("zfs", "list", "-Hrt", "snapshot", "dpool")
var listCommandOutput, err = listCommand.CombinedOutput()
var snapScanner = bufio.NewScanner(bytes.NewReader(listCommandOutput))
var snapScanner, err = createSnapshotScanner("dpool")
var snapshots = make(map[string]snapshotList)
_ = snapshots
if err != nil {
fmt.Println(listCommand)
fmt.Println("Error trying to list snapshots:", err.Error())
for snapScanner.Scan() {
fmt.Println(snapScanner.Text())
@ -61,4 +58,43 @@ func main() {
for i := range snapshots {
sort.Sort(snapshots[i])
}
//Lets get the list of snapshots in the backup pool
snapScanner, err = createSnapshotScanner("backups")
if err != nil {
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, err = ParseSnapshot(temp[0])
if err != nil {
// Ignore the bad input
}
snapshots[snapshot.Path()].addSnapshot(snapshot)
}
}
for i := range snapshots {
sort.Sort(snapshots[i])
}
var missingFromBackup list.List
_ = missingFromBackup
for i := 0; i < len(snapshots["dpool"].Snapshots); i++ {
i3 := sort.Search(len(snapshots["backups/encrypted/mars/dpool"].
Snapshots), func(i2 int) bool {
return snapshots["backups/encrypted/mars/dpool"].Snapshots[i2].
TimeStamp.After(snapshots["dpool"].Snapshots[i].TimeStamp)
})
if i3 != len(snapshots["backups/encrypted/mars/dpool"].Snapshots) {
}
}
}
func createSnapshotScanner(pool string) (scanner *bufio.Scanner, err error) {
listCommand := exec.Command("zfs", "list", "-Hrt", "snapshot", pool)
output, err := listCommand.CombinedOutput()
return bufio.NewScanner(bytes.NewReader(output)), err
}

Loading…
Cancel
Save