[lxc-devel] [lxd/master] Make a database backup on schema updates

stgraber on Github lxc-bot at linuxcontainers.org
Fri Aug 26 20:22:32 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160826/6f38b632/attachment.bin>
-------------- next part --------------
From efad6b50fa3e9291cabf149a1ec951e5d48ff35a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 26 Aug 2016 16:21:57 -0400
Subject: [PATCH] Make a database backup on schema updates
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #2299

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/db_update.go | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/lxd/db_update.go b/lxd/db_update.go
index b3c6894..a5ea755 100644
--- a/lxd/db_update.go
+++ b/lxd/db_update.go
@@ -95,11 +95,22 @@ func (u *dbUpdate) apply(currentVersion int, d *Daemon) error {
 func dbUpdatesApplyAll(d *Daemon) error {
 	currentVersion := dbGetSchema(d.db)
 
+	backup := false
 	for _, update := range dbUpdates {
 		if update.version <= currentVersion {
 			continue
 		}
 
+		if !backup {
+			shared.Log.Info("Updating the LXD database schema. Backup made as \"lxd.db.bak\"")
+			err := shared.FileCopy(shared.VarPath("lxd.db"), shared.VarPath("lxd.db.bak"))
+			if err != nil {
+				return err
+			}
+
+			backup = true
+		}
+
 		err := update.apply(currentVersion, d)
 		if err != nil {
 			return err


More information about the lxc-devel mailing list