Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Commit

Permalink
on demand backup format response
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprodan authored and Stefan Prodan committed May 8, 2017
1 parent f549ddb commit dc1b2c6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,11 @@ curl -X POST http://mgob-host:8090/backup/mongo-debug

```json
{
"name": "mongo-debug-1494241186.gz",
"plan": "mongo-debug",
"duration": 3987586336,
"size": 453343,
"status": 200,
"timestamp": "2017-05-08T10:59:46.627351656Z"
"file": "mongo-debug-1494256295.gz",
"duration": "3.635186255s",
"size": "455 kB",
"timestamp": "2017-05-08T15:11:35.940141701Z"
}
```

Expand Down
23 changes: 21 additions & 2 deletions api/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/stefanprodan/mgob/config"
"github.com/stefanprodan/mgob/notifier"
"net/http"
"time"
)

func configCtx(data config.AppConfig) func(next http.Handler) http.Handler {
Expand All @@ -32,7 +33,7 @@ func postBackup(w http.ResponseWriter, r *http.Request) {
return
}

logrus.WithField("plan", planID).Infof("On demand backup started %v", plan)
logrus.WithField("plan", planID).Info("On demand backup started")

res, err := backup.Run(plan, cfg.TmpPath, cfg.StoragePath)
if err != nil {
Expand All @@ -52,6 +53,24 @@ func postBackup(w http.ResponseWriter, r *http.Request) {
false, plan); err != nil {
logrus.WithField("plan", plan.Name).Errorf("Notifier failed for on demand backup %v", err)
}
render.JSON(w, r, res)
render.JSON(w, r, toBackupResult(res))
}
}

type backupResult struct {
Plan string `json:"plan"`
File string `json:"file"`
Duration string `json:"duration"`
Size string `json:"size"`
Timestamp time.Time `json:"timestamp"`
}

func toBackupResult(res backup.Result) backupResult {
return backupResult{
Plan: res.Plan,
Duration: fmt.Sprintf("%v", res.Duration),
File: res.Name,
Size: humanize.Bytes(uint64(res.Size)),
Timestamp: res.Timestamp,
}
}

0 comments on commit dc1b2c6

Please sign in to comment.