[lxc-devel] [lxd/master] Fix backup expiry

monstermunchkin on Github lxc-bot at linuxcontainers.org
Tue Oct 8 12:35:27 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191008/b3d407f6/attachment.bin>
-------------- next part --------------
From 2a1d40ba25915c18baf839aeb0bd784a11de1255 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Tue, 8 Oct 2019 14:03:46 +0200
Subject: [PATCH 1/2] lxd: Fix backup expiry

This fixes a bug which causes all backups to never expire.

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 lxd/container_backup.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lxd/container_backup.go b/lxd/container_backup.go
index cf6b834cb2..fb1f35e275 100644
--- a/lxd/container_backup.go
+++ b/lxd/container_backup.go
@@ -99,10 +99,10 @@ func containerBackupsPost(d *Daemon, r *http.Request) response.Response {
 		return response.InternalError(err)
 	}
 
-	expiry, _ := rj.GetString("expiry")
+	expiry, _ := rj.GetString("expires_at")
 	if expiry == "" {
 		// Disable expiration by setting it to zero time
-		rj["expiry"] = time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)
+		rj["expires_at"] = time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)
 	}
 
 	// Create body with correct expiry

From 1e9ae9c234ef76f93dcb3da691104d7bdb5e6b09 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Tue, 8 Oct 2019 14:31:30 +0200
Subject: [PATCH 2/2] lxd: Fix backup expiry check

This fixes issues regarding timezones in combination with zero time.

Before, backups might have wrongfully been expired/removed due to
timezone issues.

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 lxd/db/containers.go | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index daaab7ba0d..38336718af 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -1325,7 +1325,9 @@ func (c *Cluster) ContainerBackupsGetExpired() ([]string, error) {
 			return []string{}, err
 		}
 
-		if backupExpiry.IsZero() {
+		// Since zero time causes some issues due to timezones, we check the
+		// unix timestamp instead of IsZero().
+		if backupExpiry.Unix() <= 0 {
 			// Backup doesn't expire
 			continue
 		}


More information about the lxc-devel mailing list