Skip to content

Commit

Permalink
Add backup-version file in backup tarball
Browse files Browse the repository at this point in the history
Signed-off-by: Wayne Witzel III <wayne@riotousliving.com>
  • Loading branch information
wwitzel3 committed Dec 18, 2018
1 parent 5464b3d commit 6be86b2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/1117-wwitzel3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add backup-version file in backup tarball.
27 changes: 27 additions & 0 deletions pkg/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"fmt"
"io"
"strconv"
"time"

"github.com/pkg/errors"
Expand All @@ -41,6 +42,9 @@ import (
kubeutil "github.com/heptio/ark/pkg/util/kube"
)

// BackupVersion is the current backup version for Ark.
const BackupVersion = 1

// Backupper performs backups.
type Backupper interface {
// Backup takes a backup using the specification in the api.Backup and writes backup and log data
Expand Down Expand Up @@ -221,6 +225,10 @@ func (kb *kubernetesBackupper) Backup(logger logrus.FieldLogger, backupRequest *
log := logger.WithField("backup", kubeutil.NamespaceAndName(backupRequest))
log.Info("Starting backup")

if err := kb.writeBackupVersion(tw); err != nil {
return errors.WithStack(err)
}

backupRequest.NamespaceIncludesExcludes = getNamespaceIncludesExcludes(backupRequest.Backup)
log.Infof("Including namespaces: %s", backupRequest.NamespaceIncludesExcludes.IncludesString())
log.Infof("Excluding namespaces: %s", backupRequest.NamespaceIncludesExcludes.ExcludesString())
Expand Down Expand Up @@ -292,6 +300,25 @@ func (kb *kubernetesBackupper) Backup(logger logrus.FieldLogger, backupRequest *
return err
}

func (kb *kubernetesBackupper) writeBackupVersion(tw *tar.Writer) error {
versionString := strconv.Itoa(BackupVersion)

hdr := &tar.Header{
Name: "backup-version",
Size: int64(len(versionString)),
Typeflag: tar.TypeReg,
Mode: 0644,
ModTime: time.Now(),
}
if err := tw.WriteHeader(hdr); err != nil {
return err
}
if _, err := tw.Write([]byte(versionString)); err != nil {
return err
}
return nil
}

type tarWriter interface {
io.Closer
Write([]byte) (int, error)
Expand Down
4 changes: 1 addition & 3 deletions pkg/controller/backup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ import (
"github.com/heptio/ark/pkg/volume"
)

const backupVersion = 1

type backupController struct {
*genericController

Expand Down Expand Up @@ -245,7 +243,7 @@ func (c *backupController) prepareBackupRequest(backup *api.Backup) *pkgbackup.R
}

// set backup version
request.Status.Version = backupVersion
request.Status.Version = pkgbackup.BackupVersion

// calculate expiration
if request.Spec.TTL.Duration > 0 {
Expand Down

0 comments on commit 6be86b2

Please sign in to comment.