Change of plans

I do not plan on using the tree of snapshots idea.
master
Robert R. Russell 2 years ago
parent b1aac20b20
commit e519615e23
Signed by: robert
GPG Key ID: 5F49E26CC6B3E4B6
  1. 5
      interfaces.go
  2. 12
      main.go
  3. 7
      snapshot.go
  4. 5
      snapshotlist.go
  5. 85
      tree.go

@ -0,0 +1,5 @@
package main
type interval interface {
frequency() frequency
}

@ -4,7 +4,6 @@ import (
"bufio"
"bytes"
"fmt"
"io"
"os/exec"
"regexp"
"strings"
@ -16,8 +15,10 @@ var snapshotLineRegex = regexp.MustCompile("^" + PoolNameRegex + "@" +
func main() {
var listCommand = exec.Command("zfs", "list", "-Hrt", "snapshot", "dpool")
var snapList, err = listCommand.CombinedOutput()
var snapScanner = bufio.NewScanner(bytes.NewReader(snapList))
var listCommandOutput, err = listCommand.CombinedOutput()
var snapScanner = bufio.NewScanner(bytes.NewReader(listCommandOutput))
var snapshots = make(map[string]snapshotList)
_ = snapshots
if err != nil {
fmt.Println(listCommand)
fmt.Println("Error trying to list snapshots:", err.Error())
@ -30,7 +31,8 @@ func main() {
var temp = strings.SplitN(snapScanner.Text(), "\t", 2)
var snapshot = ParseSnapshot(temp[0])
if snapshot != nil {
var sender = exec.Command("zfs", "send", "-c",
/* var sender = exec.Command("zfs", "send", "-c",
snapshot.String())
var inData, err = sender.StdoutPipe()
if err != nil {
@ -50,7 +52,7 @@ func main() {
io.CopyBuffer(outData, inData, buf)
sender.Wait()
receiver.Wait()
break
break */
}
}
}

@ -220,6 +220,13 @@ func Receiver(backupPath string, snap Snapshot, receiver *exec.Cmd) (snapdata io
return
}
/*
Frequency returns the frequency of a Snapshot
*/
func (s Snapshot) frequency() frequency {
return s.Interval
}
/*
func testSnapshot(possible string, increment string) (bool, bool) {
var matches = zfsRegex.FindStringSubmatch(possible)

@ -0,0 +1,5 @@
package main
type snapshotList struct {
Snapshots []Snapshot
}

@ -1,5 +1,10 @@
package main
import (
"errors"
"fmt"
)
/*
Frequency is a custom unit to represent the time intervals that snapshots are taken in.
*/
@ -11,3 +16,83 @@ const weekly frequency = 2
const daily frequency = 3
const hourly frequency = 4
const frequent frequency = 5
/*
A snapshotTreeNode is a node in the tree representation of snapshots.
*/
type snapshotTreeNode struct {
Data Snapshot
Before []snapshotTreeNode
After []snapshotTreeNode
}
/*
addSnapshot adds a snapshot into a tree
*/
func (node *snapshotTreeNode) addSnapshot(s Snapshot) (err error) {
var tempNode snapshotTreeNode = snapshotTreeNode{Data: s}
if node == nil {
node = &tempNode
return nil
}
if node.frequency() > s.frequency() {
return fmt.Errorf("%s from a longer interval than %s", node.Data.String(), s.String())
}
if node.frequency() == s.frequency() {
return fmt.Errorf("%s is from the same interval as %s", node.Data.String(), s.String())
}
if node.frequency() < s.frequency() {
if node.frequency()+1 == s.frequency() {
if node.Data.TimeStamp.After(s.TimeStamp) {
if node.Before == nil {
node.Before = append(node.Before, tempNode)
return nil
}
var tSlice []snapshotTreeNode
for index := 0; index < len(node.Before); index++ {
if node.Before[index].Data.TimeStamp.Before(s.TimeStamp) {
tSlice = append(tSlice, tempNode)
copy(tSlice, node.Before[index:])
break
} else {
tSlice = append(tSlice, node.Before[index])
}
}
node.Before = tSlice
}
if node.Data.TimeStamp.Before(s.TimeStamp) {
if node.After == nil {
node.After = append(node.After, tempNode)
return nil
}
var tSlice []snapshotTreeNode
for index := 0; index < len(node.After); index++ {
if node.After[index].Data.TimeStamp.Before(s.TimeStamp) {
tSlice = append(tSlice, tempNode)
copy(tSlice, node.After[index:])
break
} else {
tSlice = append(tSlice, node.After[index])
}
}
node.After = tSlice
}
} else {
if node.Data.TimeStamp.After(s.TimeStamp) {
for index := 0; index < len(node.Before); index++ {
node.Before[index].Data.TimeStamp.Before(s.TimeStamp)
node.Before[index].addSnapshot(s)
break
}
}
}
}
return errors.New("Non implemented branch in func (node * snapshotTreeNode) addSnapshot(s Snapshot)")
}
/*
The frequency of this snapshot's interval in the tree?
*/
func (node snapshotTreeNode) frequency() frequency {
return node.Data.Interval
}

Loading…
Cancel
Save