From 016636225824d5c2c1e6d71f08f42ec8507cce4c Mon Sep 17 00:00:00 2001 From: theguymadmax Date: Tue, 17 Feb 2026 22:56:45 -0500 Subject: [PATCH 1/2] Use BackupDatabase() instead of File.Move in library.db migration --- .../Migrations/Routines/MigrateLibraryDb.cs | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Jellyfin.Server/Migrations/Routines/MigrateLibraryDb.cs b/Jellyfin.Server/Migrations/Routines/MigrateLibraryDb.cs index 59b7e143c1..ce41c0ec55 100644 --- a/Jellyfin.Server/Migrations/Routines/MigrateLibraryDb.cs +++ b/Jellyfin.Server/Migrations/Routines/MigrateLibraryDb.cs @@ -465,7 +465,36 @@ internal class MigrateLibraryDb : IDatabaseMigrationRoutine SqliteConnection.ClearAllPools(); _logger.LogInformation("Move {0} to {1}.", libraryDbPath, libraryDbPath + ".old"); - File.Move(libraryDbPath, libraryDbPath + ".old", true); + var libraryDbBackupPath = libraryDbPath + ".old"; + + if (File.Exists(libraryDbBackupPath)) + { + File.Delete(libraryDbBackupPath); + } + + using (var source = new SqliteConnection($"Filename={libraryDbPath}")) + using (var destination = new SqliteConnection($"Filename={libraryDbBackupPath}")) + { + source.Open(); + destination.Open(); + source.BackupDatabase(destination); + } + + SqliteConnection.ClearAllPools(); + + File.Delete(libraryDbPath); + + var walPath = libraryDbPath + "-wal"; + if (File.Exists(walPath)) + { + File.Delete(walPath); + } + + var shmPath = libraryDbPath + "-shm"; + if (File.Exists(shmPath)) + { + File.Delete(shmPath); + } } private DatabaseMigrationStep GetPreparedDbContext(string operationName) From 5597d8e1a7f227e89dda121c72bea4877203f240 Mon Sep 17 00:00:00 2001 From: theguymadmax Date: Wed, 18 Feb 2026 15:11:21 -0500 Subject: [PATCH 2/2] Checkpoint wal --- .../Migrations/Routines/MigrateLibraryDb.cs | 33 ++++--------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/Jellyfin.Server/Migrations/Routines/MigrateLibraryDb.cs b/Jellyfin.Server/Migrations/Routines/MigrateLibraryDb.cs index ce41c0ec55..d48ab704f6 100644 --- a/Jellyfin.Server/Migrations/Routines/MigrateLibraryDb.cs +++ b/Jellyfin.Server/Migrations/Routines/MigrateLibraryDb.cs @@ -464,37 +464,18 @@ internal class MigrateLibraryDb : IDatabaseMigrationRoutine SqliteConnection.ClearAllPools(); - _logger.LogInformation("Move {0} to {1}.", libraryDbPath, libraryDbPath + ".old"); - var libraryDbBackupPath = libraryDbPath + ".old"; - - if (File.Exists(libraryDbBackupPath)) + using (var checkpointConnection = new SqliteConnection($"Filename={libraryDbPath}")) { - File.Delete(libraryDbBackupPath); - } - - using (var source = new SqliteConnection($"Filename={libraryDbPath}")) - using (var destination = new SqliteConnection($"Filename={libraryDbBackupPath}")) - { - source.Open(); - destination.Open(); - source.BackupDatabase(destination); + checkpointConnection.Open(); + using var cmd = checkpointConnection.CreateCommand(); + cmd.CommandText = "PRAGMA wal_checkpoint(TRUNCATE);"; + cmd.ExecuteNonQuery(); } SqliteConnection.ClearAllPools(); - File.Delete(libraryDbPath); - - var walPath = libraryDbPath + "-wal"; - if (File.Exists(walPath)) - { - File.Delete(walPath); - } - - var shmPath = libraryDbPath + "-shm"; - if (File.Exists(shmPath)) - { - File.Delete(shmPath); - } + _logger.LogInformation("Move {0} to {1}.", libraryDbPath, libraryDbPath + ".old"); + File.Move(libraryDbPath, libraryDbPath + ".old", true); } private DatabaseMigrationStep GetPreparedDbContext(string operationName)