Add backup-version file in backup tarball

Signed-off-by: Wayne Witzel III <wwitzel3@vmware.com>
pull/1117/head
Wayne Witzel III 2018-12-05 17:56:53 -05:00
parent 5464b3dce8
commit d08c2e1b9c
4 changed files with 34 additions and 3 deletions

View File

@ -0,0 +1 @@
Add backup-version file in backup tarball.

View File

@ -25,6 +25,10 @@ const (
// for each resource type in the backup.
ResourcesDir = "resources"
// MetadataDir is a top-level directory expected in backups which contains
// files that store metadata about the backup, such as the backup version.
MetadataDir = "metadata"
// RestoreLabelKey is the label key that's applied to all resources that
// are created during a restore. This is applied for ease of identification
// of restored resources. The value will be the restore's name.

View File

@ -22,6 +22,7 @@ import (
"context"
"fmt"
"io"
"path/filepath"
"time"
"github.com/pkg/errors"
@ -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
@ -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())
@ -292,6 +300,26 @@ func (kb *kubernetesBackupper) Backup(logger logrus.FieldLogger, backupRequest *
return err
}
func (kb *kubernetesBackupper) writeBackupVersion(tw *tar.Writer) error {
versionFile := filepath.Join(api.MetadataDir, "version")
versionString := fmt.Sprintf("%d\n", BackupVersion)
hdr := &tar.Header{
Name: versionFile,
Size: int64(len(versionString)),
Typeflag: tar.TypeReg,
Mode: 0644,
ModTime: time.Now(),
}
if err := tw.WriteHeader(hdr); err != nil {
return errors.WithStack(err)
}
if _, err := tw.Write([]byte(versionString)); err != nil {
return errors.WithStack(err)
}
return nil
}
type tarWriter interface {
io.Closer
Write([]byte) (int, error)

View File

@ -51,8 +51,6 @@ import (
"github.com/heptio/ark/pkg/volume"
)
const backupVersion = 1
type backupController struct {
*genericController
@ -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 {