deprecate direct calls to sshconfig
This commit is contained in:
52
app.go
52
app.go
@@ -18,10 +18,10 @@ type AppConfig struct {
|
||||
|
||||
func (a AppConfig) getTime() time.Time {
|
||||
for _, v := range a.Sources {
|
||||
return cfg.Box[v.Box()].ssh.now
|
||||
return cfg.Box[v.Box()].GetTime()
|
||||
}
|
||||
for _, v := range a.Destinations {
|
||||
return cfg.Box[v.Box()].ssh.now
|
||||
return cfg.Box[v.Box()].GetTime()
|
||||
}
|
||||
return time.Now()
|
||||
}
|
||||
@@ -37,10 +37,10 @@ func (a AppConfig) getSchedule() (string, error) {
|
||||
refreshSnapshot[v.Box()] = true
|
||||
}
|
||||
for k, _ := range refreshSnapshot {
|
||||
err := cfg.Box[k].ssh.getSnapshotList()
|
||||
err := cfg.Box[k].ZFSUpdateSnapshotList()
|
||||
if err != nil {
|
||||
if *debugFlag {
|
||||
log.Printf("AppConfig.getSchedule : %s : getSnapshotList(%s) : %s", a.Name, k, err)
|
||||
log.Printf("AppConfig.getSchedule : %s : ZFSUpdateSnapshotList(%s) : %s", a.Name, k, err)
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
@@ -95,7 +95,7 @@ func (a AppConfig) needYearlySnapshot() bool {
|
||||
re := regexp.MustCompile(`^yearly-(?P<Date>[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}.[0-9]{2}.[0-9]{2})--([0-9]+[ymwdhMs]{1}|forever)$`)
|
||||
for _, src := range a.Sources {
|
||||
timeSource[string(src)] = make(map[time.Time]struct{})
|
||||
for _, snap := range cfg.Box[src.Box()].ssh.snapshot {
|
||||
for _, snap := range cfg.Box[src.Box()].ZFSGetSnapshotList() {
|
||||
if src.Path() == snap.Path() {
|
||||
if re.MatchString(snap.Name()) {
|
||||
dateString := re.ReplaceAllString(snap.Name(), "${Date}")
|
||||
@@ -157,7 +157,7 @@ func (a AppConfig) needMonthlySnapshot() bool {
|
||||
re := regexp.MustCompile(`^(yearly|monthly)-(?P<Date>[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}.[0-9]{2}.[0-9]{2})--([0-9]+[ymwdhMs]{1}|forever)$`)
|
||||
for _, src := range a.Sources {
|
||||
timeSource[string(src)] = make(map[time.Time]struct{})
|
||||
for _, snap := range cfg.Box[src.Box()].ssh.snapshot {
|
||||
for _, snap := range cfg.Box[src.Box()].ZFSGetSnapshotList() {
|
||||
if src.Path() == snap.Path() {
|
||||
if re.MatchString(snap.Name()) {
|
||||
dateString := re.ReplaceAllString(snap.Name(), "${Date}")
|
||||
@@ -219,7 +219,7 @@ func (a AppConfig) needWeeklySnapshot() bool {
|
||||
re := regexp.MustCompile(`^(yearly|monthly|weekly)-(?P<Date>[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}.[0-9]{2}.[0-9]{2})--([0-9]+[ymwdhMs]{1}|forever)$`)
|
||||
for _, src := range a.Sources {
|
||||
timeSource[string(src)] = make(map[time.Time]struct{})
|
||||
for _, snap := range cfg.Box[src.Box()].ssh.snapshot {
|
||||
for _, snap := range cfg.Box[src.Box()].ZFSGetSnapshotList() {
|
||||
if src.Path() == snap.Path() {
|
||||
if re.MatchString(snap.Name()) {
|
||||
dateString := re.ReplaceAllString(snap.Name(), "${Date}")
|
||||
@@ -283,7 +283,7 @@ func (a AppConfig) needDailySnapshot() bool {
|
||||
re := regexp.MustCompile(`^(yearly|monthly|weekly|daily)-(?P<Date>[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}.[0-9]{2}.[0-9]{2})--([0-9]+[ymwdhMs]{1}|forever)$`)
|
||||
for _, src := range a.Sources {
|
||||
timeSource[string(src)] = make(map[time.Time]struct{})
|
||||
for _, snap := range cfg.Box[src.Box()].ssh.snapshot {
|
||||
for _, snap := range cfg.Box[src.Box()].ZFSGetSnapshotList() {
|
||||
if src.Path() == snap.Path() {
|
||||
if re.MatchString(snap.Name()) {
|
||||
dateString := re.ReplaceAllString(snap.Name(), "${Date}")
|
||||
@@ -345,7 +345,7 @@ func (a AppConfig) needHourlySnapshot() bool {
|
||||
re := regexp.MustCompile(`^(yearly|monthly|weekly|daily|hourly)-(?P<Date>[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}.[0-9]{2}.[0-9]{2})--([0-9]+[ymwdhMs]{1}|forever)$`)
|
||||
for _, src := range a.Sources {
|
||||
timeSource[string(src)] = make(map[time.Time]struct{})
|
||||
for _, snap := range cfg.Box[src.Box()].ssh.snapshot {
|
||||
for _, snap := range cfg.Box[src.Box()].ZFSGetSnapshotList() {
|
||||
if src.Path() == snap.Path() {
|
||||
if re.MatchString(snap.Name()) {
|
||||
dateString := re.ReplaceAllString(snap.Name(), "${Date}")
|
||||
@@ -391,12 +391,12 @@ func (a AppConfig) CheckZFS() error {
|
||||
}
|
||||
|
||||
for _, src := range a.Sources {
|
||||
if !cfg.Box[src.Box()].ssh.isZFS(src.Path()) {
|
||||
if !cfg.Box[src.Box()].ZFSIsZFS(src.Path()) {
|
||||
return fmt.Errorf("No path %s on source", string(src))
|
||||
}
|
||||
for _, dest := range a.Destinations {
|
||||
if !cfg.Box[dest.Box()].ssh.isZFS(dest.Path() + "/" + src.Box() + "/" + src.Path()) {
|
||||
err := cfg.Box[dest.Box()].ssh.createZFS(dest.Path() + "/" + src.Box() + "/" + src.Path())
|
||||
if !cfg.Box[dest.Box()].ZFSIsZFS(dest.Path() + "/" + src.Box() + "/" + src.Path()) {
|
||||
err := cfg.Box[dest.Box()].ZFSCreateZFS(dest.Path() + "/" + src.Box() + "/" + src.Path())
|
||||
if err != nil {
|
||||
if *debugFlag {
|
||||
log.Printf("AppConfig.CheckZFS : %s : Error creating %s on %s", a.Name, dest.Path()+"/"+src.Box()+"/"+src.Path(), dest.Box())
|
||||
@@ -417,7 +417,7 @@ func (a AppConfig) ExecBefore(schedule string) error {
|
||||
for k, v := range a.Before {
|
||||
re := regexp.MustCompile(k)
|
||||
if re.MatchString(schedule) {
|
||||
err := cfg.Box[v.Box()].ssh.exec(v.Path())
|
||||
err := cfg.Box[v.Box()].SSHExec(v.Path())
|
||||
if err != nil {
|
||||
if *debugFlag {
|
||||
log.Printf("AppConfig.ExecBefore : %s : Error executing %s", a.Name, string(v))
|
||||
@@ -437,7 +437,7 @@ func (a AppConfig) ExecAfter(schedule string) error {
|
||||
for k, v := range a.After {
|
||||
re := regexp.MustCompile(k)
|
||||
if re.MatchString(schedule) {
|
||||
err := cfg.Box[v.Box()].ssh.exec(v.Path())
|
||||
err := cfg.Box[v.Box()].SSHExec(v.Path())
|
||||
if err != nil {
|
||||
if *debugFlag {
|
||||
log.Printf("AppConfig.ExecAfter : %s : Error executing %s on %s", a.Name, v.Path(), v.Box())
|
||||
@@ -463,7 +463,7 @@ func (a AppConfig) TakeSnapshot(schedule string) error {
|
||||
if *debugFlag {
|
||||
log.Printf("AppConfig.TakeSnapshot : %s : taking snapshot on %s for %s", a.Name, k, v)
|
||||
}
|
||||
err := cfg.Box[k].ssh.exec("zfsnap snapshot -p " + schedule + "- -a " + cfg.Zfsnap[schedule] + v)
|
||||
err := cfg.Box[k].SSHExec("zfsnap snapshot -p " + schedule + "- -a " + cfg.Zfsnap[schedule] + v)
|
||||
if err != nil {
|
||||
if *debugFlag {
|
||||
log.Printf("AppConfig.TakeSnapshot : %s : Error executing zfsnap on %s", a.Name, k)
|
||||
@@ -491,7 +491,7 @@ func (a AppConfig) RefreshSnapshot() error {
|
||||
if *debugFlag {
|
||||
log.Printf("AppConfig.RefreshSnapshot : %s : refreshing snapshots for source %s", a.Name, k)
|
||||
}
|
||||
err := cfg.Box[k].ssh.getSnapshotList()
|
||||
err := cfg.Box[k].ZFSUpdateSnapshotList()
|
||||
if err != nil {
|
||||
if *debugFlag {
|
||||
log.Printf("AppConfig.RefreshSnapshot : %s : Error getting snapshots on %s", a.Name, k)
|
||||
@@ -512,12 +512,12 @@ func (a AppConfig) SendSnapshots() error {
|
||||
if *debugFlag {
|
||||
log.Printf("AppConfig.SendSnapshots : %s : Sending snapshots from %s to %s", a.Name, string(src), string(dest))
|
||||
}
|
||||
dLastSnapshot, err := cfg.Box[dest.Box()].ssh.getLastSnapshot(dest.Path() + "/" + src.Box() + "/" + src.Path())
|
||||
dLastSnapshot, err := cfg.Box[dest.Box()].ZFSGetLastSnapshot(dest.Path() + "/" + src.Box() + "/" + src.Path())
|
||||
if err != nil {
|
||||
if *debugFlag {
|
||||
log.Printf("AppConfig.SendSnapshots : %s : No snapshot for %s on %s", a.Name, string(src), dest.Box())
|
||||
}
|
||||
sFirstSnapshot, err := cfg.Box[src.Box()].ssh.getFirstSnapshot(src.Path())
|
||||
sFirstSnapshot, err := cfg.Box[src.Box()].ZFSGetFirstSnapshot(src.Path())
|
||||
if err != nil {
|
||||
if *debugFlag {
|
||||
log.Printf("AppConfig.SendSnapshots : %s : No snapshot for %s", a.Name, string(src))
|
||||
@@ -527,7 +527,7 @@ func (a AppConfig) SendSnapshots() error {
|
||||
if *debugFlag {
|
||||
log.Printf("AppConfig.SendSnapshots : %s : Initializing snapshot on %s from %s", a.Name, dest.Box(), string(sFirstSnapshot))
|
||||
}
|
||||
err = cfg.Box[dest.Box()].ssh.exec("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 + "@" + 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)
|
||||
@@ -536,13 +536,13 @@ func (a AppConfig) SendSnapshots() error {
|
||||
}
|
||||
var sCurrSnapshot Snapshot
|
||||
sNextSnapshot := sFirstSnapshot
|
||||
for !cfg.Box[src.Box()].ssh.isLastSnapshot(sNextSnapshot) {
|
||||
for !cfg.Box[src.Box()].ZFSIsLastSnapshot(sNextSnapshot) {
|
||||
sCurrSnapshot = sNextSnapshot
|
||||
sNextSnapshot, err = cfg.Box[src.Box()].ssh.getNextSnapshot(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())
|
||||
}
|
||||
err = cfg.Box[dest.Box()].ssh.exec("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 -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)
|
||||
@@ -560,13 +560,13 @@ func (a AppConfig) SendSnapshots() error {
|
||||
}
|
||||
var sCurrSnapshot Snapshot
|
||||
sNextSnapshot := Snapshot(string(dLastSnapshot)[len(dest.Path())+len(src.Box())+2:])
|
||||
for !cfg.Box[src.Box()].ssh.isLastSnapshot(sNextSnapshot) {
|
||||
for !cfg.Box[src.Box()].ZFSIsLastSnapshot(sNextSnapshot) {
|
||||
sCurrSnapshot = sNextSnapshot
|
||||
sNextSnapshot, err = cfg.Box[src.Box()].ssh.getNextSnapshot(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())
|
||||
}
|
||||
err = cfg.Box[dest.Box()].ssh.exec("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 -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)
|
||||
@@ -598,7 +598,7 @@ func (a AppConfig) CleanupSnapshot() error {
|
||||
if *debugFlag {
|
||||
log.Printf("AppConfig.CleanupSnapshot : %s : cleaning snapshots on %s for%s", a.Name, k, v)
|
||||
}
|
||||
err := cfg.Box[k].ssh.exec("zfsnap destroy -p hourly- -p daily- -p weekly- -p monthly- -p yearly-" + v)
|
||||
err := cfg.Box[k].SSHExec("zfsnap destroy -p hourly- -p daily- -p weekly- -p monthly- -p yearly-" + v)
|
||||
if err != nil {
|
||||
if *debugFlag {
|
||||
log.Printf("AppConfig.CleanupSnapshot : %s : Error executing zfsnap on %s", a.Name, k)
|
||||
|
||||
Reference in New Issue
Block a user