replace zfsnap for snapshot taking

This commit is contained in:
shoopea
2021-11-14 12:21:22 +08:00
parent 119d069083
commit d9c3eac4b6
6 changed files with 39 additions and 96 deletions

23
box.go
View File

@@ -1,11 +1,15 @@
package main
import "time"
import (
"fmt"
"log"
)
type Box struct {
Addr string `json:"addr"`
User string `json:"user"`
Key string `json:"key"`
Name string `json:"-"`
ssh *SSHConfig
}
@@ -45,14 +49,15 @@ func (b *Box) ZFSCreateZFS(path string) (err error) {
return b.ssh.createZFS(path)
}
func (b *Box) GetTime() time.Time {
return b.ssh.now
}
func (b *Box) UpdateTime() (err error) {
return b.ssh.getTime()
}
func (b *Box) SSHExec(cmd string) (err error) {
return b.ssh.exec(cmd)
}
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])
return b.ssh.exec("zfs snapshot " + path + "@" + name)
}