2020-04-04 23:07:25 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/pkg/errors"
|
2020-04-14 05:01:07 +00:00
|
|
|
"github.com/pterodactyl/wings/server/backup"
|
2020-04-04 23:07:25 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2020-04-14 05:01:07 +00:00
|
|
|
// Performs a server backup and then emits the event over the server websocket. We
|
|
|
|
// let the actual backup system handle notifying the panel of the status, but that
|
|
|
|
// won't emit a websocket event.
|
|
|
|
func (s *Server) BackupRoot(b *backup.Backup) error {
|
|
|
|
r, err := b.LocalBackup(s.Filesystem.Path())
|
2020-04-05 02:55:23 +00:00
|
|
|
if err != nil {
|
2020-04-14 05:01:07 +00:00
|
|
|
if notifyError := b.NotifyPanel(r, false); notifyError != nil {
|
|
|
|
zap.S().Warnw("failed to notify panel of failed backup state", zap.String("backup", b.Uuid), zap.Error(err))
|
2020-04-04 23:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
2020-04-14 05:01:07 +00:00
|
|
|
// Try to notify the panel about the status of this backup. If for some reason this request
|
|
|
|
// fails, delete the archive from the daemon and return that error up the chain to the caller.
|
|
|
|
if notifyError := b.NotifyPanel(r, true); notifyError != nil {
|
|
|
|
b.Remove()
|
2020-04-04 23:07:25 +00:00
|
|
|
|
2020-04-14 05:01:07 +00:00
|
|
|
return notifyError
|
2020-04-04 23:07:25 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 04:03:50 +00:00
|
|
|
// Emit an event over the socket so we can update the backup in realtime on
|
|
|
|
// the frontend for the server.
|
2020-04-14 05:01:07 +00:00
|
|
|
s.Events().PublishJson(BackupCompletedEvent+":"+b.Uuid, map[string]interface{}{
|
2020-04-07 04:22:43 +00:00
|
|
|
"uuid": b.Uuid,
|
2020-04-14 05:01:07 +00:00
|
|
|
"sha256_hash": r.Checksum,
|
|
|
|
"file_size": r.Size,
|
2020-04-07 04:03:50 +00:00
|
|
|
})
|
|
|
|
|
2020-04-04 23:07:25 +00:00
|
|
|
return nil
|
2020-04-14 05:01:07 +00:00
|
|
|
}
|