change box addr for zfs send

This commit is contained in:
shoopea 2022-09-07 22:21:03 +08:00
parent 8a6fced9c8
commit f36e7da824
3 changed files with 12 additions and 7 deletions

6
app.go
View File

@ -604,7 +604,7 @@ func (a AppConfig) SendSnapshots() (err error) {
if *debugFlag { if *debugFlag {
log.Printf("AppConfig.SendSnapshots : %s : Initializing snapshot on %s from %s", a.Name, dest.Box(), string(sFirstSnapshot)) 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()) _, err = cfg.Box[dest.Box()].SSHExec("ssh " + cfg.Box[src.Box()].User + "@" + cfg.Box[src.Box()].Host() + " zfs send " + string(sFirstSnapshot) + " | zfs recv -F " + dest.Path() + "/" + src.Box() + "/" + src.Path())
if err != nil { if err != nil {
if *debugFlag { if *debugFlag {
log.Printf("AppConfig.SendSnapshots : %s : Initializing snapshot on %s from %s failed (%s)", a.Name, dest.Box(), string(sFirstSnapshot), err) log.Printf("AppConfig.SendSnapshots : %s : Initializing snapshot on %s from %s failed (%s)", a.Name, dest.Box(), string(sFirstSnapshot), err)
@ -627,7 +627,7 @@ func (a AppConfig) SendSnapshots() (err error) {
if err != nil && err.Error() != "no snapshot" { if err != nil && err.Error() != "no snapshot" {
return 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 + "@" + cfg.Box[src.Box()].Host() + " 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 : Sending snapshot on %s from %s failed (%s)", a.Name, dest.Box(), string(sNextSnapshot), err)
@ -658,7 +658,7 @@ func (a AppConfig) SendSnapshots() (err error) {
if err != nil && err.Error() != "no snapshot" { if err != nil && err.Error() != "no snapshot" {
return 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 + "@" + cfg.Box[src.Box()].Host() + " 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 : Sending snapshot on %s from %s failed (%s)", a.Name, dest.Box(), string(sNextSnapshot), err)

5
box.go
View File

@ -416,3 +416,8 @@ 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) Host() string {
s := strings.Split(string(b.Addr), `:`)
return s[0]
}

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 = "fcc9fa3" var githash = "8a6fced"
var buildstamp = "2022-06-19_04:33:26" var buildstamp = "2022-09-07_14:20:27"
var commits = "50" var commits = "51"
var version = "fcc9fa3-b50 - 2022-06-19_04:33:26" var version = "8a6fced-b51 - 2022-09-07_14:20:27"