2021-11-14 03:53:13 +01:00
|
|
|
package main
|
|
|
|
|
2021-11-14 05:21:22 +01:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
)
|
2021-11-14 03:53:13 +01:00
|
|
|
|
|
|
|
type Box struct {
|
|
|
|
Addr string `json:"addr"`
|
|
|
|
User string `json:"user"`
|
|
|
|
Key string `json:"key"`
|
2021-11-14 05:21:22 +01:00
|
|
|
Name string `json:"-"`
|
2021-11-14 03:53:13 +01:00
|
|
|
ssh *SSHConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Box) ZFSGetLastSnapshot(path string) (s Snapshot, err error) {
|
|
|
|
return b.ssh.getLastSnapshot(path)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Box) ZFSIsLastSnapshot(s Snapshot) bool {
|
|
|
|
return b.ssh.isLastSnapshot(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Box) ZFSGetFirstSnapshot(path string) (s Snapshot, err error) {
|
|
|
|
return b.ssh.getFirstSnapshot(path)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Box) ZFSGetNextSnapshot(src Snapshot) (next Snapshot, err error) {
|
|
|
|
return b.ssh.getNextSnapshot(src)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Box) ZFSUpdateSnapshotList() (err error) {
|
|
|
|
return b.ssh.getSnapshotList()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Box) ZFSGetSnapshotList() []Snapshot {
|
|
|
|
return b.ssh.snapshot
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Box) ZFSUpdateList() (err error) {
|
|
|
|
return b.ssh.getZFSList()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Box) ZFSIsZFS(path string) bool {
|
|
|
|
return b.ssh.isZFS(path)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Box) ZFSCreateZFS(path string) (err error) {
|
|
|
|
return b.ssh.createZFS(path)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *Box) SSHExec(cmd string) (err error) {
|
|
|
|
return b.ssh.exec(cmd)
|
|
|
|
}
|
2021-11-14 05:21:22 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|