update snapshot taking
This commit is contained in:
parent
0d3981ef4a
commit
d895b930f7
49
box.go
49
box.go
@ -17,12 +17,42 @@ type Box struct {
|
|||||||
zfs *ZFSConfig
|
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) {
|
func (b *Box) ZFSGetLastSnapshot(path string) (last Snapshot, err error) {
|
||||||
err = b.SnapshotInitialize()
|
err = b.SnapshotInitialize()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b.zfs.M.Lock()
|
||||||
|
defer b.zfs.M.Unlock()
|
||||||
|
|
||||||
if *debugFlag {
|
if *debugFlag {
|
||||||
log.Printf("Box.ZFSGetLastSnapshot : %s : Start %s (%d snapshots)", b.Name, path, len(b.zfs.SnapshotList))
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b.zfs.M.Lock()
|
||||||
|
defer b.zfs.M.Unlock()
|
||||||
|
|
||||||
if *debugFlag {
|
if *debugFlag {
|
||||||
log.Printf("SSHConfig.isLastSnapshot : %s : Start %s", b.Name, string(src))
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b.zfs.M.Lock()
|
||||||
|
defer b.zfs.M.Unlock()
|
||||||
|
|
||||||
if *debugFlag {
|
if *debugFlag {
|
||||||
log.Printf("SSHConfig.getFirstSnapshot : Start %s:%s", b.Name, path)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b.zfs.M.Lock()
|
||||||
|
defer b.zfs.M.Unlock()
|
||||||
|
|
||||||
if *debugFlag {
|
if *debugFlag {
|
||||||
log.Printf("Box.ZFSGetNextSnapshot : Start %s:%s", b.Name, string(src))
|
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)
|
buf, err = b.ssh.exec(cmd)
|
||||||
return
|
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
|
|
||||||
}
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// Code generated by version.sh (@generated) DO NOT EDIT.
|
// Code generated by version.sh (@generated) DO NOT EDIT.
|
||||||
package main
|
package main
|
||||||
var githash = "e192906"
|
var githash = "0d3981e"
|
||||||
var buildstamp = "2021-11-14_09:20:16"
|
var buildstamp = "2021-11-14_09:46:54"
|
||||||
var commits = "21"
|
var commits = "22"
|
||||||
var version = "e192906-b21 - 2021-11-14_09:20:16"
|
var version = "0d3981e-b22 - 2021-11-14_09:46:54"
|
||||||
|
Loading…
Reference in New Issue
Block a user