Ignore symlinks with missing target, add better backup logging, update copyright year to 2021

This commit is contained in:
Matthew Penner 2020-12-27 12:54:18 -07:00
parent e75118e0f0
commit 640e30de8a
5 changed files with 43 additions and 14 deletions

View File

@ -408,7 +408,7 @@ __ [blue][bold]Pterodactyl[reset] _____/___/_______ _______ ______
\___/\___/___/___/___/___ /______/ \___/\___/___/___/___/___ /______/
/_______/ [bold]v%s[reset] /_______/ [bold]v%s[reset]
Copyright © 2018 - 2020 Dane Everitt & Contributors Copyright © 2018 - 2021 Dane Everitt & Contributors
Website: https://pterodactyl.io Website: https://pterodactyl.io
Source: https://github.com/pterodactyl/wings Source: https://github.com/pterodactyl/wings

View File

@ -116,11 +116,14 @@ func (b *Backup) Details() *ArchiveDetails {
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
wg.Add(2) wg.Add(2)
l := log.WithField("backup_id", b.Uuid)
var checksum string var checksum string
// Calculate the checksum for the file. // Calculate the checksum for the file.
go func() { go func() {
defer wg.Done() defer wg.Done()
l.Info("computing checksum for backup..")
resp, err := b.Checksum() resp, err := b.Checksum()
if err != nil { if err != nil {
log.WithFields(log.Fields{ log.WithFields(log.Fields{
@ -131,6 +134,7 @@ func (b *Backup) Details() *ArchiveDetails {
} }
checksum = hex.EncodeToString(resp) checksum = hex.EncodeToString(resp)
l.WithField("checksum", checksum).Info("computed checksum for backup")
}() }()
var sz int64 var sz int64

View File

@ -2,6 +2,7 @@ package backup
import ( import (
"errors" "errors"
"github.com/apex/log"
"github.com/pterodactyl/wings/server/filesystem" "github.com/pterodactyl/wings/server/filesystem"
"os" "os"
) )
@ -47,9 +48,16 @@ func (b *LocalBackup) Generate(basePath, ignore string) (*ArchiveDetails, error)
Ignore: ignore, Ignore: ignore,
} }
l := log.WithFields(log.Fields{
"backup_id": b.Uuid,
"adapter": "local",
})
l.Info("attempting to create backup..")
if err := a.Create(b.Path()); err != nil { if err := a.Create(b.Path()); err != nil {
return nil, err return nil, err
} }
l.Info("created backup successfully.")
return b.Details(), nil return b.Details(), nil
} }

View File

@ -27,9 +27,16 @@ func (s *S3Backup) Generate(basePath, ignore string) (*ArchiveDetails, error) {
Ignore: ignore, Ignore: ignore,
} }
l := log.WithFields(log.Fields{
"backup_id": s.Uuid,
"adapter": "s3",
})
l.Info("attempting to create backup..")
if err := a.Create(s.Path()); err != nil { if err := a.Create(s.Path()); err != nil {
return nil, err return nil, err
} }
l.Info("created backup successfully.")
rc, err := os.Open(s.Path()) rc, err := os.Open(s.Path())
if err != nil { if err != nil {
@ -63,22 +70,26 @@ func (Reader) Close() error {
func (s *S3Backup) generateRemoteRequest(rc io.ReadCloser) error { func (s *S3Backup) generateRemoteRequest(rc io.ReadCloser) error {
defer rc.Close() defer rc.Close()
size, err := s.Backup.Size()
if err != nil {
return err
}
urls, err := api.New().GetBackupRemoteUploadURLs(s.Backup.Uuid, size)
if err != nil {
return err
}
l := log.WithFields(log.Fields{ l := log.WithFields(log.Fields{
"backup_id": s.Uuid, "backup_id": s.Uuid,
"adapter": "s3", "adapter": "s3",
}) })
l.Info("attempting to upload backup..") l.Debug("attempting to get size of backup..")
size, err := s.Backup.Size()
if err != nil {
return err
}
l.WithField("size", size).Debug("got size of backup")
l.Debug("attempting to get S3 upload urls from Panel..")
urls, err := api.New().GetBackupRemoteUploadURLs(s.Backup.Uuid, size)
if err != nil {
return err
}
l.Debug("got S3 upload urls from the Panel")
partCount := len(urls.Parts)
l.WithField("parts", partCount).Info("attempting to upload backup..")
handlePart := func(part string, size int64) (string, error) { handlePart := func(part string, size int64) (string, error) {
r, err := http.NewRequest(http.MethodPut, part, nil) r, err := http.NewRequest(http.MethodPut, part, nil)
@ -111,7 +122,6 @@ func (s *S3Backup) generateRemoteRequest(rc io.ReadCloser) error {
return res.Header.Get("ETag"), nil return res.Header.Get("ETag"), nil
} }
partCount := len(urls.Parts)
for i, part := range urls.Parts { for i, part := range urls.Parts {
// Get the size for the current part. // Get the size for the current part.
var partSize int64 var partSize int64
@ -128,6 +138,8 @@ func (s *S3Backup) generateRemoteRequest(rc io.ReadCloser) error {
l.WithField("part_id", part).WithError(err).Warn("failed to upload part") l.WithField("part_id", part).WithError(err).Warn("failed to upload part")
return err return err
} }
l.WithField("part_id", part).Info("successfully uploaded backup part.")
} }
l.WithField("parts", partCount).Info("backup has been successfully uploaded") l.WithField("parts", partCount).Info("backup has been successfully uploaded")

View File

@ -152,7 +152,12 @@ func (a *Archive) addToArchive(p string, rp string, w *tar.Writer) error {
if s.Mode()&os.ModeSymlink != 0 { if s.Mode()&os.ModeSymlink != 0 {
// Read the target of the symlink. // Read the target of the symlink.
target, err = os.Readlink(s.Name()) target, err = os.Readlink(s.Name())
if err != nil && !os.IsNotExist(err) { if err != nil {
// Skip symlinks if the target does not exist.
if os.IsNotExist(err) {
return nil
}
return errors.WithMessagef(err, "failed to read symlink target for '%s'", rp) return errors.WithMessagef(err, "failed to read symlink target for '%s'", rp)
} }
} }