update snapshot taking

This commit is contained in:
shoopea 2021-11-14 17:47:45 +08:00
parent 0d3981ef4a
commit d895b930f7
2 changed files with 43 additions and 14 deletions

49
box.go
View File

@ -17,12 +17,42 @@ type Box struct {
zfs *ZFSConfig
}
func (b *Box) ZFSTakeSnapshot(schedule, path string) (err error) {
err = b.SnapshotInitialize()
if err != nil {
return
}
b.zfs.M.Lock()
defer b.zfs.M.Unlock()
if *debugFlag {
log.Printf("Box.ZFSTakeSnapshot : %s : taking snapshot on %s for %s", b.Name, path, schedule)
}
timestamp := cfg.Now.Format("2006-01-02_15.04.05")
name := fmt.Sprintf("%s-%s--%s", schedule, timestamp, cfg.Zfsnap[schedule])
_, err = b.ssh.exec("zfs snapshot " + path + "@" + name)
if err != nil {
return
}
b.zfs.SnapshotAdded = true
b.zfs.SnapshotList = append(b.zfs.SnapshotList, Snapshot(path+"@"+name))
return
}
func (b *Box) ZFSGetLastSnapshot(path string) (last Snapshot, err error) {
err = b.SnapshotInitialize()
if err != nil {
return
}
b.zfs.M.Lock()
defer b.zfs.M.Unlock()
if *debugFlag {
log.Printf("Box.ZFSGetLastSnapshot : %s : Start %s (%d snapshots)", b.Name, path, len(b.zfs.SnapshotList))
}
@ -44,6 +74,9 @@ func (b *Box) ZFSIsLastSnapshot(src Snapshot) (is bool, err error) {
return
}
b.zfs.M.Lock()
defer b.zfs.M.Unlock()
if *debugFlag {
log.Printf("SSHConfig.isLastSnapshot : %s : Start %s", b.Name, string(src))
}
@ -66,6 +99,9 @@ func (b *Box) ZFSGetFirstSnapshot(path string) (first Snapshot, err error) {
return
}
b.zfs.M.Lock()
defer b.zfs.M.Unlock()
if *debugFlag {
log.Printf("SSHConfig.getFirstSnapshot : Start %s:%s", b.Name, path)
}
@ -86,6 +122,9 @@ func (b *Box) ZFSGetNextSnapshot(src Snapshot) (next Snapshot, err error) {
return
}
b.zfs.M.Lock()
defer b.zfs.M.Unlock()
if *debugFlag {
log.Printf("Box.ZFSGetNextSnapshot : Start %s:%s", b.Name, string(src))
}
@ -288,13 +327,3 @@ func (b *Box) SSHExec(cmd string) (buf *bytes.Buffer, err error) {
buf, err = b.ssh.exec(cmd)
return
}
func (b *Box) ZFSTakeSnapshot(schedule, path string) (err error) {
if *debugFlag {
log.Printf("Box.ZFSTakeSnapshot : %s : taking snapshot on %s for %s", b.Name, path, schedule)
}
timestamp := cfg.Now.Format("2006-01-02_15.04.05")
name := fmt.Sprintf("%s-%s--%s", schedule, timestamp, cfg.Zfsnap[schedule])
_, err = b.ssh.exec("zfs snapshot " + path + "@" + name)
return
}

View File

@ -1,6 +1,6 @@
// Code generated by version.sh (@generated) DO NOT EDIT.
package main
var githash = "e192906"
var buildstamp = "2021-11-14_09:20:16"
var commits = "21"
var version = "e192906-b21 - 2021-11-14_09:20:16"
var githash = "0d3981e"
var buildstamp = "2021-11-14_09:46:54"
var commits = "22"
var version = "0d3981e-b22 - 2021-11-14_09:46:54"