From 94f2473fbbb761a6d635b72db2c9aaaca1c04de2 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sat, 29 Jul 2017 20:27:34 +0200 Subject: [PATCH] Fixed: Backup fails after recent develop release on certain platforms. (Trouble updating? see github issue #2080) fixes #2080 --- .../Backup/MakeDatabaseBackup.cs | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/NzbDrone.Core/Backup/MakeDatabaseBackup.cs b/src/NzbDrone.Core/Backup/MakeDatabaseBackup.cs index 3beacac15..bafcd8232 100644 --- a/src/NzbDrone.Core/Backup/MakeDatabaseBackup.cs +++ b/src/NzbDrone.Core/Backup/MakeDatabaseBackup.cs @@ -30,6 +30,8 @@ namespace NzbDrone.Core.Backup var backupConnectionStringBuilder = new SQLiteConnectionStringBuilder(sourceConnectionString); backupConnectionStringBuilder.DataSource = Path.Combine(targetDirectory, Path.GetFileName(backupConnectionStringBuilder.DataSource)); + // We MUST use journal mode instead of WAL coz WAL has issues when page sizes change. This should also automatically deal with the -journal and -wal files during restore. + backupConnectionStringBuilder.JournalMode = SQLiteJournalModeEnum.Truncate; using (var sourceConnection = (SQLiteConnection)SQLiteFactory.Instance.CreateConnection()) using (var backupConnection = (SQLiteConnection)SQLiteFactory.Instance.CreateConnection()) @@ -42,23 +44,16 @@ namespace NzbDrone.Core.Backup sourceConnection.BackupDatabase(backupConnection, "main", "main", -1, null, 500); - // Make sure there are no lingering connections so the wal gets truncated. + // The backup changes the journal_mode, force it to truncate again. + using (var command = backupConnection.CreateCommand()) + { + command.CommandText = "pragma journal_mode=truncate"; + command.ExecuteNonQuery(); + } + + // Make sure there are no lingering connections. SQLiteConnection.ClearAllPools(); } - - var backupWalPath = backupConnectionStringBuilder.DataSource + "-wal"; - if (backupConnectionStringBuilder.JournalMode == SQLiteJournalModeEnum.Wal && !File.Exists(backupWalPath)) - { - // Make sure the wal gets created in the backup so users are less likely to make an error during restore. - File.WriteAllBytes(backupWalPath, new byte[0]); - } - - var backupJournalPath = backupConnectionStringBuilder.DataSource + "-journal"; - if (backupConnectionStringBuilder.JournalMode != SQLiteJournalModeEnum.Wal && !File.Exists(backupJournalPath)) - { - // Make sure the journal gets created in the backup so users are less likely to make an error during restore. - File.WriteAllBytes(backupJournalPath, new byte[0]); - } } } }