prysm-pulse/beacon-chain/db/http_backup_handler.go
Preston Van Loon 7a04ff6368 Add database API for creating backups (#3694)
* Save db backup

* Fix DB backup method

* Add backup db webhook

* gaz

* if err != nil

* more verbose filename

* Don't obliterate everything :)
2019-10-03 17:29:49 +08:00

30 lines
708 B
Go

package db
import (
"context"
"fmt"
"net/http"
"github.com/sirupsen/logrus"
)
// BackupHandler for accepting requests to initiate a new database backup.
func BackupHandler(db Database) func(http.ResponseWriter, *http.Request) {
log := logrus.WithField("prefix", "db")
return func(w http.ResponseWriter, _ *http.Request) {
log.Debug("Creating database backup from HTTP webhook.")
if err := db.Backup(context.Background()); err != nil {
log.WithError(err).Error("Failed to create backup")
w.WriteHeader(http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
_, err := fmt.Fprint(w, "OK")
if err != nil {
log.WithError(err).Error("Failed to write OK")
}
}
}