replace zfsnap for snapshot taking
This commit is contained in:
36
app.go
36
app.go
@@ -16,16 +16,6 @@ type AppConfig struct {
|
||||
After map[string]Location `json:"after"`
|
||||
}
|
||||
|
||||
func (a AppConfig) getTime() time.Time {
|
||||
for _, v := range a.Sources {
|
||||
return cfg.Box[v.Box()].GetTime()
|
||||
}
|
||||
for _, v := range a.Destinations {
|
||||
return cfg.Box[v.Box()].GetTime()
|
||||
}
|
||||
return time.Now()
|
||||
}
|
||||
|
||||
func (a AppConfig) getSchedule() (string, error) {
|
||||
var schedule string
|
||||
if *debugFlag {
|
||||
@@ -123,9 +113,8 @@ func (a AppConfig) needYearlySnapshot() bool {
|
||||
}
|
||||
|
||||
// finding an eligible timestamp
|
||||
now := a.getTime()
|
||||
for t, _ := range timeTotal {
|
||||
if t.Year() == now.Year() {
|
||||
if t.Year() == cfg.Now.Year() {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -185,9 +174,8 @@ func (a AppConfig) needMonthlySnapshot() bool {
|
||||
}
|
||||
|
||||
// finding an eligible timestamp
|
||||
now := a.getTime()
|
||||
for t, _ := range timeTotal {
|
||||
if t.Year() == now.Year() && t.Month() == now.Month() {
|
||||
if t.Year() == cfg.Now.Year() && t.Month() == cfg.Now.Month() {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -247,8 +235,7 @@ func (a AppConfig) needWeeklySnapshot() bool {
|
||||
}
|
||||
|
||||
// finding an eligible timestamp
|
||||
now := a.getTime()
|
||||
nowYear, nowWeek := now.ISOWeek()
|
||||
nowYear, nowWeek := cfg.Now.ISOWeek()
|
||||
for t, _ := range timeTotal {
|
||||
snapYear, snapWeek := t.ISOWeek()
|
||||
if nowYear == snapYear && nowWeek == snapWeek {
|
||||
@@ -311,9 +298,8 @@ func (a AppConfig) needDailySnapshot() bool {
|
||||
}
|
||||
|
||||
// finding an eligible timestamp
|
||||
now := a.getTime()
|
||||
for t, _ := range timeTotal {
|
||||
if t.Year() == now.Year() && t.Month() == now.Month() && t.Day() == now.Day() {
|
||||
if t.Year() == cfg.Now.Year() && t.Month() == cfg.Now.Month() && t.Day() == cfg.Now.Day() {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -373,9 +359,8 @@ func (a AppConfig) needHourlySnapshot() bool {
|
||||
}
|
||||
|
||||
// finding an eligible timestamp
|
||||
now := a.getTime()
|
||||
for t, _ := range timeTotal {
|
||||
if t.Year() == now.Year() && t.Month() == now.Month() && t.Day() == now.Day() && t.Hour() == now.Hour() {
|
||||
if t.Year() == cfg.Now.Year() && t.Month() == cfg.Now.Month() && t.Day() == cfg.Now.Day() && t.Hour() == cfg.Now.Hour() {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -455,18 +440,11 @@ func (a AppConfig) TakeSnapshot(schedule string) error {
|
||||
log.Printf("AppConfig.TakeSnapshot : %s : Start %s", a.Name, schedule)
|
||||
}
|
||||
|
||||
takeSnapshot := make(map[string]string)
|
||||
for _, v := range a.Sources {
|
||||
takeSnapshot[v.Box()] = takeSnapshot[v.Box()] + " " + v.Path()
|
||||
}
|
||||
for k, v := range takeSnapshot {
|
||||
if *debugFlag {
|
||||
log.Printf("AppConfig.TakeSnapshot : %s : taking snapshot on %s for %s", a.Name, k, v)
|
||||
}
|
||||
err := cfg.Box[k].SSHExec("zfsnap snapshot -p " + schedule + "- -a " + cfg.Zfsnap[schedule] + v)
|
||||
err := cfg.Box[v.Box()].ZFSTakeSnapshot(schedule, v.Path())
|
||||
if err != nil {
|
||||
if *debugFlag {
|
||||
log.Printf("AppConfig.TakeSnapshot : %s : Error executing zfsnap on %s", a.Name, k)
|
||||
log.Printf("AppConfig.TakeSnapshot : %s : ZFSTakeSnapshot", a.Name)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user