< Summary - Jellyfin

Information
Class: Jellyfin.Server.Implementations.FullSystemBackup.BackupService
Assembly: Jellyfin.Server.Implementations
File(s): /srv/git/jellyfin/Jellyfin.Server.Implementations/FullSystemBackup/BackupService.cs
Line coverage
16%
Covered lines: 8
Uncovered lines: 40
Coverable lines: 48
Total lines: 577
Line coverage: 16.6%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 12/28/2025 - 12:10:13 AM Line coverage: 16.6% (8/48) Branch coverage: 0% (0/2) Total lines: 5591/19/2026 - 12:13:54 AM Line coverage: 16.6% (8/48) Branch coverage: 0% (0/2) Total lines: 5603/31/2026 - 12:14:24 AM Line coverage: 16.6% (8/48) Branch coverage: 0% (0/2) Total lines: 577 12/28/2025 - 12:10:13 AM Line coverage: 16.6% (8/48) Branch coverage: 0% (0/2) Total lines: 5591/19/2026 - 12:13:54 AM Line coverage: 16.6% (8/48) Branch coverage: 0% (0/2) Total lines: 5603/31/2026 - 12:14:24 AM Line coverage: 16.6% (8/48) Branch coverage: 0% (0/2) Total lines: 577

Coverage delta

Coverage delta 1 -1

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%210%
.ctor(...)100%11100%
ScheduleRestoreAndRestartServer(...)100%210%
TestBackupVersionCompatibility(...)0%620%
Map(...)100%210%
Map(...)100%210%
Map(...)100%210%
NormalizePathSeparator(...)100%210%

File(s)

