[lxc-devel] [lxd/master] Make backup expiry work
monstermunchkin on Github
lxc-bot at linuxcontainers.org
Mon Oct 15 13:33:38 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 376 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20181015/3f9ea749/attachment.bin>
-------------- next part --------------
From 1212551740b9faf31a752d2ca3a8db3d7cf48087 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Mon, 15 Oct 2018 14:59:38 +0200
Subject: [PATCH] Make backup expiry work
Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
lxc/import.go | 1 +
lxd/backup.go | 21 ++++++++++++++-------
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/lxc/import.go b/lxc/import.go
index 74d4bc0d19..d544b58882 100644
--- a/lxc/import.go
+++ b/lxc/import.go
@@ -82,6 +82,7 @@ func (c *cmdImport) Run(cmd *cobra.Command, args []string) error {
op, err := resource.server.CreateContainerFromBackup(createArgs)
if err != nil {
+ progress.Done("")
return err
}
diff --git a/lxd/backup.go b/lxd/backup.go
index 75f4e33b16..5806582a55 100644
--- a/lxd/backup.go
+++ b/lxd/backup.go
@@ -90,13 +90,14 @@ type backup struct {
}
type backupInfo struct {
- Project string `json:"project" yaml:"project"`
- Name string `json:"name" yaml:"name"`
- Backend string `json:"backend" yaml:"backend"`
- Privileged bool `json:"privileged" yaml:"privileged"`
- Pool string `json:"pool" yaml:"pool"`
- Snapshots []string `json:"snapshots,omitempty" yaml:"snapshots,omitempty"`
- HasBinaryFormat bool `json:"-" yaml:"-"`
+ Project string `json:"project" yaml:"project"`
+ Name string `json:"name" yaml:"name"`
+ Backend string `json:"backend" yaml:"backend"`
+ Privileged bool `json:"privileged" yaml:"privileged"`
+ Pool string `json:"pool" yaml:"pool"`
+ Snapshots []string `json:"snapshots,omitempty" yaml:"snapshots,omitempty"`
+ HasBinaryFormat bool `json:"-" yaml:"-"`
+ Expiry time.Time `json:"expiry" yaml:"expiry"`
}
// Rename renames a container backup
@@ -236,6 +237,11 @@ func backupGetInfo(r io.ReadSeeker) (*backupInfo, error) {
return nil, fmt.Errorf("Backup is missing index.yaml")
}
+ // Check whether the backup has expired
+ if time.Now().Unix()-result.Expiry.Unix() >= 0 {
+ return nil, fmt.Errorf("Backup has expired")
+ }
+
result.HasBinaryFormat = hasBinaryFormat
return &result, nil
}
@@ -321,6 +327,7 @@ func backupCreateTarball(s *state.State, path string, backup backup) error {
Privileged: container.IsPrivileged(),
Pool: pool,
Snapshots: []string{},
+ Expiry: backup.expiryDate,
}
if !backup.containerOnly {
More information about the lxc-devel
mailing list