Jump to content

Windows to Linux Server Migration Resulted in Broken Images


Recommended Posts

tech37
Posted (edited)

I used the Backup & Restore plugin to make a full backup of my Windows server, created a fresh Emby install on TrueNAS Scale as a docker container, added my premium license, and restored from the backup. 

All the data is there now, and I manually corrected my cache path and transcoding paths, however all the media and user profile picture images are broken.

When I try to browse to an image directly at a URL like http://192.168.2.166:9096/emby/Users/e9a10d8f74b049798582d53a07b0c291/Images/Primary?height=250&tag=ad49a54efc9ad629fcd5a58963f74cfb&quality=90 , I get error:

The file '/var/run/s6/services/emby-server/C:\Users\coulter\AppData\Roaming\Emby-Server\programdata\config\users\e9a10d8f74b049798582d53a07b0c291\poster.png' cound not be found.

Which makes me thing the database has some wonky paths that are merging the old windows paths with the new linux environment. I did shell into the container and found that /config/config/users/e9a10d8f74b049798582d53a07b0c291/poster.png does exist, so maybe the files copied correctly but the database update had an issue?

What's the best way to fix this? I could probably dump the database and do a series of find/replaces, but that feels pretty dicey.

Bonus/related question: is manually removing the Windows path/adding the Linux path for each library and re-scanning the best practice, or is there a slicker find/replace for that as well? Trying to minimise the amount of re-fixing metadata that's needed.

Thanks in advance!

Edited by tech37
tech37
Posted (edited)

Not pretty but came up with this fix:

  • Shutdown the emby docker container
  • SSH into the Emby data folder (in my case `/mnt/.ix-apps/app_mounts/emby/config/data`)
  • scp copy down the library.db and users.db files to my local machine
  • Fire up DB Browser for SQLite and open users.db and library.db files (after making a backup copy)
  • Run the below SQL commands to find/replace the windows paths with your Linux paths (adjust as necessary):
/* users.db */
UPDATE LocalUsersv2
SET data = REPLACE(
                REPLACE(
                    data, 
                    'C:\\Users\\coulter\\AppData\\Roaming\\Emby-Server\\programdata\\config\\users\\', 
                    'config/config/users/'
                ), 
                '\\', 
                '/'
            )
WHERE data LIKE '%C:\\Users\\coulter\\AppData\\Roaming\\Emby-Server%';

 

/* library.db */
UPDATE MediaItems
SET Path = REPLACE(
                REPLACE(
                    Path, 
                    'F:\media', 
                    '/media'
                ), 
                '\', 
                '/'
            )
WHERE Path LIKE '%F:\media%';

 

/* library.db */
UPDATE ItemExtradata
SET Value = REPLACE(
                REPLACE(
                    Value, 
                    'F:\\media', 
                    '/media'
                ), 
                '\\', 
                '/'
            )
WHERE Value LIKE '%F:\\media%';

 

/* library.db */
UPDATE MediaItems
SET Images = REPLACE(
                    Images, 
                    '\', 
					'/'
                ) 
WHERE Images LIKE '%MetadataPath%';

 

  • Write those changes back to the DB files, then scp them up to your home directory on your linux machine (in my case my truenas scale box)
  • For each file, run this series of commands:
    • sudo cp /mnt/.ix-apps/app_mounts/emby/config/data/library.db /mnt/.ix-apps/app_mounts/emby/config/data/library.bak.db 
    • sudo cp ~/library.db /mnt/.ix-apps/app_mounts/emby/config/data/library.db
    • sudo chown apps:apps /mnt/.ix-apps/app_mounts/emby/config/data/library.db (or whatever your emby user name/group is)
    • sudo chmod 755 /mnt/.ix-apps/app_mounts/emby/config/data/library.db
    • * Repeat for users.db *
  • Boot up the Emby container and you should see images and corrected file paths again.
  • Re-scan libraries

