mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-03 09:44:41 +02:00
Add: Backup notification (#3225)
* Formatting updates * Add: backup completion notification * Fix: comment for backup * Add: backup size units to notification * Add: failed backup notification * Add: calls to failed backup notification * Update: notification OpenAPI spec * Update notifications to first check if any are active for an event, update JS docs --------- Co-authored-by: advplyr <advplyr@protonmail.com>
This commit is contained in:
parent
5308fd8b46
commit
27b3a44147
7 changed files with 144 additions and 25 deletions
|
@ -16,9 +16,11 @@ const { getFileSize } = require('../utils/fileUtils')
|
|||
const Backup = require('../objects/Backup')
|
||||
|
||||
class BackupManager {
|
||||
constructor() {
|
||||
constructor(notificationManager) {
|
||||
this.ItemsMetadataPath = Path.join(global.MetadataPath, 'items')
|
||||
this.AuthorsMetadataPath = Path.join(global.MetadataPath, 'authors')
|
||||
/** @type {import('./NotificationManager')} */
|
||||
this.notificationManager = notificationManager
|
||||
|
||||
this.scheduleTask = null
|
||||
|
||||
|
@ -294,6 +296,8 @@ class BackupManager {
|
|||
// Create backup sqlite file
|
||||
const sqliteBackupPath = await this.backupSqliteDb(newBackup).catch((error) => {
|
||||
Logger.error(`[BackupManager] Failed to backup sqlite db`, error)
|
||||
const errorMsg = error?.message || error || 'Unknown Error'
|
||||
this.notificationManager.onBackupFailed(errorMsg)
|
||||
return false
|
||||
})
|
||||
|
||||
|
@ -304,6 +308,8 @@ class BackupManager {
|
|||
// Zip sqlite file, /metadata/items, and /metadata/authors folders
|
||||
const zipResult = await this.zipBackup(sqliteBackupPath, newBackup).catch((error) => {
|
||||
Logger.error(`[BackupManager] Backup Failed ${error}`)
|
||||
const errorMsg = error?.message || error || 'Unknown Error'
|
||||
this.notificationManager.onBackupFailed(errorMsg)
|
||||
return false
|
||||
})
|
||||
|
||||
|
@ -324,13 +330,18 @@ class BackupManager {
|
|||
}
|
||||
|
||||
// Check remove oldest backup
|
||||
if (this.backups.length > this.backupsToKeep) {
|
||||
const removeOldest = this.backups.length > this.backupsToKeep
|
||||
if (removeOldest) {
|
||||
this.backups.sort((a, b) => a.createdAt - b.createdAt)
|
||||
|
||||
const oldBackup = this.backups.shift()
|
||||
Logger.debug(`[BackupManager] Removing old backup ${oldBackup.id}`)
|
||||
this.removeBackup(oldBackup)
|
||||
}
|
||||
|
||||
// Notification for backup successfully completed
|
||||
this.notificationManager.onBackupCompleted(newBackup, this.backups.length, removeOldest)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -348,7 +359,6 @@ class BackupManager {
|
|||
/**
|
||||
* @see https://github.com/TryGhost/node-sqlite3/pull/1116
|
||||
* @param {Backup} backup
|
||||
* @promise
|
||||
*/
|
||||
backupSqliteDb(backup) {
|
||||
const db = new sqlite3.Database(Database.dbPath)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue