From 3dbe7eec1f226f532a19285fdb45b3f58303ea85 Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Sun, 25 Jul 2021 19:34:55 -0500 Subject: [PATCH] Feature/manual db backup (#437) Added: New button in manage server to manually create a backup of DB (Fixes Add on demand DB backup from Admin Dashboard #322) --- API/Controllers/ServerController.cs | 22 +++++++++++++++++++ Kavita.Common/Kavita.Common.csproj | 2 +- UI/Web/src/app/_services/server.service.ts | 4 ++++ .../manage-system.component.html | 7 ++++++ .../manage-system/manage-system.component.ts | 9 ++++++++ 5 files changed, 43 insertions(+), 1 deletion(-) diff --git a/API/Controllers/ServerController.cs b/API/Controllers/ServerController.cs index 929f0d0ae..028d180df 100644 --- a/API/Controllers/ServerController.cs +++ b/API/Controllers/ServerController.cs @@ -35,6 +35,10 @@ namespace API.Controllers _cacheService = cacheService; } + /// + /// Attempts to Restart the server. Does not work, will shutdown the instance. + /// + /// [HttpPost("restart")] public ActionResult RestartServer() { @@ -44,6 +48,10 @@ namespace API.Controllers return Ok(); } + /// + /// Performs an ad-hoc cleanup of Cache + /// + /// [HttpPost("clear-cache")] public ActionResult ClearCache() { @@ -53,6 +61,19 @@ namespace API.Controllers return Ok(); } + /// + /// Performs an ad-hoc backup of the Database + /// + /// + [HttpPost("backup-db")] + public ActionResult BackupDatabase() + { + _logger.LogInformation("{UserName} is backing up database of server from admin dashboard", User.GetUsername()); + _backupService.BackupDatabase(); + + return Ok(); + } + /// /// Returns non-sensitive information about the current system /// @@ -79,5 +100,6 @@ namespace API.Controllers } + } } diff --git a/Kavita.Common/Kavita.Common.csproj b/Kavita.Common/Kavita.Common.csproj index 85e968d75..7e67cccbb 100644 --- a/Kavita.Common/Kavita.Common.csproj +++ b/Kavita.Common/Kavita.Common.csproj @@ -4,7 +4,7 @@ net5.0 kavitareader.com Kavita - 0.4.3.1 + 0.4.3.2 en diff --git a/UI/Web/src/app/_services/server.service.ts b/UI/Web/src/app/_services/server.service.ts index 3abec515b..a3964f908 100644 --- a/UI/Web/src/app/_services/server.service.ts +++ b/UI/Web/src/app/_services/server.service.ts @@ -23,4 +23,8 @@ export class ServerService { clearCache() { return this.httpClient.post(this.baseUrl + 'server/clear-cache', {}); } + + backupDatabase() { + return this.httpClient.post(this.baseUrl + 'server/backup-db', {}); + } } diff --git a/UI/Web/src/app/admin/manage-system/manage-system.component.html b/UI/Web/src/app/admin/manage-system/manage-system.component.html index 6d0529130..b8f99e6cf 100644 --- a/UI/Web/src/app/admin/manage-system/manage-system.component.html +++ b/UI/Web/src/app/admin/manage-system/manage-system.component.html @@ -8,6 +8,13 @@ Clear Cache + diff --git a/UI/Web/src/app/admin/manage-system/manage-system.component.ts b/UI/Web/src/app/admin/manage-system/manage-system.component.ts index 00db673a1..0e5e95ca4 100644 --- a/UI/Web/src/app/admin/manage-system/manage-system.component.ts +++ b/UI/Web/src/app/admin/manage-system/manage-system.component.ts @@ -21,6 +21,7 @@ export class ManageSystemComponent implements OnInit { serverInfo!: ServerInfo; clearCacheInProgress: boolean = false; + backupDBInProgress: boolean = false; constructor(private settingsService: SettingsService, private toastr: ToastrService, private serverService: ServerService, public downloadService: DownloadService) { } @@ -71,4 +72,12 @@ export class ManageSystemComponent implements OnInit { }); } + backupDB() { + this.backupDBInProgress = true; + this.serverService.backupDatabase().subscribe(res => { + this.backupDBInProgress = false; + this.toastr.success('Database has been backed up'); + }); + } + }