[lxc-devel] [lxd/master] lxd: Remove backup directory after creating tarball

monstermunchkin on Github lxc-bot at linuxcontainers.org
Mon Feb 25 09:25:32 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 523 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190225/fc755d45/attachment.bin>
-------------- next part --------------
From ccb9863269a1b69631d44caa8bfcd168a31081f2 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Mon, 25 Feb 2019 10:24:23 +0100
Subject: [PATCH] lxd: Remove backup directory after creating tarball

Remove the backup backup directory as soon as the tarball has been
created. That way one will hopefully not run out of disk space when
doing backups.

See #5515

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 lxd/backup.go        | 5 +++++
 lxd/storage_btrfs.go | 1 -
 lxd/storage_ceph.go  | 1 -
 lxd/storage_dir.go   | 1 -
 lxd/storage_lvm.go   | 1 -
 lxd/storage_zfs.go   | 1 -
 6 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lxd/backup.go b/lxd/backup.go
index 237aac13be..60b5da0871 100644
--- a/lxd/backup.go
+++ b/lxd/backup.go
@@ -382,6 +382,11 @@ func backupCreateTarball(s *state.State, path string, backup backup) error {
 		return err
 	}
 
+	err = os.RemoveAll(path)
+	if err != nil {
+		return err
+	}
+
 	// Compress it
 	compress, err := cluster.ConfigGetString(s.Cluster, "backups.compression_algorithm")
 	if err != nil {
diff --git a/lxd/storage_btrfs.go b/lxd/storage_btrfs.go
index e371848e12..f3e7534cca 100644
--- a/lxd/storage_btrfs.go
+++ b/lxd/storage_btrfs.go
@@ -1819,7 +1819,6 @@ func (s *storageBtrfs) ContainerBackupCreate(backup backup, source container) er
 	if err != nil {
 		return err
 	}
-	defer os.RemoveAll(tmpPath)
 
 	// Generate the actual backup
 	if backup.optimizedStorage {
diff --git a/lxd/storage_ceph.go b/lxd/storage_ceph.go
index 0e379a6bdb..c7c9e2571d 100644
--- a/lxd/storage_ceph.go
+++ b/lxd/storage_ceph.go
@@ -1987,7 +1987,6 @@ func (s *storageCeph) ContainerBackupCreate(backup backup, source container) err
 	if err != nil {
 		return err
 	}
-	defer os.RemoveAll(tmpPath)
 
 	// Generate the actual backup
 	if !backup.containerOnly {
diff --git a/lxd/storage_dir.go b/lxd/storage_dir.go
index 6fe7b3e5b1..0aa31ee9bd 100644
--- a/lxd/storage_dir.go
+++ b/lxd/storage_dir.go
@@ -1106,7 +1106,6 @@ func (s *storageDir) ContainerBackupCreate(backup backup, source container) erro
 	if err != nil {
 		return err
 	}
-	defer os.RemoveAll(tmpPath)
 
 	// Prepare for rsync
 	rsync := func(oldPath string, newPath string, bwlimit string) error {
diff --git a/lxd/storage_lvm.go b/lxd/storage_lvm.go
index cd1380894e..a1d529c04b 100644
--- a/lxd/storage_lvm.go
+++ b/lxd/storage_lvm.go
@@ -1690,7 +1690,6 @@ func (s *storageLvm) ContainerBackupCreate(backup backup, source container) erro
 	if err != nil {
 		return err
 	}
-	defer os.RemoveAll(tmpPath)
 
 	// Prepare for rsync
 	rsync := func(oldPath string, newPath string, bwlimit string) error {
diff --git a/lxd/storage_zfs.go b/lxd/storage_zfs.go
index 0c0f169f4b..318c607550 100644
--- a/lxd/storage_zfs.go
+++ b/lxd/storage_zfs.go
@@ -2136,7 +2136,6 @@ func (s *storageZfs) ContainerBackupCreate(backup backup, source container) erro
 	if err != nil {
 		return err
 	}
-	defer os.RemoveAll(tmpPath)
 
 	// Generate the actual backup
 	if backup.optimizedStorage {


More information about the lxc-devel mailing list