diff --git a/src/NzbDrone.Common/EnvironmentInfo/AppFolderFactory.cs b/src/NzbDrone.Common/EnvironmentInfo/AppFolderFactory.cs index e6833aca0..116c22eee 100644 --- a/src/NzbDrone.Common/EnvironmentInfo/AppFolderFactory.cs +++ b/src/NzbDrone.Common/EnvironmentInfo/AppFolderFactory.cs @@ -85,8 +85,7 @@ namespace NzbDrone.Common.EnvironmentInfo if (_diskProvider.FileExists(_appFolderInfo.GetDatabase())) return; if (!_diskProvider.FileExists(oldDbFile)) return; - _diskProvider.MoveFile(oldDbFile, _appFolderInfo.GetDatabase()); - CleanupSqLiteRollbackFiles(); + MoveSqliteDatabase(oldDbFile, _appFolderInfo.GetDatabase()); RemovePidFile(); } @@ -108,12 +107,9 @@ namespace NzbDrone.Common.EnvironmentInfo // Rename the DB file if (_diskProvider.FileExists(oldDbFile)) { - _diskProvider.MoveFile(oldDbFile, _appFolderInfo.GetDatabase()); + MoveSqliteDatabase(oldDbFile, _appFolderInfo.GetDatabase()); } - // Remove SQLite rollback files - CleanupSqLiteRollbackFiles(); - // Remove Old PID file RemovePidFile(); @@ -127,7 +123,6 @@ namespace NzbDrone.Common.EnvironmentInfo } } - private void InitializeMonoApplicationData() { if (OsInfo.IsWindows) return; @@ -158,12 +153,37 @@ namespace NzbDrone.Common.EnvironmentInfo } } - private void CleanupSqLiteRollbackFiles() + private void MoveSqliteDatabase(string source, string destination) { - _diskProvider.GetFiles(_appFolderInfo.AppDataFolder, SearchOption.TopDirectoryOnly) - .Where(f => Path.GetFileName(f).StartsWith("nzbdrone.db")) - .ToList() - .ForEach(_diskProvider.DeleteFile); + _logger.Info("Moving {0}* to {1}*", source, destination); + + var dbSuffixes = new[] { "", "-shm", "-wal", "-journal" }; + + foreach (var suffix in dbSuffixes) + { + var sourceFile = source + suffix; + var destFile = destination + suffix; + + if (_diskProvider.FileExists(destFile)) + { + _diskProvider.DeleteFile(destFile); + } + + if (_diskProvider.FileExists(sourceFile)) + { + _diskProvider.CopyFile(sourceFile, destFile); + } + } + + foreach (var suffix in dbSuffixes) + { + var sourceFile = source + suffix; + + if (_diskProvider.FileExists(sourceFile)) + { + _diskProvider.DeleteFile(sourceFile); + } + } } private void RemovePidFile() diff --git a/src/NzbDrone.Core/Datastore/Migration/Framework/MigrationController.cs b/src/NzbDrone.Core/Datastore/Migration/Framework/MigrationController.cs index 69d33e7e6..07fb25ee2 100644 --- a/src/NzbDrone.Core/Datastore/Migration/Framework/MigrationController.cs +++ b/src/NzbDrone.Core/Datastore/Migration/Framework/MigrationController.cs @@ -24,7 +24,7 @@ namespace NzbDrone.Core.Datastore.Migration.Framework { var sw = Stopwatch.StartNew(); - _announcer.Heading("Migrating " + connectionString); + _announcer.Heading("Checking database for required migrations " + connectionString); var assembly = Assembly.GetExecutingAssembly();