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 (
|
import (
|
||||||
"brainbaking.com/restictray/restic"
|
"brainbaking.com/restictray/restic"
|
||||||
"errors"
|
|
||||||
"fyne.io/systray"
|
"fyne.io/systray"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"github.com/rs/zerolog/log"
|
"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("")
|
log.Err(err).Msg("")
|
||||||
systray.ResetMenu()
|
systray.ResetMenu()
|
||||||
addMenuError(err)
|
addMenuError(err)
|
||||||
|
@ -64,16 +63,12 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates snapshot information in restic wrapper and menu labels. This is a blocking call.
|
// 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) {
|
func updateSnapshots(cnf *restic.Config, mnu *resticmenu) {
|
||||||
err := wrapper.UpdateLatestSnapshots(cnf)
|
err := wrapper.UpdateLatestSnapshots(cnf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, restic.ResticCmdTimeoutError) {
|
log.Warn().Err(err).Msg("update snapshot")
|
||||||
log.Warn().Err(err).Msg("update snapshot timeout")
|
mnu.latestSnapshot.SetTitle("‼️ " + err.Error())
|
||||||
mnu.latestSnapshot.SetTitle("‼️ Latest: timeout while updating")
|
|
||||||
mnu.backupNowEnable()
|
|
||||||
} else {
|
|
||||||
handleError(err)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +126,7 @@ func onSystrayReady() {
|
||||||
|
|
||||||
cnf, err := restic.ReadConfig()
|
cnf, err := restic.ReadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(err)
|
handleFatalError(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +134,7 @@ func onSystrayReady() {
|
||||||
|
|
||||||
backupCheckTime := make(chan bool, 1)
|
backupCheckTime := make(chan bool, 1)
|
||||||
hourlyBackupCheckFn := func() {
|
hourlyBackupCheckFn := func() {
|
||||||
time.Sleep(1 * time.Minute)
|
time.Sleep(1 * time.Hour)
|
||||||
backupCheckTime <- true
|
backupCheckTime <- true
|
||||||
}
|
}
|
||||||
go hourlyBackupCheckFn()
|
go hourlyBackupCheckFn()
|
||||||
|
@ -217,7 +212,7 @@ func buildMenu() *resticmenu {
|
||||||
func mountBackups(cnf *restic.Config) {
|
func mountBackups(cnf *restic.Config) {
|
||||||
err := wrapper.MountBackups(cnf)
|
err := wrapper.MountBackups(cnf)
|
||||||
if err != nil {
|
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.
|
// 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 {
|
func (w *Wrapper) UpdateLatestSnapshots(c *Config) error {
|
||||||
cmd := resticCmd("--json", "--password-file", PasswordFile(), "-r", c.Repository, "snapshots")
|
cmd := resticCmd("--json", "--password-file", PasswordFile(), "-r", c.Repository, "snapshots")
|
||||||
|
|
||||||
|
@ -125,11 +126,11 @@ func (w *Wrapper) UpdateLatestSnapshots(c *Config) error {
|
||||||
case <-done:
|
case <-done:
|
||||||
case <-time.After(cmdTimeout):
|
case <-time.After(cmdTimeout):
|
||||||
cmd.Process.Kill()
|
cmd.Process.Kill()
|
||||||
return fmt.Errorf("restic snapshots cmd: %w", ResticCmdTimeoutError)
|
return fmt.Errorf("snapshot cmd: %w", ResticCmdTimeoutError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
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)
|
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.
|
// 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 {
|
func (w *Wrapper) Backup(c *Config) error {
|
||||||
cmd := resticCmd("--password-file", PasswordFile(), "-r", c.Repository, "--exclude-file", ExcludeFile(), "backup", c.Backup, "--no-scan")
|
cmd := resticCmd("--password-file", PasswordFile(), "-r", c.Repository, "--exclude-file", ExcludeFile(), "backup", c.Backup, "--no-scan")
|
||||||
stdout, _ := cmd.StdoutPipe()
|
stdout, _ := cmd.StdoutPipe()
|
||||||
|
|
Loading…
Reference in New Issue