Skip to content

Commit

Permalink
Merge pull request #27 from abbbi/upload-backup-log
Browse files Browse the repository at this point in the history
add upload-backup-log handler
  • Loading branch information
tizbac authored Aug 14, 2024
2 parents 81af25c + 54b3d2f commit 73c5ba2
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cmd/pmoxs3backuproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,28 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Write(resp)
}

if strings.HasPrefix(action, "upload-backup-log") && r.Method == "POST" {
var ss s3pmoxcommon.Snapshot
ss.InitWithQuery(r.URL.Query())
tgtfile := ss.S3Prefix() + "/client.log.blob"
_, err := C.Client.PutObject(
context.Background(),
ds,
tgtfile,
r.Body,
r.ContentLength,
minio.PutObjectOptions{},
)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
s3backuplog.ErrorPrint("%s failed to upload backup log: %s", err.Error())
return
}
s3backuplog.InfoPrint("Saved backup log: %s", tgtfile)
w.WriteHeader(http.StatusOK)
}

if strings.HasPrefix(action, "snapshots") {
if r.Method == "DELETE" {
var ss s3pmoxcommon.Snapshot
Expand Down Expand Up @@ -417,13 +439,15 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.RequestURI, "/fixed_index") && s.H2Ticket != nil && r.Method == "PUT" {
body, err := io.ReadAll(r.Body)
if err != nil {
s3backuplog.ErrorPrint("Unable to read body: %s", err.Error())
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
return
}
req := AssignmentRequest{}
err = json.Unmarshal(body, &req)
if err != nil {
s3backuplog.ErrorPrint("Unable to unmarshal json: %s", err.Error())
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
return
Expand All @@ -446,6 +470,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
for i := 0; i < len(req.DigestList); i++ {
b, err := hex.DecodeString(req.DigestList[i])
if err != nil {
s3backuplog.ErrorPrint("Unable to decode digest: %s", err.Error())
w.WriteHeader(http.StatusBadRequest)
io.WriteString(w, err.Error())
}
Expand Down

0 comments on commit 73c5ba2

Please sign in to comment.