@Luke hope this maybe helps with the logic for the future backup/restore features I saw you mentioned for switching platforms

Edited by tech37
  • Like 1
Neminem
Posted

Jep migration of Emby server is still not supported when switching between OS's like windows to linux.

Do to differences in OS path's.

But cool you found a solution 😉

Happy2Play
Posted

Yes there are several topics on this where manual db updates for effected paths works

As there are several areas to look depending on your overall setup.

Posted in other topics as areas I have found.

UPDATE "main"."MediaItems" SET "Path" = replace( "Path", 'C:\Users\Media\Desktop\Videos', 'E:\Media' ) WHERE path LIKE 'C:\Users\Media\Desktop\Videos%';
UPDATE "main"."MediaItems" SET "Images" = replace( "Images", 'C:\Users\Media\Desktop\Videos', 'E:\Media' ) WHERE Images LIKE 'C:\Users\Media\Desktop\Videos%';
UPDATE "main"."MediaStreams2" SET "Path" = replace( "Path", 'C:\Users\Media\Desktop\Videos', 'E:\Media' ) WHERE path LIKE 'C:\Users\Media\Desktop\Videos%';
UPDATE "main"."Chapters3" SET "ImagePath" = replace( "ImagePath", 'C:\Users\Media\Desktop\Videos', 'E:\Media' ) WHERE imagepath LIKE 'C:\Users\Media\Desktop\Videos%';
UPDATE "main"."ItemExtradata" SET "Value" = replace( "Value", '"Path":"C:\\Users\\Media\\Desktop\\Videos', '"Path":"E:\\Media' ) WHERE value LIKE '%"Path":"C:\\Users\\Media\\Desktop\\Videos%';

If you filled in Network path on Library setup you will could need to update in options.xml and itemextradata. xml is obsolete in new 4.8+
Cinema Intro plugin paths
If you use AutoOrganizer you will need to update or delete the fileorganization.db
If you applied user images then path will need updated users.db

 

tech37
Posted

@Happy2Playthanks glad to hear I'm on the right track!

Been testing my updated db for a bit, and after rescanning library files it seems like most libraries will play fine, but one will decide to throw a sqlite error (and it seems to change as I re-copy over the updated db). This is the error I get:

