2020-04-06 02:07:16 +00:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/pterodactyl/wings/server"
|
2020-04-14 05:01:07 +00:00
|
|
|
"github.com/pterodactyl/wings/server/backup"
|
2020-04-06 02:07:16 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Backs up a server.
|
|
|
|
func postServerBackup(c *gin.Context) {
|
|
|
|
s := GetServer(c.Param("server"))
|
|
|
|
|
2020-04-14 05:01:07 +00:00
|
|
|
data := &backup.Backup{}
|
2020-04-06 02:07:16 +00:00
|
|
|
c.BindJSON(&data)
|
|
|
|
|
2020-04-14 05:01:07 +00:00
|
|
|
go func(b *backup.Backup, serv *server.Server) {
|
|
|
|
if err := serv.BackupRoot(b); err != nil {
|
2020-04-06 02:07:16 +00:00
|
|
|
zap.S().Errorw("failed to generate backup for server", zap.Error(err))
|
|
|
|
}
|
2020-04-14 05:01:07 +00:00
|
|
|
}(data, s)
|
2020-04-06 02:07:16 +00:00
|
|
|
|
|
|
|
c.Status(http.StatusAccepted)
|
|
|
|
}
|
2020-04-10 05:07:48 +00:00
|
|
|
|
|
|
|
// Deletes a local backup of a server.
|
|
|
|
func deleteServerBackup(c *gin.Context) {
|
|
|
|
s := GetServer(c.Param("server"))
|
|
|
|
|
2020-04-14 05:01:07 +00:00
|
|
|
b, _, err := backup.LocateLocal(c.Param("backup"))
|
2020-04-10 05:07:48 +00:00
|
|
|
if err != nil {
|
|
|
|
TrackedServerError(err, s).AbortWithServerError(c)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-14 05:01:07 +00:00
|
|
|
if err := b.Remove(); err != nil {
|
2020-04-10 05:07:48 +00:00
|
|
|
TrackedServerError(err, s).AbortWithServerError(c)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Status(http.StatusNoContent)
|
|
|
|
}
|