[lxc-devel] [lxd/master] backup: Allow backups to not expire
monstermunchkin on Github
lxc-bot at linuxcontainers.org
Mon Nov 5 03:51:08 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 592 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20181105/5cbb830a/attachment.bin>
-------------- next part --------------
From 35b1683996fe97dc33742bfebb7f24c826a6941a Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Mon, 5 Nov 2018 04:31:05 +0100
Subject: [PATCH 1/2] lxc/export: Don't set expiry
Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
lxc/export.go | 2 --
1 file changed, 2 deletions(-)
diff --git a/lxc/export.go b/lxc/export.go
index fdb43c82dc..0b76e1517d 100644
--- a/lxc/export.go
+++ b/lxc/export.go
@@ -4,7 +4,6 @@ import (
"io"
"os"
"strings"
- "time"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@@ -65,7 +64,6 @@ func (c *cmdExport) Run(cmd *cobra.Command, args []string) error {
req := api.ContainerBackupsPost{
Name: "",
- ExpiryDate: time.Now().Add(30 * time.Minute),
ContainerOnly: c.flagContainerOnly,
OptimizedStorage: c.flagOptimizedStorage,
}
From 94e732e488d4494d754a2af5109f9a2d8a0fa5a3 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Mon, 5 Nov 2018 04:34:15 +0100
Subject: [PATCH 2/2] backup: Allow backups to not expire
Backup expiry can be disabled by setting `"expiry" = "0"`. A simple
empty string would not suffice since we cannot always differentiate
between an empty string and an omitted `expiry` field.
Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
lxd/container_backup.go | 15 +++++++++++++--
shared/api/container_backup.go | 8 ++++----
2 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/lxd/container_backup.go b/lxd/container_backup.go
index 345ff49789..03082786cf 100644
--- a/lxd/container_backup.go
+++ b/lxd/container_backup.go
@@ -82,7 +82,8 @@ func containerBackupsPost(d *Daemon, r *http.Request) Response {
}
req := api.ContainerBackupsPost{
- ExpiryDate: time.Now().Add(30 * time.Minute), // default expiry time of 30 minutes
+ // default expiry time of 30 minutes
+ ExpiryDate: time.Now().Add(30 * time.Minute).Format(time.RFC3339),
}
err = json.NewDecoder(r.Body).Decode(&req)
if err != nil {
@@ -127,12 +128,22 @@ func containerBackupsPost(d *Daemon, r *http.Request) Response {
fullName := name + shared.SnapshotDelimiter + req.Name
+ if req.ExpiryDate == "0" {
+ // Set zero time if backup is not to expiry
+ req.ExpiryDate = time.Date(1, time.January, 1, 0, 0, 0, 0, time.Local).Format(time.RFC3339)
+ }
+
+ expiry, err := time.Parse(time.RFC3339, req.ExpiryDate)
+ if err != nil {
+ return BadRequest(err)
+ }
+
backup := func(op *operation) error {
args := db.ContainerBackupArgs{
Name: fullName,
ContainerID: c.Id(),
CreationDate: time.Now(),
- ExpiryDate: req.ExpiryDate,
+ ExpiryDate: expiry,
ContainerOnly: req.ContainerOnly,
OptimizedStorage: req.OptimizedStorage,
}
diff --git a/shared/api/container_backup.go b/shared/api/container_backup.go
index 15b3b5234d..067b3d230f 100644
--- a/shared/api/container_backup.go
+++ b/shared/api/container_backup.go
@@ -5,10 +5,10 @@ import "time"
// ContainerBackupsPost represents the fields available for a new LXD container backup
// API extension: container_backup
type ContainerBackupsPost struct {
- Name string `json:"name" yaml:"name"`
- ExpiryDate time.Time `json:"expiry" yaml:"expiry"`
- ContainerOnly bool `json:"container_only" yaml:"container_only"`
- OptimizedStorage bool `json:"optimized_storage" yaml:"optimized_storage"`
+ Name string `json:"name" yaml:"name"`
+ ExpiryDate string `json:"expiry" yaml:"expiry"`
+ ContainerOnly bool `json:"container_only" yaml:"container_only"`
+ OptimizedStorage bool `json:"optimized_storage" yaml:"optimized_storage"`
}
// ContainerBackup represents a LXD container backup
More information about the lxc-devel
mailing list