Fixed: Backup fails on certain platforms

This commit is contained in:
Qstick 2017-10-29 00:10:27 -04:00
parent 272adfcef7
commit 64d58a2248
1 changed files with 10 additions and 15 deletions

View File

@ -30,6 +30,8 @@ namespace NzbDrone.Core.Backup
var backupConnectionStringBuilder = new SQLiteConnectionStringBuilder(sourceConnectionString); var backupConnectionStringBuilder = new SQLiteConnectionStringBuilder(sourceConnectionString);
backupConnectionStringBuilder.DataSource = Path.Combine(targetDirectory, Path.GetFileName(backupConnectionStringBuilder.DataSource)); 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 sourceConnection = (SQLiteConnection)SQLiteFactory.Instance.CreateConnection())
using (var backupConnection = (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); 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(); 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]);
}
} }
} }
} }