/srv/git/jellyfin/Jellyfin.Server.Implementations/FullSystemBackup/BackupService.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.IO;
 4using System.IO.Compression;
 5using System.Linq;
 6using System.Text.Json;
 7using System.Text.Json.Nodes;
 8using System.Text.Json.Serialization;
 9using System.Threading;
 10using System.Threading.Tasks;
 11using Jellyfin.Database.Implementations;
 12using Jellyfin.Server.Implementations.StorageHelpers;
 13using Jellyfin.Server.Implementations.SystemBackupService;
 14using MediaBrowser.Controller;
 15using MediaBrowser.Controller.SystemBackupService;
 16using Microsoft.EntityFrameworkCore;
 17using Microsoft.EntityFrameworkCore.Infrastructure;
 18using Microsoft.EntityFrameworkCore.Migrations;
 19using Microsoft.Extensions.Hosting;
 20using Microsoft.Extensions.Logging;
 21
 22namespace Jellyfin.Server.Implementations.FullSystemBackup;
 23
 24/// <summary>
 25/// Contains methods for creating and restoring backups.
 26/// </summary>
 27public class BackupService : IBackupService
 28{
 29    private const string ManifestEntryName = "manifest.json";
 30    private readonly ILogger<BackupService> _logger;
 31    private readonly IDbContextFactory<JellyfinDbContext> _dbProvider;
 32    private readonly IServerApplicationHost _applicationHost;
 33    private readonly IServerApplicationPaths _applicationPaths;
 34    private readonly IJellyfinDatabaseProvider _jellyfinDatabaseProvider;
 35    private readonly IHostApplicationLifetime _hostApplicationLifetime;
 036    private static readonly JsonSerializerOptions _serializerSettings = new JsonSerializerOptions(JsonSerializerDefaults
 037    {
 038        AllowTrailingCommas = true,
 039        ReferenceHandler = ReferenceHandler.IgnoreCycles,
 040    };
 41
 2142    private readonly Version _backupEngineVersion = new Version(0, 2, 0);
 43
 44    /// <summary>
 45    /// Initializes a new instance of the <see cref="BackupService"/> class.
 46    /// </summary>
 47    /// <param name="logger">A logger.</param>
 48    /// <param name="dbProvider">A Database Factory.</param>
 49    /// <param name="applicationHost">The Application host.</param>
 50    /// <param name="applicationPaths">The application paths.</param>
 51    /// <param name="jellyfinDatabaseProvider">The Jellyfin database Provider in use.</param>
 52    /// <param name="applicationLifetime">The SystemManager.</param>
 53    public BackupService(
 54        ILogger<BackupService> logger,
 55        IDbContextFactory<JellyfinDbContext> dbProvider,
 56        IServerApplicationHost applicationHost,
 57        IServerApplicationPaths applicationPaths,
 58        IJellyfinDatabaseProvider jellyfinDatabaseProvider,
 59        IHostApplicationLifetime applicationLifetime)
 60    {
 2161        _logger = logger;
 2162        _dbProvider = dbProvider;
 2163        _applicationHost = applicationHost;
 2164        _applicationPaths = applicationPaths;
 2165        _jellyfinDatabaseProvider = jellyfinDatabaseProvider;
 2166        _hostApplicationLifetime = applicationLifetime;
 2167    }
 68
 69    /// <inheritdoc/>
 70    public void ScheduleRestoreAndRestartServer(string archivePath)
 71    {
 072        _applicationHost.RestoreBackupPath = archivePath;
 073        _applicationHost.ShouldRestart = true;
 074        _applicationHost.NotifyPendingRestart();
 075        _ = Task.Run(async () =>
 076        {
 077            await Task.Delay(500).ConfigureAwait(false);
 078            _hostApplicationLifetime.StopApplication();
 079        });
 080    }
 81
 82    /// <inheritdoc/>
 83    public async Task RestoreBackupAsync(string archivePath)
 84    {
 85        _logger.LogWarning("Begin restoring system to {BackupArchive}", archivePath); // Info isn't cutting it
 86        if (!File.Exists(archivePath))
 87        {
 88            throw new FileNotFoundException($"Requested backup file '{archivePath}' does not exist.");
 89        }
 90
 91        StorageHelper.TestCommonPathsForStorageCapacity(_applicationPaths, _logger);
 92
 93        var fileStream = File.OpenRead(archivePath);
 94        await using (fileStream.ConfigureAwait(false))
 95        {
 96            using var zipArchive = new ZipArchive(fileStream, ZipArchiveMode.Read, false);
 97            var zipArchiveEntry = zipArchive.GetEntry(ManifestEntryName);
 98
 99            if (zipArchiveEntry is null)
 100            {
 101                throw new NotSupportedException($"The loaded archive '{archivePath}' does not appear to be a Jellyfin ba
 102            }
 103
 104            BackupManifest? manifest;
 105            var manifestStream = await zipArchiveEntry.OpenAsync().ConfigureAwait(false);
 106            await using (manifestStream.ConfigureAwait(false))
 107            {
 108                manifest = await JsonSerializer.DeserializeAsync<BackupManifest>(manifestStream, _serializerSettings).Co
 109            }
 110
 111            if (manifest!.ServerVersion > _applicationHost.ApplicationVersion) // newer versions of Jellyfin should be a
 112            {
 113                throw new NotSupportedException($"The loaded archive '{archivePath}' is made for a newer version of Jell
 114            }
 115
 116            if (!TestBackupVersionCompatibility(manifest.BackupEngineVersion))
 117            {
 118                throw new NotSupportedException($"The loaded archive '{archivePath}' is made for a newer version of Jell
 119            }
 120
 121            void CopyDirectory(string source, string target, string[]? exclude = null)
 122            {
 123                var fullSourcePath = NormalizePathSeparator(Path.GetFullPath(source) + Path.DirectorySeparatorChar);
 124                var fullTargetRoot = Path.GetFullPath(target) + Path.DirectorySeparatorChar;
 125                var excludePaths = exclude?.Select(e => $"{source}/{e}/").ToArray();
 126                foreach (var item in zipArchive.Entries)
 127                {
 128                    var sourcePath = NormalizePathSeparator(Path.GetFullPath(item.FullName));
 129                    var targetPath = Path.GetFullPath(Path.Combine(target, Path.GetRelativePath(source, item.FullName)))
 130
 131                    if (excludePaths is not null && excludePaths.Any(e => item.FullName.StartsWith(e, StringComparison.O
 132                    {
 133                        continue;
 134                    }
 135
 136                    if (!sourcePath.StartsWith(fullSourcePath, StringComparison.Ordinal)
 137                        || !targetPath.StartsWith(fullTargetRoot, StringComparison.Ordinal)
 138                        || Path.EndsInDirectorySeparator(item.FullName))
 139                    {
 140                        continue;
 141                    }
 142
 143                    _logger.LogInformation("Restore and override {File}", targetPath);
 144
 145                    Directory.CreateDirectory(Path.GetDirectoryName(targetPath)!);
 146                    item.ExtractToFile(targetPath, overwrite: true);
 147                }
 148            }
 149
 150            CopyDirectory("Config", _applicationPaths.ConfigurationDirectoryPath);
 151            CopyDirectory("Data", _applicationPaths.DataPath, exclude: ["metadata", "metadata-default"]);
 152            CopyDirectory("Root", _applicationPaths.RootFolderPath);
 153            CopyDirectory("Data/metadata", _applicationPaths.InternalMetadataPath);
 154            CopyDirectory("Data/metadata-default", _applicationPaths.DefaultInternalMetadataPath);
 155
 156            if (manifest.Options.Database)
 157            {
 158                _logger.LogInformation("Begin restoring Database");
 159                var dbContext = await _dbProvider.CreateDbContextAsync().ConfigureAwait(false);
 160                await using (dbContext.ConfigureAwait(false))
 161                {
 162                    // restore migration history manually
 163                    var historyEntry = zipArchive.GetEntry(NormalizePathSeparator(Path.Combine("Database", $"{nameof(His
 164                    if (historyEntry is null)
 165                    {
 166                        _logger.LogInformation("No backup of the history table in archive. This is required for Jellyfin
 167                        throw new InvalidOperationException("Cannot restore backup that has no History data.");
 168                    }
 169
 170                    HistoryRow[] historyEntries;
 171                    var historyArchive = await historyEntry.OpenAsync().ConfigureAwait(false);
 172                    await using (historyArchive.ConfigureAwait(false))
 173                    {
 174                        historyEntries = await JsonSerializer.DeserializeAsync<HistoryRow[]>(historyArchive).ConfigureAw
 175                            throw new InvalidOperationException("Cannot restore backup that has no History data.");
 176                    }
 177
 178                    var historyRepository = dbContext.GetService<IHistoryRepository>();
 179                    await historyRepository.CreateIfNotExistsAsync().ConfigureAwait(false);
 180
 181                    foreach (var item in await historyRepository.GetAppliedMigrationsAsync(CancellationToken.None).Confi
 182                    {
 183                        var insertScript = historyRepository.GetDeleteScript(item.MigrationId);
 184                        await dbContext.Database.ExecuteSqlRawAsync(insertScript).ConfigureAwait(false);
 185                    }
 186
 187                    foreach (var item in historyEntries)
 188                    {
 189                        var insertScript = historyRepository.GetInsertScript(item);
 190                        await dbContext.Database.ExecuteSqlRawAsync(insertScript).ConfigureAwait(false);
 191                    }
 192
 193                    dbContext.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
 194                    var entityTypes = typeof(JellyfinDbContext).GetProperties(System.Reflection.BindingFlags.Public | Sy
 195                        .Where(e => e.PropertyType.IsAssignableTo(typeof(IQueryable)))
 196                        .Select(e => (Type: e, Set: e.GetValue(dbContext) as IQueryable))
 197                        .ToArray();
 198
 199                    var tableNames = entityTypes.Select(f => dbContext.Model.FindEntityType(f.Type.PropertyType.GetGener
 200                    _logger.LogInformation("Begin purging database");
 201                    await _jellyfinDatabaseProvider.PurgeDatabase(dbContext, tableNames).ConfigureAwait(false);
 202                    _logger.LogInformation("Database Purged");
 203
 204                    foreach (var entityType in entityTypes)
 205                    {
 206                        _logger.LogInformation("Read backup of {Table}", entityType.Type.Name);
 207
 208                        var zipEntry = zipArchive.GetEntry(NormalizePathSeparator(Path.Combine("Database", $"{entityType
 209                        if (zipEntry is null)
 210                        {
 211                            _logger.LogInformation("No backup of expected table {Table} is present in backup, continuing
 212                            continue;
 213                        }
 214
 215                        var zipEntryStream = await zipEntry.OpenAsync().ConfigureAwait(false);
 216                        await using (zipEntryStream.ConfigureAwait(false))
 217                        {
 218                            _logger.LogInformation("Restore backup of {Table}", entityType.Type.Name);
 219                            var records = 0;
 220                            await foreach (var item in JsonSerializer.DeserializeAsyncEnumerable<JsonObject>(zipEntryStr
 221                            {
 222                                var entity = item.Deserialize(entityType.Type.PropertyType.GetGenericArguments()[0]);
 223                                if (entity is null)
 224                                {
 225                                    throw new InvalidOperationException($"Cannot deserialize entity '{item}'");
 226                                }
 227
 228                                try
 229                                {
 230                                    records++;
 231                                    dbContext.Add(entity);
 232                                }
 233                                catch (Exception ex)
 234                                {
 235                                    _logger.LogError(ex, "Could not store entity {Entity}, continuing anyway", item);
 236                                }
 237                            }
 238
 239                            _logger.LogInformation("Prepared to restore {Number} entries for {Table}", records, entityTy
 240                        }
 241                    }
 242
 243                    _logger.LogInformation("Try restore Database");
 244                    await dbContext.SaveChangesAsync().ConfigureAwait(false);
 245                    _logger.LogInformation("Restored database");
 246                }
 247            }
 248
 249            _logger.LogInformation("Restored Jellyfin system from {Date}", manifest.DateCreated);
 250        }
 251    }
 252
 253    private bool TestBackupVersionCompatibility(Version backupEngineVersion)
 254    {
 0255        if (backupEngineVersion == _backupEngineVersion)
 256        {
 0257            return true;
 258        }
 259
 0260        return false;
 261    }
 262
 263    /// <inheritdoc/>
 264    public async Task<BackupManifestDto> CreateBackupAsync(BackupOptionsDto backupOptions)
 265    {
 266        var manifest = new BackupManifest()
 267        {
 268            DateCreated = DateTime.UtcNow,
 269            ServerVersion = _applicationHost.ApplicationVersion,
 270            DatabaseTables = null!,
 271            BackupEngineVersion = _backupEngineVersion,
 272            Options = Map(backupOptions)
 273        };
 274
 275        _logger.LogInformation("Running database optimization before backup");
 276
 277        await _jellyfinDatabaseProvider.RunScheduledOptimisation(CancellationToken.None).ConfigureAwait(false);
 278
 279        var backupFolder = Path.Combine(_applicationPaths.BackupPath);
 280
 281        if (!Directory.Exists(backupFolder))
 282        {
 283            Directory.CreateDirectory(backupFolder);
 284        }
 285
 286        var backupStorageSpace = StorageHelper.GetFreeSpaceOf(_applicationPaths.BackupPath);
 287
 288        const long FiveGigabyte = 5_368_709_115;
 289        if (backupStorageSpace.FreeSpace < FiveGigabyte)
 290        {
 291            throw new InvalidOperationException($"The backup directory '{backupStorageSpace.Path}' does not have at leas
 292        }
 293
 294        var backupPath = Path.Combine(backupFolder, $"jellyfin-backup-{manifest.DateCreated.ToLocalTime():yyyyMMddHHmmss
 295
 296        try
 297        {
 298            _logger.LogInformation("Attempting to create a new backup at {BackupPath}", backupPath);
 299            var fileStream = File.OpenWrite(backupPath);
 300            await using (fileStream.ConfigureAwait(false))
 301            using (var zipArchive = new ZipArchive(fileStream, ZipArchiveMode.Create, false))
 302            {
 303                _logger.LogInformation("Starting backup process");
 304                var dbContext = await _dbProvider.CreateDbContextAsync().ConfigureAwait(false);
 305                await using (dbContext.ConfigureAwait(false))
 306                {
 307                    dbContext.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
 308
 309                    static IAsyncEnumerable<object> GetValues(IQueryable dbSet)
 310                    {
 311                        var method = dbSet.GetType().GetMethod(nameof(DbSet<object>.AsAsyncEnumerable))!;
 312                        var enumerable = method.Invoke(dbSet, null)!;
 313                        return (IAsyncEnumerable<object>)enumerable;
 314                    }
 315
 316                    // include the migration history as well
 317                    var historyRepository = dbContext.GetService<IHistoryRepository>();
 318                    var migrations = await historyRepository.GetAppliedMigrationsAsync().ConfigureAwait(false);
 319
 320                    ICollection<(Type Type, string SourceName, Func<IAsyncEnumerable<object>> ValueFactory)> entityTypes
 321                    [
 322                        .. typeof(JellyfinDbContext)
 323                            .GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instan
 324                            .Where(e => e.PropertyType.IsAssignableTo(typeof(IQueryable)))
 325                            .Select(e => (Type: e.PropertyType, dbContext.Model.FindEntityType(e.PropertyType.GetGeneric
 326                        (Type: typeof(HistoryRow), SourceName: nameof(HistoryRow), ValueFactory: () => migrations.ToAsyn
 327                    ];
 328                    manifest.DatabaseTables = entityTypes.Select(e => e.Type.Name).ToArray();
 329                    var transaction = await dbContext.Database.BeginTransactionAsync().ConfigureAwait(false);
 330
 331                    await using (transaction.ConfigureAwait(false))
 332                    {
 333                        _logger.LogInformation("Begin Database backup");
 334
 335                        foreach (var entityType in entityTypes)
 336                        {
 337                            _logger.LogInformation("Begin backup of entity {Table}", entityType.SourceName);
 338                            var zipEntry = zipArchive.CreateEntry(NormalizePathSeparator(Path.Combine("Database", $"{ent
 339                            var entities = 0;
 340                            var zipEntryStream = await zipEntry.OpenAsync().ConfigureAwait(false);
 341                            await using (zipEntryStream.ConfigureAwait(false))
 342                            {
 343                                var jsonSerializer = new Utf8JsonWriter(zipEntryStream);
 344                                await using (jsonSerializer.ConfigureAwait(false))
 345                                {
 346                                    jsonSerializer.WriteStartArray();
 347
 348                                    var set = entityType.ValueFactory().ConfigureAwait(false);
 349                                    await foreach (var item in set.ConfigureAwait(false))
 350                                    {
 351                                        entities++;
 352                                        try
 353                                        {
 354                                            using var document = JsonSerializer.SerializeToDocument(item, _serializerSet
 355                                            document.WriteTo(jsonSerializer);
 356                                        }
 357                                        catch (Exception ex)
 358                                        {
 359                                            _logger.LogError(ex, "Could not load entity {Entity}", item);
 360                                            throw;
 361                                        }
 362                                    }
 363
 364                                    jsonSerializer.WriteEndArray();
 365                                }
 366                            }
 367
 368                            _logger.LogInformation("Backup of entity {Table} with {Number} created", entityType.SourceNa
 369                        }
 370                    }
 371                }
 372
 373                _logger.LogInformation("Backup of folder {Table}", _applicationPaths.ConfigurationDirectoryPath);
 374                foreach (var item in Directory.EnumerateFiles(_applicationPaths.ConfigurationDirectoryPath, "*.xml", Sea
 375                             .Union(Directory.EnumerateFiles(_applicationPaths.ConfigurationDirectoryPath, "*.json", Sea
 376                {
 377                    await zipArchive.CreateEntryFromFileAsync(item, NormalizePathSeparator(Path.Combine("Config", Path.G
 378                }
 379
 380                void CopyDirectory(string source, string target, string filter = "*")
 381                {
 382                    if (!Directory.Exists(source))
 383                    {
 384                        return;
 385                    }
 386
 387                    _logger.LogInformation("Backup of folder {Table}", source);
 388
 389                    foreach (var item in Directory.EnumerateFiles(source, filter, SearchOption.AllDirectories))
 390                    {
 391                        // TODO: @bond make async
 392                        zipArchive.CreateEntryFromFile(item, NormalizePathSeparator(Path.Combine(target, Path.GetRelativ
 393                    }
 394                }
 395
 396                CopyDirectory(Path.Combine(_applicationPaths.ConfigurationDirectoryPath, "users"), Path.Combine("Config"
 397                CopyDirectory(Path.Combine(_applicationPaths.ConfigurationDirectoryPath, "ScheduledTasks"), Path.Combine
 398                CopyDirectory(Path.Combine(_applicationPaths.RootFolderPath), "Root");
 399                CopyDirectory(Path.Combine(_applicationPaths.DataPath, "collections"), Path.Combine("Data", "collections
 400                CopyDirectory(Path.Combine(_applicationPaths.DataPath, "playlists"), Path.Combine("Data", "playlists"));
 401                CopyDirectory(Path.Combine(_applicationPaths.DataPath, "ScheduledTasks"), Path.Combine("Data", "Schedule
 402                if (backupOptions.Subtitles)
 403                {
 404                    CopyDirectory(Path.Combine(_applicationPaths.DataPath, "subtitles"), Path.Combine("Data", "subtitles
 405                }
 406
 407                if (backupOptions.Trickplay)
 408                {
 409                    CopyDirectory(Path.Combine(_applicationPaths.DataPath, "trickplay"), Path.Combine("Data", "trickplay
 410                }
 411
 412                if (backupOptions.Metadata)
 413                {
 414                    CopyDirectory(Path.Combine(_applicationPaths.InternalMetadataPath), Path.Combine("Data", "metadata")
 415
 416                    // If a custom metadata path is configured, the default location may still contain data.
 417                    if (!string.Equals(
 418                            Path.GetFullPath(_applicationPaths.DefaultInternalMetadataPath),
 419                            Path.GetFullPath(_applicationPaths.InternalMetadataPath),
 420                            StringComparison.OrdinalIgnoreCase))
 421                    {
 422                        CopyDirectory(Path.Combine(_applicationPaths.DefaultInternalMetadataPath), Path.Combine("Data", 
 423                    }
 424                }
 425
 426                var manifestStream = await zipArchive.CreateEntry(ManifestEntryName).OpenAsync().ConfigureAwait(false);
 427                await using (manifestStream.ConfigureAwait(false))
 428                {
 429                    await JsonSerializer.SerializeAsync(manifestStream, manifest).ConfigureAwait(false);
 430                }
 431            }
 432
 433            _logger.LogInformation("Backup created");
 434            return Map(manifest, backupPath);
 435        }
 436        catch (Exception ex)
 437        {
 438            _logger.LogError(ex, "Failed to create backup, removing {BackupPath}", backupPath);
 439            try
 440            {
 441                if (File.Exists(backupPath))
 442                {
 443                    File.Delete(backupPath);
 444                }
 445            }
 446            catch (Exception innerEx)
 447            {
 448                _logger.LogWarning(innerEx, "Unable to remove failed backup");
 449            }
 450
 451            throw;
 452        }
 453    }
 454
 455    /// <inheritdoc/>
 456    public async Task<BackupManifestDto?> GetBackupManifest(string archivePath)
 457    {
 458        if (!File.Exists(archivePath))
 459        {
 460            return null;
 461        }
 462
 463        BackupManifest? manifest;
 464        try
 465        {
 466            manifest = await GetManifest(archivePath).ConfigureAwait(false);
 467        }
 468        catch (Exception ex)
 469        {
 470            _logger.LogWarning(ex, "Tried to load manifest from archive {Path} but failed", archivePath);
 471            return null;
 472        }
 473
 474        if (manifest is null)
 475        {
 476            return null;
 477        }
 478
 479        return Map(manifest, archivePath);
 480    }
 481
 482    /// <inheritdoc/>
 483    public async Task<BackupManifestDto[]> EnumerateBackups()
 484    {
 485        if (!Directory.Exists(_applicationPaths.BackupPath))
 486        {
 487            return [];
 488        }
 489
 490        var archives = Directory.EnumerateFiles(_applicationPaths.BackupPath, "*.zip");
 491        var manifests = new List<BackupManifestDto>();
 492        foreach (var item in archives)
 493        {
 494            try
 495            {
 496                var manifest = await GetManifest(item).ConfigureAwait(false);
 497
 498                if (manifest is null)
 499                {
 500                    continue;
 501                }
 502
 503                manifests.Add(Map(manifest, item));
 504            }
 505            catch (Exception ex)
 506            {
 507                _logger.LogWarning(ex, "Tried to load manifest from archive {Path} but failed", item);
 508            }
 509        }
 510
 511        return manifests.ToArray();
 512    }
 513
 514    private static async ValueTask<BackupManifest?> GetManifest(string archivePath)
 515    {
 516        var archiveStream = File.OpenRead(archivePath);
 517        await using (archiveStream.ConfigureAwait(false))
 518        {
 519            using var zipStream = new ZipArchive(archiveStream, ZipArchiveMode.Read);
 520            var manifestEntry = zipStream.GetEntry(ManifestEntryName);
 521            if (manifestEntry is null)
 522            {
 523                return null;
 524            }
 525
 526            var manifestStream = await manifestEntry.OpenAsync().ConfigureAwait(false);
 527            await using (manifestStream.ConfigureAwait(false))
 528            {
 529                return await JsonSerializer.DeserializeAsync<BackupManifest>(manifestStream, _serializerSettings).Config
 530            }
 531        }
 532    }
 533
 534    private static BackupManifestDto Map(BackupManifest manifest, string path)
 535    {
 0536        return new BackupManifestDto()
 0537        {
 0538            BackupEngineVersion = manifest.BackupEngineVersion,
 0539            DateCreated = manifest.DateCreated,
 0540            ServerVersion = manifest.ServerVersion,
 0541            Path = path,
 0542            Options = Map(manifest.Options)
 0543        };
 544    }
 545
 546    private static BackupOptionsDto Map(BackupOptions options)
 547    {
 0548        return new BackupOptionsDto()
 0549        {
 0550            Metadata = options.Metadata,
 0551            Subtitles = options.Subtitles,
 0552            Trickplay = options.Trickplay,
 0553            Database = options.Database
 0554        };
 555    }
 556
 557    private static BackupOptions Map(BackupOptionsDto options)
 558    {
 0559        return new BackupOptions()
 0560        {
 0561            Metadata = options.Metadata,
 0562            Subtitles = options.Subtitles,
 0563            Trickplay = options.Trickplay,
 0564            Database = options.Database
 0565        };
 566    }
 567
 568    /// <summary>
 569    /// Windows is able to handle '/' as a path seperator in zip files
 570    /// but linux isn't able to handle '\' as a path seperator in zip files,
 571    /// So normalize to '/'.
 572    /// </summary>
 573    /// <param name="path">The path to normalize.</param>
 574    /// <returns>The normalized path. </returns>
 575    private static string NormalizePathSeparator(string path)
 0576        => path.Replace('\\', '/');
 577}