From cd18b96f69a24fc7ea98306d6f5867c9694e0dd3 Mon Sep 17 00:00:00 2001 From: Matthew Nickson Date: Tue, 14 Feb 2023 16:43:40 +0000 Subject: [PATCH] Added check to ensure backup exists when restoring (#2779) A check to ensure that the backup database exists before deleting the current database. Fixes #2778 Signed-off-by: Matthew Nickson --- server/database.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/database.js b/server/database.js index 19c09a00f..449f16d55 100644 --- a/server/database.js +++ b/server/database.js @@ -496,6 +496,16 @@ class Database { const shmPath = Database.path + "-shm"; const walPath = Database.path + "-wal"; + // Make sure we have a backup to restore before deleting old db + if ( + !fs.existsSync(this.backupPath) + && !fs.existsSync(shmPath) + && !fs.existsSync(walPath) + ) { + log.error("db", "Backup file not found! Leaving database in failed state."); + process.exit(1); + } + // Delete patch failed db try { if (fs.existsSync(Database.path)) {