allow offline box
This commit is contained in:
158
app.go
158
app.go
@@ -540,104 +540,106 @@ func (a AppConfig) SendSnapshots() (err error) {
|
||||
|
||||
for _, src := range a.Sources {
|
||||
for _, dest := range a.Destinations {
|
||||
if *debugFlag {
|
||||
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 cfg.Box[dest.Box()].online {
|
||||
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
|
||||
sFirstSnapshot, err = cfg.Box[src.Box()].ZFSGetFirstSnapshot(src.Path())
|
||||
if err != nil {
|
||||
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 {
|
||||
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 !cfg.Box[dest.Box()].ZFSIsZFS(dest.Path() + "/" + src.Box() + "/" + src.Path()) {
|
||||
if *debugFlag {
|
||||
log.Printf("AppConfig.SendSnapshots : %s : Creating on %s path %s", a.Name, dest.Box(), dest.Path()+"/"+src.Box()+"/"+src.Path())
|
||||
}
|
||||
if err = cfg.Box[dest.Box()].ZFSCreateZFS(dest.Path() + "/" + src.Box() + "/" + src.Path()); err != nil {
|
||||
if *debugFlag {
|
||||
log.Printf("AppConfig.SendSnapshots : %s : Creating on %s path %s failed (%s)", a.Name, dest.Box(), dest.Path()+"/"+src.Box()+"/"+src.Path(), err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if *debugFlag {
|
||||
log.Printf("AppConfig.SendSnapshots : %s : Initializing snapshot on %s from %s", a.Name, dest.Box(), string(sFirstSnapshot))
|
||||
}
|
||||
_, 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)
|
||||
for !isLastSnapshot {
|
||||
sCurrSnapshot = sNextSnapshot
|
||||
sNextSnapshot, err = cfg.Box[src.Box()].ZFSGetNextSnapshot(sNextSnapshot)
|
||||
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 " + dest.Path() + "/" + src.Box() + "/" + src.Path())
|
||||
var sFirstSnapshot Snapshot
|
||||
sFirstSnapshot, err = cfg.Box[src.Box()].ZFSGetFirstSnapshot(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)
|
||||
log.Printf("AppConfig.SendSnapshots : %s : No snapshot for %s", a.Name, string(src))
|
||||
}
|
||||
return
|
||||
}
|
||||
isLastSnapshot, _ = cfg.Box[src.Box()].ZFSIsLastSnapshot(sNextSnapshot)
|
||||
}
|
||||
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)
|
||||
for !isLastSnapshot {
|
||||
sCurrSnapshot = sNextSnapshot
|
||||
sNextSnapshot, err = cfg.Box[src.Box()].ZFSGetNextSnapshot(sNextSnapshot)
|
||||
if !cfg.Box[dest.Box()].ZFSIsZFS(dest.Path() + "/" + src.Box() + "/" + src.Path()) {
|
||||
if *debugFlag {
|
||||
log.Printf("AppConfig.SendSnapshots : %s : Creating on %s path %s", a.Name, dest.Box(), dest.Path()+"/"+src.Box()+"/"+src.Path())
|
||||
}
|
||||
if err = cfg.Box[dest.Box()].ZFSCreateZFS(dest.Path() + "/" + src.Box() + "/" + src.Path()); err != nil {
|
||||
if *debugFlag {
|
||||
log.Printf("AppConfig.SendSnapshots : %s : Creating on %s path %s failed (%s)", a.Name, dest.Box(), dest.Path()+"/"+src.Box()+"/"+src.Path(), err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
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" {
|
||||
return
|
||||
}
|
||||
_, err = cfg.Box[dest.Box()].SSHExec("ssh " + cfg.Box[src.Box()].User + "@" + src.Box() + " zfs send -I " + string(sCurrSnapshot) + " " + string(sNextSnapshot) + " | zfs recv " + dest.Path() + "/" + src.Box() + "/" + 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 : 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
|
||||
}
|
||||
|
||||
var (
|
||||
sCurrSnapshot, sNextSnapshot Snapshot
|
||||
isLastSnapshot bool
|
||||
)
|
||||
sNextSnapshot = sFirstSnapshot
|
||||
isLastSnapshot, _ = cfg.Box[src.Box()].ZFSIsLastSnapshot(sNextSnapshot)
|
||||
for !isLastSnapshot {
|
||||
sCurrSnapshot = sNextSnapshot
|
||||
sNextSnapshot, err = cfg.Box[src.Box()].ZFSGetNextSnapshot(sNextSnapshot)
|
||||
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 " + 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
|
||||
}
|
||||
isLastSnapshot, _ = cfg.Box[src.Box()].ZFSIsLastSnapshot(sNextSnapshot)
|
||||
}
|
||||
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)
|
||||
for !isLastSnapshot {
|
||||
sCurrSnapshot = sNextSnapshot
|
||||
sNextSnapshot, err = cfg.Box[src.Box()].ZFSGetNextSnapshot(sNextSnapshot)
|
||||
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 " + 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
|
||||
}
|
||||
isLastSnapshot, _ = cfg.Box[src.Box()].ZFSIsLastSnapshot(sNextSnapshot)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user