Compare commits

...

2 Commits

Author SHA1 Message Date
shoopea
c93aa200b4 more debug 2021-11-14 18:09:58 +08:00
shoopea
efeb3a0e66 more debug 2021-11-14 18:09:51 +08:00
2 changed files with 44 additions and 20 deletions

56
box.go
View File

@ -18,6 +18,10 @@ type Box struct {
}
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)
}
err = b.SnapshotInitialize()
if err != nil {
return
@ -26,10 +30,6 @@ func (b *Box) ZFSTakeSnapshot(schedule, path string) (err error) {
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)
@ -45,6 +45,10 @@ func (b *Box) ZFSTakeSnapshot(schedule, path string) (err error) {
}
func (b *Box) ZFSGetLastSnapshot(path string) (last Snapshot, err error) {
if *debugFlag {
log.Printf("Box.ZFSGetLastSnapshot : %s : Start %s (%d snapshots)", b.Name, path, len(b.zfs.SnapshotList))
}
err = b.SnapshotInitialize()
if err != nil {
return
@ -53,10 +57,6 @@ func (b *Box) ZFSGetLastSnapshot(path string) (last Snapshot, err error) {
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))
}
for _, v := range b.zfs.SnapshotList {
if v.Path() == path {
last = v
@ -69,6 +69,10 @@ func (b *Box) ZFSGetLastSnapshot(path string) (last Snapshot, err error) {
}
func (b *Box) ZFSIsLastSnapshot(src Snapshot) (is bool, err error) {
if *debugFlag {
log.Printf("Box.ZFSIsLastSnapshot : %s : Start %s", b.Name, string(src))
}
err = b.SnapshotInitialize()
if err != nil {
return
@ -94,6 +98,10 @@ func (b *Box) ZFSIsLastSnapshot(src Snapshot) (is bool, err error) {
}
func (b *Box) ZFSGetFirstSnapshot(path string) (first Snapshot, err error) {
if *debugFlag {
log.Printf("SSHConfig.getFirstSnapshot : %s : Start %s", b.Name, path)
}
err = b.SnapshotInitialize()
if err != nil {
return
@ -102,10 +110,6 @@ func (b *Box) ZFSGetFirstSnapshot(path string) (first Snapshot, err error) {
b.zfs.M.Lock()
defer b.zfs.M.Unlock()
if *debugFlag {
log.Printf("SSHConfig.getFirstSnapshot : Start %s:%s", b.Name, path)
}
for _, v := range b.zfs.SnapshotList {
if v.Path() == path {
first = v
@ -117,6 +121,10 @@ func (b *Box) ZFSGetFirstSnapshot(path string) (first Snapshot, err error) {
}
func (b *Box) ZFSGetNextSnapshot(src Snapshot) (next Snapshot, err error) {
if *debugFlag {
log.Printf("Box.ZFSGetNextSnapshot : %s : Start %s", b.Name, string(src))
}
err = b.SnapshotInitialize()
if err != nil {
return
@ -125,10 +133,6 @@ func (b *Box) ZFSGetNextSnapshot(src Snapshot) (next Snapshot, err error) {
b.zfs.M.Lock()
defer b.zfs.M.Unlock()
if *debugFlag {
log.Printf("Box.ZFSGetNextSnapshot : Start %s:%s", b.Name, string(src))
}
for id, v := range b.zfs.SnapshotList {
if v == src {
if len(b.zfs.SnapshotList) > id+1 {
@ -150,6 +154,10 @@ func (b *Box) ZFSGetNextSnapshot(src Snapshot) (next Snapshot, err error) {
}
func (b *Box) ZFSUpdateSnapshotList() (err error) {
if *debugFlag {
log.Printf("Box.ZFSUpdateSnapshotList : %s : Start", b.Name)
}
b.zfs.M.Lock()
if b.zfs.SnapshotDeleted || b.zfs.SnapshotAdded {
b.zfs.SnapshotInitialized = false
@ -161,6 +169,10 @@ func (b *Box) ZFSUpdateSnapshotList() (err error) {
}
func (b *Box) ZFSGetSnapshotList() (snaps []Snapshot, err error) {
if *debugFlag {
log.Printf("Box.ZFSGetSnapshotList : %s : Start", b.Name)
}
err = b.SnapshotInitialize()
if err != nil {
return
@ -218,6 +230,10 @@ func (b *Box) SnapshotInitialize() (err error) {
}
func (b *Box) ZFSUpdateList() (err error) {
if *debugFlag {
log.Printf("Box.ZFSUpdateList : %s : Start", b.Name)
}
b.zfs.M.Lock()
if b.zfs.ZFSDeleted || b.zfs.ZFSAdded {
b.zfs.ZFSInitialized = false
@ -229,6 +245,10 @@ func (b *Box) ZFSUpdateList() (err error) {
}
func (b *Box) ZFSIsZFS(path string) bool {
if *debugFlag {
log.Printf("Box.ZFSIsZFS : %s : Start %s", b.Name, path)
}
err := b.ZFSInitialize()
if err != nil {
return false
@ -245,6 +265,10 @@ func (b *Box) ZFSIsZFS(path string) bool {
}
func (b *Box) ZFSCreateZFS(path string) (err error) {
if *debugFlag {
log.Printf("Box.ZFSCreateZFS : %s : Start %s", b.Name, path)
}
err = b.ZFSInitialize()
if err != nil {
return

View File

@ -1,6 +1,6 @@
// Code generated by version.sh (@generated) DO NOT EDIT.
package main
var githash = "0d3981e"
var buildstamp = "2021-11-14_09:46:54"
var commits = "22"
var version = "0d3981e-b22 - 2021-11-14_09:46:54"
var githash = "d895b93"
var buildstamp = "2021-11-14_10:09:45"
var commits = "23"
var version = "d895b93-b23 - 2021-11-14_10:09:45"