Skip to content

Commit

Permalink
prevent backup from silently failing
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptobioz authored and mcanevet committed Sep 18, 2018
1 parent 4cbdd18 commit f19ffce
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions engines/restic.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,35 @@ func (r *ResticEngine) Backup() (err error) {
err = util.Retry(3, r.init)
if err != nil {
err = fmt.Errorf("failed to create a secure repository: %v", err)
r.sendBackupStatus(1, v.Name)
return
}

err = util.Retry(3, r.resticBackup)
if err != nil {
err = fmt.Errorf("failed to backup the volume: %v", err)
r.sendBackupStatus(1, v.Name)
return
}

err = util.Retry(3, r.forget)
if err != nil {
err = fmt.Errorf("failed to forget the oldest snapshots: %v", err)
r.sendBackupStatus(1, v.Name)
return
}

if c.IsCheckScheduled(v) {
err = util.Retry(3, r.verify)
if err != nil {
err = fmt.Errorf("failed to verify backup: %v", err)
r.sendBackupStatus(1, v.Name)
return err
}
}

r.sendBackupStatus(0, v.Name)

return
}

Expand Down Expand Up @@ -268,6 +274,22 @@ func (r *ResticEngine) snapshots() (snapshots []Snapshot, err error) {
return
}

// sendBackupStatus creates a metric which represents the backup status. 0 == OK / 1 == KO
func (r *ResticEngine) sendBackupStatus(status int, volume string) {
metric := r.Volume.MetricsHandler.NewMetric("bivac_backupExitCode", "gauge")
err := metric.UpdateEvent(
&metrics.Event{
Labels: map[string]string{
"volume": volume,
},
Value: strconv.Itoa(status),
},
)
if err != nil {
log.Errorf("failed to send metric: %v", err)
}
}

// launchRestic starts a restic container with the given command
func (r *ResticEngine) launchRestic(cmd []string, volumes []*volume.Volume) (state int, stdout string, err error) {
config := r.Orchestrator.GetHandler().Config
Expand Down

0 comments on commit f19ffce

Please sign in to comment.