Support generating a compressed archive for a server via the API

This commit is contained in:
Dane Everitt
2020-07-11 13:13:49 -07:00
parent 79928aff76
commit c1e591c99b
6 changed files with 155 additions and 7 deletions

View File

@@ -21,10 +21,10 @@ type Archive struct {
}
// Creates an archive at dest with all of the files definied in the included files struct.
func (a *Archive) Create(dest string, ctx context.Context) error {
func (a *Archive) Create(dest string, ctx context.Context) (os.FileInfo, error) {
f, err := os.OpenFile(dest, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return err
return nil, err
}
defer f.Close()
@@ -70,10 +70,12 @@ func (a *Archive) Create(dest string, ctx context.Context) error {
log.WithField("location", dest).Warn("failed to delete corrupted backup archive")
}
return err
return nil, err
}
return nil
st, _ := f.Stat()
return st, nil
}
// Adds a single file to the existing tar archive writer.

View File

@@ -47,7 +47,7 @@ func (b *LocalBackup) Generate(included *IncludedFiles, prefix string) (*Archive
Files: included,
}
if err := a.Create(b.Path(), context.Background()); err != nil {
if _, err := a.Create(b.Path(), context.Background()); err != nil {
return nil, err
}

View File

@@ -32,7 +32,7 @@ func (s *S3Backup) Generate(included *IncludedFiles, prefix string) (*ArchiveDet
Files: included,
}
if err := a.Create(s.Path(), context.Background()); err != nil {
if _, err := a.Create(s.Path(), context.Background()); err != nil {
return nil, err
}