Update Backup to use key to check for old backups no longer supported

This commit is contained in:
advplyr 2023-07-14 14:20:35 -05:00
parent 1b97582975
commit c5a4f63670
3 changed files with 15 additions and 8 deletions

View File

@ -21,15 +21,14 @@
<td class="hidden sm:table-cell font-mono md:text-sm text-xs">{{ $bytesPretty(backup.fileSize) }}</td>
<td>
<div class="w-full flex flex-row items-center justify-center">
<ui-btn v-if="backup.serverVersion" small color="primary" @click="applyBackup(backup)">{{ $strings.ButtonRestore }}</ui-btn>
<button v-if="backup.serverVersion" aria-label="Download Backup" class="inline-flex material-icons text-xl mx-1 mt-1 text-white/70 hover:text-white/100" @click.stop="downloadBackup(backup)">download</button>
<ui-btn v-if="backup.serverVersion && backup.key" small color="primary" @click="applyBackup(backup)">{{ $strings.ButtonRestore }}</ui-btn>
<ui-tooltip v-else text="This backup was created with an old version of audiobookshelf no longer supported" direction="bottom" class="mx-2 flex items-center">
<span class="material-icons-outlined text-2xl text-error">error_outline</span>
</ui-tooltip>
<button v-if="backup.serverVersion" aria-label="Delete Backup" class="inline-flex material-icons text-xl mx-1 text-white/70 hover:text-error" @click="deleteBackupClick(backup)">delete</button>
<button aria-label="Download Backup" class="inline-flex material-icons text-xl mx-1 mt-1 text-white/70 hover:text-white/100" @click.stop="downloadBackup(backup)">download</button>
<button aria-label="Delete Backup" class="inline-flex material-icons text-xl mx-1 text-white/70 hover:text-error" @click="deleteBackupClick(backup)">delete</button>
</div>
</td>
</tr>

View File

@ -180,8 +180,10 @@ class BackupManager {
const backup = new Backup({ details, fullPath: fullFilePath })
if (!backup.serverVersion) {
Logger.error(`[BackupManager] Old unsupported backup was found "${backup.fullPath}"`)
if (!backup.serverVersion) { // Backups before v2
Logger.error(`[BackupManager] Old unsupported backup was found "${backup.filename}"`)
} else if (!backup.key) { // Backups before sqlite migration
Logger.warn(`[BackupManager] Old unsupported backup was found "${backup.filename}" (pre sqlite migration)`)
}
backup.fileSize = await getFileSize(backup.fullPath)

View File

@ -5,6 +5,7 @@ const version = require('../../package.json').version
class Backup {
constructor(data = null) {
this.id = null
this.key = null // Special key for pre-version checks
this.datePretty = null
this.backupDirPath = null
@ -24,7 +25,7 @@ class Backup {
get detailsString() {
const details = []
details.push(this.id)
details.push('1') // Unused old boolean spot
details.push(this.key)
details.push(this.createdAt)
details.push(this.serverVersion)
return details.join('\n')
@ -32,6 +33,9 @@ class Backup {
construct(data) {
this.id = data.details[0]
this.key = data.details[1]
if (this.key == 1) this.key = null // v2.2.23 and below backups stored '1' here
this.createdAt = Number(data.details[2])
this.serverVersion = data.details[3] || null
@ -46,6 +50,7 @@ class Backup {
toJSON() {
return {
id: this.id,
key: this.key,
backupDirPath: this.backupDirPath,
datePretty: this.datePretty,
fullPath: this.fullPath,
@ -59,6 +64,7 @@ class Backup {
setData(backupDirPath) {
this.id = date.format(new Date(), 'YYYY-MM-DD[T]HHmm')
this.key = 'sqlite'
this.datePretty = date.format(new Date(), 'ddd, MMM D YYYY HH:mm')
this.backupDirPath = backupDirPath