feat: adds support for allowing backups of unlimited size

This commit is contained in:
Andrew Leonard 2024-07-15 23:58:05 -04:00
parent b1bc472205
commit 2bc949fae3
No known key found for this signature in database
2 changed files with 14 additions and 13 deletions

View File

@ -64,7 +64,7 @@
<ui-text-input type="number" v-model="maxBackupSize" no-spinner :disabled="updatingServerSettings" :padding-x="1" text-center class="w-10" @change="updateBackupsSettings" /> <ui-text-input type="number" v-model="maxBackupSize" no-spinner :disabled="updatingServerSettings" :padding-x="1" text-center class="w-10" @change="updateBackupsSettings" />
<ui-tooltip :text="$strings.LabelBackupsMaxBackupSizeHelp"> <ui-tooltip :text="$strings.LabelBackupsMaxBackupSizeHelp">
<p class="pl-4 text-lg">{{ $strings.LabelBackupsMaxBackupSize }} <span class="material-symbols icon-text">info</span></p> <p class="pl-4 text-lg">{{ $strings.LabelBackupsMaxBackupSize }} (0 for unlimited) <span class="material-symbols icon-text">info</span></p>
</ui-tooltip> </ui-tooltip>
</div> </div>
@ -170,7 +170,7 @@ export default {
}) })
}, },
updateBackupsSettings() { updateBackupsSettings() {
if (isNaN(this.maxBackupSize) || this.maxBackupSize <= 0) { if (isNaN(this.maxBackupSize) || this.maxBackupSize < 0) {
this.$toast.error('Invalid maximum backup size') this.$toast.error('Invalid maximum backup size')
return return
} }
@ -200,10 +200,9 @@ export default {
}, },
initServerSettings() { initServerSettings() {
this.newServerSettings = this.serverSettings ? { ...this.serverSettings } : {} this.newServerSettings = this.serverSettings ? { ...this.serverSettings } : {}
this.backupsToKeep = this.newServerSettings.backupsToKeep || 2 this.backupsToKeep = this.newServerSettings.backupsToKeep || 2
this.enableBackups = !!this.newServerSettings.backupSchedule this.enableBackups = !!this.newServerSettings.backupSchedule
this.maxBackupSize = this.newServerSettings.maxBackupSize || 1 this.maxBackupSize = this.newServerSettings.maxBackupSize || 0
this.cronExpression = this.newServerSettings.backupSchedule || '30 1 * * *' this.cronExpression = this.newServerSettings.backupSchedule || '30 1 * * *'
} }
}, },

View File

@ -42,7 +42,7 @@ class BackupManager {
} }
get maxBackupSize() { get maxBackupSize() {
return global.ServerSettings.maxBackupSize || 1 return global.ServerSettings.maxBackupSize || Infinity
} }
async init() { async init() {
@ -419,14 +419,16 @@ class BackupManager {
reject(err) reject(err)
}) })
archive.on('progress', ({ fs: fsobj }) => { archive.on('progress', ({ fs: fsobj }) => {
const maxBackupSizeInBytes = this.maxBackupSize * 1000 * 1000 * 1000 if (this.maxBackupSize !== Infinity) {
if (fsobj.processedBytes > maxBackupSizeInBytes) { const maxBackupSizeInBytes = this.maxBackupSize * 1000 * 1000 * 1000
Logger.error(`[BackupManager] Archiver is too large - aborting to prevent endless loop, Bytes Processed: ${fsobj.processedBytes}`) if (fsobj.processedBytes > maxBackupSizeInBytes) {
archive.abort() Logger.error(`[BackupManager] Archiver is too large - aborting to prevent endless loop, Bytes Processed: ${fsobj.processedBytes}`)
setTimeout(() => { archive.abort()
this.removeBackup(backup) setTimeout(() => {
output.destroy('Backup too large') // Promise is reject in write stream error evt this.removeBackup(backup)
}, 500) output.destroy('Backup too large') // Promise is reject in write stream error evt
}, 500)
}
} }
}) })