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)

This commit is contained in:
Joseph Milazzo 2021-10-19 08:35:52 -07:00 committed by GitHub
parent 9d84bfca5f
commit 6fb01eefa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 15 deletions

View File

@ -71,10 +71,10 @@ namespace API.Controllers
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPost("backup-db")] [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()); _logger.LogInformation("{UserName} is backing up database of server from admin dashboard", User.GetUsername());
_backupService.BackupDatabase(); await _backupService.BackupDatabase();
return Ok(); return Ok();
} }

View File

@ -9,6 +9,7 @@ using API.Extensions;
using API.Interfaces; using API.Interfaces;
using API.Interfaces.Services; using API.Interfaces.Services;
using Hangfire; using Hangfire;
using Kavita.Common.EnvironmentInfo;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -33,15 +34,32 @@ namespace API.Services.Tasks
var maxRollingFiles = config.GetMaxRollingFiles(); var maxRollingFiles = config.GetMaxRollingFiles();
var loggingSection = config.GetLoggingFileName(); var loggingSection = config.GetLoggingFileName();
var files = LogFiles(maxRollingFiles, loggingSection); var files = LogFiles(maxRollingFiles, loggingSection);
_backupFiles = new List<string>()
if (new OsInfo(Array.Empty<IOsVersionAdapter>()).IsDocker)
{ {
"appsettings.json", _backupFiles = new List<string>()
"Hangfire.db", {
"Hangfire-log.db", "data/appsettings.json",
"kavita.db", "data/Hangfire.db",
"kavita.db-shm", // This wont always be there "data/Hangfire-log.db",
"kavita.db-wal", // This wont always be there "data/kavita.db",
}; "data/kavita.db-shm", // This wont always be there
"data/kavita.db-wal" // This wont always be there
};
}
else
{
_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()) foreach (var file in files.Select(f => (new FileInfo(f)).Name).ToList())
{ {
_backupFiles.Add(file); _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. // 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> /// <summary>

View File

@ -41,12 +41,13 @@ namespace Kavita.Common.EnvironmentInfo
break; break;
} }
} }
} }
public OsInfo(IEnumerable<IOsVersionAdapter> versionAdapters) public OsInfo(IEnumerable<IOsVersionAdapter> versionAdapters)
{ {
OsVersionModel osInfo = null; OsVersionModel osInfo = null;
foreach (var osVersionAdapter in versionAdapters.Where(c => c.Enabled)) foreach (var osVersionAdapter in versionAdapters.Where(c => c.Enabled))
{ {
try try
@ -57,13 +58,13 @@ namespace Kavita.Common.EnvironmentInfo
{ {
Console.WriteLine("Couldn't get OS Version info: " + e.Message); Console.WriteLine("Couldn't get OS Version info: " + e.Message);
} }
if (osInfo != null) if (osInfo != null)
{ {
break; break;
} }
} }
if (osInfo != null) if (osInfo != null)
{ {
Name = osInfo.Name; Name = osInfo.Name;
@ -75,7 +76,7 @@ namespace Kavita.Common.EnvironmentInfo
Name = Os.ToString(); Name = Os.ToString();
FullName = Name; FullName = Name;
} }
if (IsLinux && File.Exists("/proc/1/cgroup") && File.ReadAllText("/proc/1/cgroup").Contains("/docker/")) if (IsLinux && File.Exists("/proc/1/cgroup") && File.ReadAllText("/proc/1/cgroup").Contains("/docker/"))
{ {
IsDocker = true; IsDocker = true;
@ -145,4 +146,4 @@ namespace Kavita.Common.EnvironmentInfo
LinuxMusl, LinuxMusl,
Bsd Bsd
} }
} }