1
0
mirror of https://github.com/advplyr/audiobookshelf.git synced 2025-01-08 00:08:14 +01:00

Backups to store server version in zip details and check and show alert for old backups created before version 2.0.0

This commit is contained in:
advplyr 2022-04-13 18:51:06 -05:00
parent 79a82df914
commit 05dff2583a
3 changed files with 29 additions and 8 deletions
client/components/tables
server

View File

@ -13,17 +13,20 @@
<th class="hidden sm:table-cell w-20 md:w-28">Size</th> <th class="hidden sm:table-cell w-20 md:w-28">Size</th>
<th class="w-36"></th> <th class="w-36"></th>
</tr> </tr>
<tr v-for="backup in backups" :key="backup.id"> <tr v-for="backup in backups" :key="backup.id" :class="!backup.serverVersion ? 'bg-error bg-opacity-10' : ''">
<td> <td>
<p class="truncate text-xs sm:text-sm md:text-base">/{{ backup.path.replace(/\\/g, '/') }}</p> <p class="truncate text-xs sm:text-sm md:text-base">/{{ backup.path.replace(/\\/g, '/') }}</p>
</td> </td>
<td class="hidden sm:table-cell font-sans text-base">{{ backup.datePretty }}</td> <td class="hidden sm:table-cell font-sans text-sm">{{ backup.datePretty }}</td>
<td class="hidden sm:table-cell font-mono md:text-base text-xs">{{ $bytesPretty(backup.fileSize) }}</td> <td class="hidden sm:table-cell font-mono md:text-sm text-xs">{{ $bytesPretty(backup.fileSize) }}</td>
<td> <td>
<div class="w-full flex flex-row items-center justify-center"> <div class="w-full flex flex-row items-center justify-center">
<ui-btn small color="primary" @click="applyBackup(backup)">Apply</ui-btn> <ui-btn v-if="backup.serverVersion" small color="primary" @click="applyBackup(backup)">Apply</ui-btn>
<a :href="`/metadata/${$encodeUriPath(backup.path)}?token=${userToken}`" class="mx-1 pt-1 hover:text-opacity-100 text-opacity-70 text-white" download><span class="material-icons text-xl">download</span></a> <a v-if="backup.serverVersion" :href="`/metadata/${$encodeUriPath(backup.path)}?token=${userToken}`" class="mx-1 pt-1 hover:text-opacity-100 text-opacity-70 text-white" download><span class="material-icons text-xl">download</span></a>
<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-error">error_outline</span>
</ui-tooltip>
<span class="material-icons text-xl hover:text-error hover:text-opacity-100 text-opacity-70 text-white cursor-pointer mx-1" @click="deleteBackupClick(backup)">delete</span> <span class="material-icons text-xl hover:text-error hover:text-opacity-100 text-opacity-70 text-white cursor-pointer mx-1" @click="deleteBackupClick(backup)">delete</span>
</div> </div>
@ -176,11 +179,11 @@ export default {
text-align: center; text-align: center;
} }
#backups tr:nth-child(even) { #backups tr:nth-child(even):not(.bg-error) {
background-color: #3a3a3a; background-color: #3a3a3a;
} }
#backups tr:not(.staticrow):hover { #backups tr:not(.staticrow):not(.bg-error):hover {
background-color: #444; background-color: #444;
} }

View File

@ -92,6 +92,12 @@ class BackupManager {
var details = data.toString('utf8').split('\n') var details = data.toString('utf8').split('\n')
var backup = new Backup({ details, fullPath: tempPath }) var backup = new Backup({ details, fullPath: tempPath })
if (!backup.serverVersion) {
Logger.error(`[BackupManager] Invalid backup with no server version - might be a backup created before version 2.0.0`)
return res.status(500).send('Invalid backup. Might be a backup created before version 2.0.0.')
}
backup.fileSize = await getFileSize(backup.fullPath) backup.fileSize = await getFileSize(backup.fullPath)
var existingBackupIndex = this.backups.findIndex(b => b.id === backup.id) var existingBackupIndex = this.backups.findIndex(b => b.id === backup.id)
@ -133,6 +139,11 @@ class BackupManager {
var details = data.toString('utf8').split('\n') var details = data.toString('utf8').split('\n')
var backup = new Backup({ details, fullPath: fullFilePath }) var backup = new Backup({ details, fullPath: fullFilePath })
if (!backup.serverVersion) {
Logger.error(`[BackupManager] Old unsupported backup was found "${backup.fullPath}"`)
}
backup.fileSize = await getFileSize(backup.fullPath) backup.fileSize = await getFileSize(backup.fullPath)
var existingBackupWithId = this.backups.find(b => b.id === backup.id) var existingBackupWithId = this.backups.find(b => b.id === backup.id)
if (existingBackupWithId) { if (existingBackupWithId) {

View File

@ -1,5 +1,6 @@
const Path = require('path') const Path = require('path')
const date = require('date-and-time') const date = require('date-and-time')
const version = require('../../package.json').version
class Backup { class Backup {
constructor(data = null) { constructor(data = null) {
@ -11,6 +12,7 @@ class Backup {
this.filename = null this.filename = null
this.path = null this.path = null
this.fullPath = null this.fullPath = null
this.serverVersion = null
this.fileSize = null this.fileSize = null
this.createdAt = null this.createdAt = null
@ -25,6 +27,7 @@ class Backup {
details.push(this.id) details.push(this.id)
details.push(this.backupMetadataCovers ? '1' : '0') details.push(this.backupMetadataCovers ? '1' : '0')
details.push(this.createdAt) details.push(this.createdAt)
details.push(this.serverVersion)
return details.join('\n') return details.join('\n')
} }
@ -32,6 +35,7 @@ class Backup {
this.id = data.details[0] this.id = data.details[0]
this.backupMetadataCovers = data.details[1] === '1' this.backupMetadataCovers = data.details[1] === '1'
this.createdAt = Number(data.details[2]) this.createdAt = Number(data.details[2])
this.serverVersion = data.details[3] || null
this.datePretty = date.format(new Date(this.createdAt), 'ddd, MMM D YYYY HH:mm') this.datePretty = date.format(new Date(this.createdAt), 'ddd, MMM D YYYY HH:mm')
@ -51,7 +55,8 @@ class Backup {
path: this.path, path: this.path,
filename: this.filename, filename: this.filename,
fileSize: this.fileSize, fileSize: this.fileSize,
createdAt: this.createdAt createdAt: this.createdAt,
serverVersion: this.serverVersion
} }
} }
@ -67,6 +72,8 @@ class Backup {
this.path = Path.join('backups', this.filename) this.path = Path.join('backups', this.filename)
this.fullPath = Path.join(this.backupDirPath, this.filename) this.fullPath = Path.join(this.backupDirPath, this.filename)
this.serverVersion = version
this.createdAt = Date.now() this.createdAt = Date.now()
} }
} }