only send with online boxes

This commit is contained in:
shoopea 2022-06-17 22:11:20 +08:00
parent 9594fd7970
commit 7c309b850b
2 changed files with 73 additions and 71 deletions

136
app.go
View File

@ -578,92 +578,94 @@ func (a AppConfig) SendSnapshots() (err error) {
} }
for _, src := range a.Sources { for _, src := range a.Sources {
for _, dest := range a.Destinations { if cfg.Box[src.Box()].online {
if cfg.Box[dest.Box()].online { for _, dest := range a.Destinations {
if *debugFlag { if cfg.Box[dest.Box()].online {
log.Printf("AppConfig.SendSnapshots : %s : Sending snapshots from %s to %s", a.Name, string(src), string(dest))
}
var dLastSnapshot Snapshot
dLastSnapshot, err = cfg.Box[dest.Box()].ZFSGetLastSnapshot(dest.Path() + "/" + src.Box() + "/" + src.Path())
if err != nil && err.Error() == "no snapshot" {
if *debugFlag { if *debugFlag {
log.Printf("AppConfig.SendSnapshots : %s : No snapshot for %s on %s", a.Name, string(src), dest.Box()) log.Printf("AppConfig.SendSnapshots : %s : Sending snapshots from %s to %s", a.Name, string(src), string(dest))
} }
var sFirstSnapshot Snapshot var dLastSnapshot Snapshot
sFirstSnapshot, err = cfg.Box[src.Box()].ZFSGetFirstSnapshot(src.Path()) dLastSnapshot, err = cfg.Box[dest.Box()].ZFSGetLastSnapshot(dest.Path() + "/" + src.Box() + "/" + src.Path())
if err != nil { if err != nil && err.Error() == "no snapshot" {
if *debugFlag { if *debugFlag {
log.Printf("AppConfig.SendSnapshots : %s : No snapshot for %s", a.Name, string(src)) log.Printf("AppConfig.SendSnapshots : %s : No snapshot for %s on %s", a.Name, string(src), dest.Box())
} }
return
}
if *debugFlag { var sFirstSnapshot Snapshot
log.Printf("AppConfig.SendSnapshots : %s : Initializing snapshot on %s from %s", a.Name, dest.Box(), string(sFirstSnapshot)) sFirstSnapshot, err = cfg.Box[src.Box()].ZFSGetFirstSnapshot(src.Path())
}
_, err = cfg.Box[dest.Box()].SSHExec("ssh " + cfg.Box[src.Box()].User + "@" + src.Box() + " zfs send " + string(sFirstSnapshot) + " | zfs recv -F " + dest.Path() + "/" + src.Box() + "/" + src.Path())
if err != nil {
if *debugFlag {
log.Printf("AppConfig.SendSnapshots : %s : Initializing snapshot on %s from %s failed (%s)", a.Name, dest.Box(), string(sFirstSnapshot), err)
}
return
}
var (
sCurrSnapshot, sNextSnapshot Snapshot
isLastSnapshot bool
)
sNextSnapshot = sFirstSnapshot
isLastSnapshot, _ = cfg.Box[src.Box()].ZFSIsLastSnapshot(sNextSnapshot)
if !isLastSnapshot {
sCurrSnapshot = sNextSnapshot
sNextSnapshot, err = cfg.Box[src.Box()].ZFSGetLastSnapshot(sNextSnapshot.Path())
if *debugFlag {
log.Printf("AppConfig.SendSnapshots : %s : Sending incrementally %s to %s", a.Name, string(sNextSnapshot), dest.Box())
}
if err != nil && err.Error() != "no snapshot" {
return
}
_, err = cfg.Box[dest.Box()].SSHExec("ssh " + cfg.Box[src.Box()].User + "@" + src.Box() + " zfs send -I " + string(sCurrSnapshot) + " " + string(sNextSnapshot) + " | zfs recv -F " + dest.Path() + "/" + src.Box() + "/" + src.Path())
if err != nil { if err != nil {
if *debugFlag { if *debugFlag {
log.Printf("AppConfig.SendSnapshots : %s : Sending snapshot on %s from %s failed (%s)", a.Name, dest.Box(), string(sNextSnapshot), err) log.Printf("AppConfig.SendSnapshots : %s : No snapshot for %s", a.Name, string(src))
} }
return return
} }
}
if *debugFlag {
log.Printf("AppConfig.SendSnapshots : %s : All snapshots sent for %s", a.Name, string(src))
}
} else {
if *debugFlag {
log.Printf("AppConfig.SendSnapshots : %s : Last snapshot on %s is %s", a.Name, dest.Box(), string(dLastSnapshot))
}
var (
sCurrSnapshot, sNextSnapshot Snapshot
isLastSnapshot bool
)
sNextSnapshot = Snapshot(string(dLastSnapshot)[len(dest.Path())+len(src.Box())+2:])
isLastSnapshot, _ = cfg.Box[src.Box()].ZFSIsLastSnapshot(sNextSnapshot)
if !isLastSnapshot {
sCurrSnapshot = sNextSnapshot
sNextSnapshot, err = cfg.Box[src.Box()].ZFSGetLastSnapshot(sNextSnapshot.Path())
if *debugFlag { if *debugFlag {
log.Printf("AppConfig.SendSnapshots : %s : Sending incrementally %s to %s", a.Name, string(sNextSnapshot), dest.Box()) log.Printf("AppConfig.SendSnapshots : %s : Initializing snapshot on %s from %s", a.Name, dest.Box(), string(sFirstSnapshot))
} }
if err != nil && err.Error() != "no snapshot" { _, err = cfg.Box[dest.Box()].SSHExec("ssh " + cfg.Box[src.Box()].User + "@" + src.Box() + " zfs send " + string(sFirstSnapshot) + " | zfs recv -F " + dest.Path() + "/" + src.Box() + "/" + src.Path())
return
}
_, err = cfg.Box[dest.Box()].SSHExec("ssh " + cfg.Box[src.Box()].User + "@" + src.Box() + " zfs send -I " + string(sCurrSnapshot) + " " + string(sNextSnapshot) + " | zfs recv -F " + dest.Path() + "/" + src.Box() + "/" + src.Path())
if err != nil { if err != nil {
if *debugFlag { if *debugFlag {
log.Printf("AppConfig.SendSnapshots : %s : Sending snapshot on %s from %s failed (%s)", a.Name, dest.Box(), string(sNextSnapshot), err) log.Printf("AppConfig.SendSnapshots : %s : Initializing snapshot on %s from %s failed (%s)", a.Name, dest.Box(), string(sFirstSnapshot), err)
} }
return return
} }
var (
sCurrSnapshot, sNextSnapshot Snapshot
isLastSnapshot bool
)
sNextSnapshot = sFirstSnapshot
isLastSnapshot, _ = cfg.Box[src.Box()].ZFSIsLastSnapshot(sNextSnapshot)
if !isLastSnapshot {
sCurrSnapshot = sNextSnapshot
sNextSnapshot, err = cfg.Box[src.Box()].ZFSGetLastSnapshot(sNextSnapshot.Path())
if *debugFlag {
log.Printf("AppConfig.SendSnapshots : %s : Sending incrementally %s to %s", a.Name, string(sNextSnapshot), dest.Box())
}
if err != nil && err.Error() != "no snapshot" {
return
}
_, err = cfg.Box[dest.Box()].SSHExec("ssh " + cfg.Box[src.Box()].User + "@" + src.Box() + " zfs send -I " + string(sCurrSnapshot) + " " + string(sNextSnapshot) + " | zfs recv -F " + dest.Path() + "/" + src.Box() + "/" + src.Path())
if err != nil {
if *debugFlag {
log.Printf("AppConfig.SendSnapshots : %s : Sending snapshot on %s from %s failed (%s)", a.Name, dest.Box(), string(sNextSnapshot), err)
}
return
}
}
if *debugFlag {
log.Printf("AppConfig.SendSnapshots : %s : All snapshots sent for %s", a.Name, string(src))
}
} else {
if *debugFlag {
log.Printf("AppConfig.SendSnapshots : %s : Last snapshot on %s is %s", a.Name, dest.Box(), string(dLastSnapshot))
}
var (
sCurrSnapshot, sNextSnapshot Snapshot
isLastSnapshot bool
)
sNextSnapshot = Snapshot(string(dLastSnapshot)[len(dest.Path())+len(src.Box())+2:])
isLastSnapshot, _ = cfg.Box[src.Box()].ZFSIsLastSnapshot(sNextSnapshot)
if !isLastSnapshot {
sCurrSnapshot = sNextSnapshot
sNextSnapshot, err = cfg.Box[src.Box()].ZFSGetLastSnapshot(sNextSnapshot.Path())
if *debugFlag {
log.Printf("AppConfig.SendSnapshots : %s : Sending incrementally %s to %s", a.Name, string(sNextSnapshot), dest.Box())
}
if err != nil && err.Error() != "no snapshot" {
return
}
_, err = cfg.Box[dest.Box()].SSHExec("ssh " + cfg.Box[src.Box()].User + "@" + src.Box() + " zfs send -I " + string(sCurrSnapshot) + " " + string(sNextSnapshot) + " | zfs recv -F " + dest.Path() + "/" + src.Box() + "/" + src.Path())
if err != nil {
if *debugFlag {
log.Printf("AppConfig.SendSnapshots : %s : Sending snapshot on %s from %s failed (%s)", a.Name, dest.Box(), string(sNextSnapshot), err)
}
return
}
}
} }
} }
} }

View File

@ -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 = "23d7d90" var githash = "9594fd7"
var buildstamp = "2022-06-17_14:07:22" var buildstamp = "2022-06-17_14:11:08"
var commits = "40" var commits = "41"
var version = "23d7d90-b40 - 2022-06-17_14:07:22" var version = "9594fd7-b41 - 2022-06-17_14:11:08"