mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
The result of an Admin Panel backup lived only in the memory of the server process that ran it. After a restart, or on another pod of a multi-pod deployment, the Backup pane said "idle", so nobody could see whether last night's backup had worked. There was no history, no warning when a scheduled backup failed or did not run, and local backups were never cleaned up. - Every run, scheduled or "Backup now", is recorded in backupRuns: start and end, who or the schedule, scope, storage, status, size, duration and error. Records are kept 400 days. A run still "running" after 24 hours counts as failed, and a scheduled run skipped for another backup is recorded as failed. - Admin Panel / Problems / Backup shows the last success (overdue when its period has passed), the last failure with its error, the next run and the last 30 runs. The same status is above the schedule in Attachments / Backup. - Problems / Summary lists "Backup failed" and "Backup overdue". /metrics adds wekan_backup_last_success_timestamp_seconds, wekan_backup_last_run_timestamp_seconds, wekan_backup_last_run_success and wekan_backup_overdue for alerting. - BACKUP_KEEP_DAYS: after a successful backup, local backups of the same scope older than N days are deleted. The newest is always kept, and only a directory inside the backup root holding a backup.zip is removed. From the patch by Raymond-Voogt, and in Admin Panel as well: - BACKUP_KEEP_DAYS is the catalog's backup section (models/lib/authConfigCatalog.js), overridable beside the schedule in Admin Panel / Attachments / Backup and resolved through authEnv at every backup. - It is listed on every platform: the compose files, start-wekan.sh and .bat, the snap config and help, and the Dockerfile, which the patch's version had missed. Its platform hunks, written before #6789, were re-applied by hand. tests/backupRuns.test.cjs (21): the run records, overdue and pruning against a real directory, and the Admin Panel override, including that nothing reads the variable around it. tests/authConfigCatalog.test.cjs checks every platform. admin-attachment-retention.e2e.js checks the Backup pane shows the field. Thanks to Raymond-Voogt and xet7 ! Fixes #6790.
95 lines
2.8 KiB
JavaScript
95 lines
2.8 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { Template } from 'meteor/templating';
|
|
import { ReactiveVar } from 'meteor/reactive-var';
|
|
import { Session } from 'meteor/session';
|
|
import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
|
|
import { TAPi18n } from '/imports/i18n';
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
|
|
// Admin Panel backup status and history (backupRunsStatus.jade): the recorded runs
|
|
// and the instance backup's health from the backupHistory method
|
|
// (server/methods/backup.js, rules in models/lib/backupRuns.js). Used in
|
|
// Admin Panel / Attachments / Backup and Admin Panel / Problems / Backup.
|
|
//
|
|
// Reloads when Session 'backupHistoryChanged' changes - the Backup pane sets
|
|
// it when a run it is watching ends - and on the refresh icon.
|
|
|
|
function formatBytes(bytes) {
|
|
if (!Number.isFinite(bytes)) return '';
|
|
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
let n = bytes;
|
|
let i = 0;
|
|
while (n >= 1024 && i < units.length - 1) { n /= 1024; i += 1; }
|
|
return `${n.toFixed(i ? 1 : 0)} ${units[i]}`;
|
|
}
|
|
|
|
function formatDuration(ms) {
|
|
if (!Number.isFinite(ms)) return '';
|
|
const total = Math.round(ms / 1000);
|
|
const h = Math.floor(total / 3600);
|
|
const m = Math.floor((total % 3600) / 60);
|
|
const sec = total % 60;
|
|
if (h) return `${h}h ${m}m`;
|
|
return m ? `${m}m ${sec}s` : `${sec}s`;
|
|
}
|
|
|
|
function load(tpl) {
|
|
Meteor.call('backupHistory', (err, history) => {
|
|
if (!err && history) tpl.history.set(history);
|
|
});
|
|
}
|
|
|
|
Template.backupRunsStatus.onCreated(function () {
|
|
this.history = new ReactiveVar(null);
|
|
this.autorun(() => {
|
|
Session.get('backupHistoryChanged');
|
|
load(this);
|
|
});
|
|
});
|
|
|
|
Template.backupRunsStatus.helpers({
|
|
backupHealth() {
|
|
const h = Template.instance().history.get();
|
|
return h && h.health;
|
|
},
|
|
backupHealthIs(state) {
|
|
const h = Template.instance().history.get();
|
|
return !!(h && h.health && h.health.state === state);
|
|
},
|
|
backupRuns() {
|
|
const h = Template.instance().history.get();
|
|
return (h && h.runs) || [];
|
|
},
|
|
backupNextRunAt() {
|
|
const h = Template.instance().history.get();
|
|
return h && h.nextRunAt;
|
|
},
|
|
backupRunIs(status) {
|
|
return this.status === status;
|
|
},
|
|
backupRunSize() {
|
|
return formatBytes(this.size);
|
|
},
|
|
backupRunDuration() {
|
|
return formatDuration(this.durationMs);
|
|
},
|
|
backupScopeName(orgId) {
|
|
if (!orgId) return TAPi18n.__('backup-scope-instance');
|
|
const org = ReactiveCache.getOrg(orgId);
|
|
return (org && org.orgDisplayName) || orgId;
|
|
},
|
|
settingsLink() {
|
|
return !!(Template.currentData() && Template.currentData().settingsLink);
|
|
},
|
|
backupSettingsPath() {
|
|
return FlowRouter.path('attachments', { pane: 'backup' });
|
|
},
|
|
});
|
|
|
|
Template.backupRunsStatus.events({
|
|
'click .js-refresh-backup-history'(event, tpl) {
|
|
event.preventDefault();
|
|
load(tpl);
|
|
},
|
|
});
|