From 7c309b850b13ac85eb6fd1cd06d0fc5201c6d377 Mon Sep 17 00:00:00 2001 From: shoopea Date: Fri, 17 Jun 2022 22:11:20 +0800 Subject: [PATCH] only send with online boxes --- app.go | 136 +++++++++++++++++++++++++++-------------------------- version.go | 8 ++-- 2 files changed, 73 insertions(+), 71 deletions(-) diff --git a/app.go b/app.go index 216b166..d9a29b0 100644 --- a/app.go +++ b/app.go @@ -578,92 +578,94 @@ func (a AppConfig) SendSnapshots() (err error) { } for _, src := range a.Sources { - for _, dest := range a.Destinations { - if cfg.Box[dest.Box()].online { - 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[src.Box()].online { + for _, dest := range a.Destinations { + 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 *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) - 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()) + 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 } - } - 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()) + 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 -F " + 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) + 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 + } + } } } } diff --git a/version.go b/version.go index d7fe4c0..99d5368 100644 --- a/version.go +++ b/version.go @@ -1,6 +1,6 @@ // Code generated by version.sh (@generated) DO NOT EDIT. package main -var githash = "23d7d90" -var buildstamp = "2022-06-17_14:07:22" -var commits = "40" -var version = "23d7d90-b40 - 2022-06-17_14:07:22" +var githash = "9594fd7" +var buildstamp = "2022-06-17_14:11:08" +var commits = "41" +var version = "9594fd7-b41 - 2022-06-17_14:11:08"