mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-01-15 15:48:03 +00:00
Add Full system backup feature (#13945)
This commit is contained in:
@@ -14,7 +14,6 @@ public class TrickplayInfo
|
||||
/// <remarks>
|
||||
/// Required.
|
||||
/// </remarks>
|
||||
[JsonIgnore]
|
||||
public Guid ItemId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -61,7 +61,6 @@ namespace Jellyfin.Database.Implementations.Entities
|
||||
/// <remarks>
|
||||
/// Identity, Indexed, Required.
|
||||
/// </remarks>
|
||||
[JsonIgnore]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -62,4 +63,12 @@ public interface IJellyfinDatabaseProvider
|
||||
/// <param name="cancellationToken">A cancellation token.</param>
|
||||
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
|
||||
Task RestoreBackupFast(string key, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Removes all contents from the database.
|
||||
/// </summary>
|
||||
/// <param name="dbContext">The Database context.</param>
|
||||
/// <param name="tableNames">The names of the tables to purge or null for all tables to be purged.</param>
|
||||
/// <returns>A Task.</returns>
|
||||
Task PurgeDatabase(JellyfinDbContext dbContext, IEnumerable<string>? tableNames);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
@@ -82,7 +83,7 @@ public sealed class SqliteDatabaseProvider : IJellyfinDatabaseProvider
|
||||
}
|
||||
|
||||
// Run before disposing the application
|
||||
var context = await DbContextFactory!.CreateDbContextAsync(cancellationToken).ConfigureAwait(false);
|
||||
var context = await DbContextFactory.CreateDbContextAsync(cancellationToken).ConfigureAwait(false);
|
||||
await using (context.ConfigureAwait(false))
|
||||
{
|
||||
await context.Database.ExecuteSqlRawAsync("PRAGMA optimize", cancellationToken).ConfigureAwait(false);
|
||||
@@ -127,4 +128,25 @@ public sealed class SqliteDatabaseProvider : IJellyfinDatabaseProvider
|
||||
File.Copy(backupFile, path, true);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task PurgeDatabase(JellyfinDbContext dbContext, IEnumerable<string>? tableNames)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(tableNames);
|
||||
|
||||
var deleteQueries = new List<string>();
|
||||
foreach (var tableName in tableNames)
|
||||
{
|
||||
deleteQueries.Add($"DELETE FROM \"{tableName}\";");
|
||||
}
|
||||
|
||||
var deleteAllQuery =
|
||||
$"""
|
||||
PRAGMA foreign_keys = OFF;
|
||||
{string.Join('\n', deleteQueries)}
|
||||
PRAGMA foreign_keys = ON;
|
||||
""";
|
||||
|
||||
await dbContext.Database.ExecuteSqlRawAsync(deleteAllQuery).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user