Break out the backup functions of the daemon in prep for S3 support

This commit is contained in:
Dane Everitt
2020-04-13 22:01:07 -07:00
parent fd9487ea4d
commit 11035b561a
7 changed files with 260 additions and 227 deletions

View File

@@ -4,6 +4,7 @@ import (
"bufio"
"github.com/gin-gonic/gin"
"github.com/pterodactyl/wings/router/tokens"
"github.com/pterodactyl/wings/server/backup"
"net/http"
"os"
"strconv"
@@ -25,13 +26,20 @@ func getDownloadBackup(c *gin.Context) {
return
}
p, st, err := s.LocateBackup(token.BackupUuid)
b, st, err := backup.LocateLocal(token.BackupUuid)
if err != nil {
if os.IsNotExist(err) {
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{
"error": "The requested backup was not found on this server.",
})
return
}
TrackedServerError(err, s).AbortWithServerError(c)
return
}
f, err := os.Open(p)
f, err := os.Open(b.Path())
if err != nil {
TrackedServerError(err, s).AbortWithServerError(c)
return

View File

@@ -3,26 +3,23 @@ package router
import (
"github.com/gin-gonic/gin"
"github.com/pterodactyl/wings/server"
"github.com/pterodactyl/wings/server/backup"
"go.uber.org/zap"
"net/http"
"os"
)
// Backs up a server.
func postServerBackup(c *gin.Context) {
s := GetServer(c.Param("server"))
var data struct{
Uuid string `json:"uuid"`
IgnoredFiles []string `json:"ignored_files"`
}
data := &backup.Backup{}
c.BindJSON(&data)
go func(backup *server.Backup) {
if err := backup.BackupAndNotify(); err != nil {
go func(b *backup.Backup, serv *server.Server) {
if err := serv.BackupRoot(b); err != nil {
zap.S().Errorw("failed to generate backup for server", zap.Error(err))
}
}(s.NewBackup(data.Uuid, data.IgnoredFiles))
}(data, s)
c.Status(http.StatusAccepted)
}
@@ -31,13 +28,13 @@ func postServerBackup(c *gin.Context) {
func deleteServerBackup(c *gin.Context) {
s := GetServer(c.Param("server"))
p, _, err := s.LocateBackup(c.Param("backup"))
b, _, err := backup.LocateLocal(c.Param("backup"))
if err != nil {
TrackedServerError(err, s).AbortWithServerError(c)
return
}
if err := os.Remove(p); err != nil {
if err := b.Remove(); err != nil {
TrackedServerError(err, s).AbortWithServerError(c)
return
}