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 5, 2018
1 parent 5464b3d commit 92b9896
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pkg/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ import (
kubeutil "github.com/heptio/ark/pkg/util/kube"
)

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

// 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 +224,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 +299,23 @@ func (kb *kubernetesBackupper) Backup(logger logrus.FieldLogger, backupRequest *
return err
}

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

type tarWriter interface {
io.Closer
Write([]byte) (int, error)
Expand Down

0 comments on commit 92b9896

Please sign in to comment.