do not treat snapshot check failures as fatal errors
This commit is contained in:
parent
94b9157d88
commit
c0b2fd5f21
19
main.go
19
main.go
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"brainbaking.com/restictray/restic"
|
||||
"errors"
|
||||
"fyne.io/systray"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
@ -34,7 +33,7 @@ func addMenuError(err error) {
|
|||
}()
|
||||
}
|
||||
|
||||
func handleError(err error) {
|
||||
func handleFatalError(err error) {
|
||||
log.Err(err).Msg("")
|
||||
systray.ResetMenu()
|
||||
addMenuError(err)
|
||||
|
@ -64,16 +63,12 @@ func main() {
|
|||
}
|
||||
|
||||
// Updates snapshot information in restic wrapper and menu labels. This is a blocking call.
|
||||
// This should be resilient as it's frequently called.
|
||||
func updateSnapshots(cnf *restic.Config, mnu *resticmenu) {
|
||||
err := wrapper.UpdateLatestSnapshots(cnf)
|
||||
if err != nil {
|
||||
if errors.Is(err, restic.ResticCmdTimeoutError) {
|
||||
log.Warn().Err(err).Msg("update snapshot timeout")
|
||||
mnu.latestSnapshot.SetTitle("‼️ Latest: timeout while updating")
|
||||
mnu.backupNowEnable()
|
||||
} else {
|
||||
handleError(err)
|
||||
}
|
||||
log.Warn().Err(err).Msg("update snapshot")
|
||||
mnu.latestSnapshot.SetTitle("‼️ " + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -131,7 +126,7 @@ func onSystrayReady() {
|
|||
|
||||
cnf, err := restic.ReadConfig()
|
||||
if err != nil {
|
||||
handleError(err)
|
||||
handleFatalError(err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -139,7 +134,7 @@ func onSystrayReady() {
|
|||
|
||||
backupCheckTime := make(chan bool, 1)
|
||||
hourlyBackupCheckFn := func() {
|
||||
time.Sleep(1 * time.Minute)
|
||||
time.Sleep(1 * time.Hour)
|
||||
backupCheckTime <- true
|
||||
}
|
||||
go hourlyBackupCheckFn()
|
||||
|
@ -217,7 +212,7 @@ func buildMenu() *resticmenu {
|
|||
func mountBackups(cnf *restic.Config) {
|
||||
err := wrapper.MountBackups(cnf)
|
||||
if err != nil {
|
||||
handleError(err)
|
||||
handleFatalError(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -110,6 +110,7 @@ func openFolder(folder string) error {
|
|||
}
|
||||
|
||||
// UpdateLatestSnapshots updates LatestSnapshots or returns an error. If timed out, returns an error as well.
|
||||
// Returns a ResticCmdTimeoutError if no response from restic after cmdTimeout
|
||||
func (w *Wrapper) UpdateLatestSnapshots(c *Config) error {
|
||||
cmd := resticCmd("--json", "--password-file", PasswordFile(), "-r", c.Repository, "snapshots")
|
||||
|
||||
|
@ -125,11 +126,11 @@ func (w *Wrapper) UpdateLatestSnapshots(c *Config) error {
|
|||
case <-done:
|
||||
case <-time.After(cmdTimeout):
|
||||
cmd.Process.Kill()
|
||||
return fmt.Errorf("restic snapshots cmd: %w", ResticCmdTimeoutError)
|
||||
return fmt.Errorf("snapshot cmd: %w", ResticCmdTimeoutError)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("restic snapshots cmd: %s: %w", string(out), err)
|
||||
return fmt.Errorf("snapshot cmd: %s: %w", string(out), err)
|
||||
}
|
||||
|
||||
err = json.Unmarshal(out, &w.LatestSnapshots)
|
||||
|
@ -142,6 +143,7 @@ func (w *Wrapper) UpdateLatestSnapshots(c *Config) error {
|
|||
}
|
||||
|
||||
// Backup uses "restic backup" to create a new snapshot. This is a blocking call.
|
||||
// Returns a ResticCmdTimeoutError if no response from restic after cmdTimeout
|
||||
func (w *Wrapper) Backup(c *Config) error {
|
||||
cmd := resticCmd("--password-file", PasswordFile(), "-r", c.Repository, "--exclude-file", ExcludeFile(), "backup", c.Backup, "--no-scan")
|
||||
stdout, _ := cmd.StdoutPipe()
|
||||
|
|
Loading…
Reference in New Issue