2025-03-04 13:03:23.618 Error Server: Error processing request
        *** Error Report ***
        Version: 4.8.10.0
        Command line: /system/EmbyServer.dll -programdata /config -ffdetect /bin/ffdetect -ffmpeg /bin/ffmpeg -ffprobe /bin/ffprobe -restartexitcode 3
        Operating system: Linux version 6.6.44-production+truenas (root@tnsbuilds01.tn.ixsystems.net) (gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40) #1
        Framework: .NET 6.0.31
        OS/Process: x64/x64
        Runtime: system/System.Private.CoreLib.dll
        Processor count: 4
        Data path: /config
        Application path: /system
        SQLitePCL.pretty.SQLiteException: Corrupt: database disk image is malformed
        SQLitePCL.pretty.SQLiteException: Exception of type 'SQLitePCL.pretty.SQLiteException' was thrown.
           at SQLitePCL.pretty.SQLiteException.CheckOk(sqlite3 db, Int32 rc)
           at SQLitePCL.pretty.StatementImpl.MoveNext()
           at Emby.Sqlite.SqliteExtensions.ExecuteQuery(IStatement This)+MoveNext()
           at Emby.Server.Implementations.Data.SqliteItemRepository.QueryItemsInTransaction[T](InternalItemsQuery query, IDatabaseConnection db, String[] columnsToSelect, Boolean filterColumns, String[] groupBy, Func`5 rowReaderFn, String methodName)
           at Emby.Server.Implementations.Data.SqliteItemRepository.GetItemList(InternalItemsQuery query)
           at Emby.Server.Implementations.Library.LibraryManager.GetItemsResult(InternalItemsQuery query)
           at Emby.Server.Implementations.TV.TVSeriesManager.GetNextUpEpisodes(User user, Series series, Nullable`1 startIndex, Nullable`1 limit, Boolean enableTotalRecordCount, BaseItem[] ancestors, DtoOptions dtoOptions, Int64 notSyncedToTargetId)
           at Emby.Server.Implementations.TV.TVSeriesManager.GetNextUp(NextUpQuery request, User user, DtoOptions dtoOptions)
           at Emby.Api.TvShowsService.Get(GetNextUpEpisodes request)
           at Emby.Server.Implementations.Services.ServiceController.Execute(HttpListenerHost appHost, Object requestDto, IRequest req, Type serviceType)
           at Emby.Server.Implementations.Services.ServiceHandler.ProcessRequestAsync(HttpListenerHost httpHost, IServerApplicationHost appHost, IRequest httpReq, IResponse httpRes, IStreamHelper streamHelper, RestPath restPath, String responseContentType, CancellationToken cancellationToken)
           at Emby.Server.Implementations.HttpServer.HttpListenerHost.RequestHandler(IRequest httpReq, ReadOnlyMemory`1 urlString, ReadOnlyMemory`1 localPath, CancellationToken cancellationToken)
        Source: SQLitePCL.pretty
        TargetSite: Void CheckOk(SQLitePCLEx.sqlite3, Int32)

Can anyone spot in my SQL update commands why my library.db might be getting malformed?

Posted

Hi, please take a look at this and let us know if it helps:

Corrupt Database

tech37
Posted

Thanks Luke!

Some trial and error but this process appears to have healed my library.db:

  • Shutdown emby docker container
  • Fresh copy of my bulk-find-replaced db into the emby data folder
  • Started emby container, checked 'vacuum on next reboot', restarted emby, then let it scan all libraries
  • Shutdown emby container
  • `sqlite3 library.db "PRAGMA integrity_check"` ran fine, however `sqlite3 library.db ".recover" | sqlite3 library-recovered.db` gave errors like other attempts, so I rebuilt the db this way:
    • `sqlite3 library.db ".dump" > dump.sql`
    • Confirmed dump.sql had actual SQL instructions in it and not errors
    • `sudo sqlite3 new-library.db < dump.sql`
    • No errors, so I copied new-library.db to library.db in the data folder
  • Started up Emby docker container and all libraries were able to play fine now

@Lukemaybe the ".dump" steps should be added to the Corrupt Database doc as a last resort before the "Steps to Reset Library Database & Load Fresh" step?

  • Thanks 1
tech37
Posted

Bonus note to anyone else in my scenario: If you're making copies of your library.db file for purposes of rebuilding or backing up, be sure to move them out of your data directory, as they may get picked up by emby 😅

  • Thanks 1
Posted
4 hours ago, tech37 said:

Thanks Luke!

Some trial and error but this process appears to have healed my library.db:

  • Shutdown emby docker container
  • Fresh copy of my bulk-find-replaced db into the emby data folder
  • Started emby container, checked 'vacuum on next reboot', restarted emby, then let it scan all libraries
  • Shutdown emby container
  • `sqlite3 library.db "PRAGMA integrity_check"` ran fine, however `sqlite3 library.db ".recover" | sqlite3 library-recovered.db` gave errors like other attempts, so I rebuilt the db this way:
    • `sqlite3 library.db ".dump" > dump.sql`
    • Confirmed dump.sql had actual SQL instructions in it and not errors
    • `sudo sqlite3 new-library.db < dump.sql`
    • No errors, so I copied new-library.db to library.db in the data folder
  • Started up Emby docker container and all libraries were able to play fine now

@Lukemaybe the ".dump" steps should be added to the Corrupt Database doc as a last resort before the "Steps to Reset Library Database & Load Fresh" step?

HI, yes we can take a look at that. Thanks.

 

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...