...
 
Commits (3)
......@@ -225,6 +225,18 @@ current backup has finished, and exit afterwards.
You can find the pid of the running process in the repository directory in the
file `.pid`.
Signals
-------
snaprd responds to various signals.
- **INT**, **TERM**: Makes snaprd exit immediately, killing a potentially
running rsync process using the same signal.
- **USR1**: While rsync is running, wait until it finished, then exit.
Otherwise just exit.
- **USR2**: If snaprd is idle waiting for the next scheduled snapshot,
sending SIGUSR2 will cancel this waiting time and force an immediate
snapshot.
Schedules
---------
......
......@@ -14,6 +14,21 @@ func FailureMail(exitCode int, logBuffer *RingIO) {
SendMail(config.Notify, subject, mail)
}
func RsyncIssueMail(rsyncError error, rsyncErrorCode int) {
var errText string
if s, ok := rsyncIgnoredErrors[rsyncErrorCode]; ok == true {
errText = s
} else {
errText = "<unknown>"
}
mail := fmt.Sprintf(`rsync finished with error: %s (%s).
This is a non-fatal error, snaprd will try again.`, rsyncError, errText)
subject := fmt.Sprintf("snaprd rsync error (origin: %s)", config.Origin)
// In this case we care that the mail command is not blocking the whole
// program
go SendMail(config.Notify, subject, mail)
}
func NotifyMail(to, msg string) {
SendMail(to, "snaprd notice", msg)
}
......
......@@ -54,9 +54,15 @@ func lastGoodTicker(in, out chan *snapshot, cl clock) {
debugf("gap: %s", gap)
wait = schedules[config.Schedule][0] - gap
if wait > 0 {
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, syscall.SIGUSR2)
log.Println("wait", wait, "before next snapshot")
time.Sleep(wait)
debugf("Awoken at %s\n", cl.Now())
select {
case <-sigc:
log.Println("Snapshot forced by signal, skipping wait time.")
case <-time.After(wait):
debugf("Awoken at %s\n", cl.Now())
}
}
}
out <- sn
......
......@@ -137,6 +137,10 @@ func createSnapshot(base *snapshot) (*snapshot, error) {
debugf("The error code we got is: %v", rsyncRet)
if errmsg, ok := rsyncIgnoredErrors[rsyncRet]; ok == true {
log.Printf("ignoring rsync error %d: %s", rsyncRet, errmsg)
// 24 ("files vanished") happens too often and is usually harmless
if rsyncRet != 24 && config.Notify != "" {
RsyncIssueMail(err, rsyncRet)
}
failed = false
}
}
......