Skip to content

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.

Fixed an issue where docker users were not properly backing up the database. Removed an empty File for when covers/ had nothing in it. (#692)

Joseph Milazzo6fb01eefa482
diff --git a/API/Controllers/ServerController.cs b/API/Controllers/ServerController.cs
index eec7c53cb..104d00310 100644
--- a/API/Controllers/ServerController.cs
+++ b/API/Controllers/ServerController.cs
@@ -71,10 +71,10 @@ namespace API.Controllers
/// </summary>
/// <returns></returns>
[HttpPost("backup-db")]
- public ActionResult BackupDatabase()
+ public async Task<ActionResult> BackupDatabase()
{
_logger.LogInformation("{UserName} is backing up database of server from admin dashboard", User.GetUsername());
- _backupService.BackupDatabase();
+ await _backupService.BackupDatabase();
return Ok();
}
diff --git a/API/Services/Tasks/BackupService.cs b/API/Services/Tasks/BackupService.cs
index b4dc3910b..ab8a84ea9 100644
--- a/API/Services/Tasks/BackupService.cs
+++ b/API/Services/Tasks/BackupService.cs
@@ -9,6 +9,7 @@ using API.Extensions;
using API.Interfaces;
using API.Interfaces.Services;
using Hangfire;
+using Kavita.Common.EnvironmentInfo;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
@@ -33,15 +34,32 @@ namespace API.Services.Tasks
var maxRollingFiles = config.GetMaxRollingFiles();
var loggingSection = config.GetLoggingFileName();
var files = LogFiles(maxRollingFiles, loggingSection);
- _backupFiles = new List<string>()
+
+ if (new OsInfo(Array.Empty<IOsVersionAdapter>()).IsDocker)
+ {
+ _backupFiles = new List<string>()
+ {
+ "data/appsettings.json",
+ "data/Hangfire.db",
+ "data/Hangfire-log.db",
+ "data/kavita.db",
+ "data/kavita.db-shm", // This wont always be there
+ "data/kavita.db-wal" // This wont always be there
+ };
+ }
+ else
{
- "appsettings.json",
- "Hangfire.db",
- "Hangfire-log.db",
- "kavita.db",
- "kavita.db-shm", // This wont always be there
- "kavita.db-wal", // This wont always be there
- };
+ _backupFiles = new List<string>()
+ {
+ "appsettings.json",
+ "Hangfire.db",
+ "Hangfire-log.db",
+ "kavita.db",
+ "kavita.db-shm", // This wont always be there
+ "kavita.db-wal" // This wont always be there
+ };
+ }
+
foreach (var file in files.Select(f => (new FileInfo(f)).Name).ToList())
{
_backupFiles.Add(file);
@@ -129,6 +147,11 @@ namespace API.Services.Tasks
{
// Swallow exception. This can be a duplicate cover being copied as chapter and volumes can share same file.
}
+
+ if (!_directoryService.GetFiles(outputTempDir).Any())
+ {
+ DirectoryService.ClearAndDeleteDirectory(outputTempDir);
+ }
}
/// <summary>
diff --git a/Kavita.Common/EnvironmentInfo/IOsInfo.cs b/Kavita.Common/EnvironmentInfo/IOsInfo.cs
index f93e4781c..d90be9489 100644
--- a/Kavita.Common/EnvironmentInfo/IOsInfo.cs
+++ b/Kavita.Common/EnvironmentInfo/IOsInfo.cs
@@ -41,12 +41,13 @@ namespace Kavita.Common.EnvironmentInfo
break;
}
}
+
}
public OsInfo(IEnumerable<IOsVersionAdapter> versionAdapters)
{
OsVersionModel osInfo = null;
-
+
foreach (var osVersionAdapter in versionAdapters.Where(c => c.Enabled))
{
try
@@ -57,13 +58,13 @@ namespace Kavita.Common.EnvironmentInfo
{
Console.WriteLine("Couldn't get OS Version info: " + e.Message);
}
-
+
if (osInfo != null)
{
break;
}
}
-
+
if (osInfo != null)
{
Name = osInfo.Name;
@@ -75,7 +76,7 @@ namespace Kavita.Common.EnvironmentInfo
Name = Os.ToString();
FullName = Name;
}
-
+
if (IsLinux && File.Exists("/proc/1/cgroup") && File.ReadAllText("/proc/1/cgroup").Contains("/docker/"))
{
IsDocker = true;
@@ -145,4 +146,4 @@ namespace Kavita.Common.EnvironmentInfo
LinuxMusl,
Bsd
}
-}
\ No newline at end of file
+}