u
This commit is contained in:
72
src/api/routes/backup.js
Normal file
72
src/api/routes/backup.js
Normal file
@@ -0,0 +1,72 @@
|
||||
import { listBackups, getBackupServiceStatus, createHourlyBackup } from '../../services/backupService.js';
|
||||
|
||||
/**
|
||||
* Registers internal backup service status and execution endpoints.
|
||||
* @param {import('express').Application} app - Express app
|
||||
* @param {string} [basePath=''] - Optional URL prefix for all routes in this module
|
||||
*/
|
||||
export function register(app, basePath = '') {
|
||||
/**
|
||||
* @openapi
|
||||
* /backup:
|
||||
* get:
|
||||
* tags: [Backup]
|
||||
* summary: List backups and service status
|
||||
* description: Retrieves the current status of the internal backup service and lists available hourly, daily, and monthly backups.
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Backup service status and listing
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* status:
|
||||
* type: object
|
||||
* backups:
|
||||
* type: object
|
||||
* 500:
|
||||
* description: Internal error
|
||||
*/
|
||||
// #region GET /backup
|
||||
// MARK: handles GET /backup to list backups and service status
|
||||
app.get(`${basePath}/backup`, async (_req, res) => {
|
||||
try {
|
||||
const status = getBackupServiceStatus();
|
||||
const backups = listBackups();
|
||||
res.status(200).json({ status, backups });
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /backup/run:
|
||||
* post:
|
||||
* tags: [Backup]
|
||||
* summary: Trigger manual backup
|
||||
* description: Immediately triggers an on-demand backup snapshot of VFS, storage, and SQLite database.
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Backup triggered successfully
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* 500:
|
||||
* description: Backup execution failure
|
||||
*/
|
||||
// #region POST /backup/run
|
||||
// MARK: handles POST /backup/run to trigger manual backup
|
||||
app.post(`${basePath}/backup/run`, async (_req, res) => {
|
||||
try {
|
||||
const result = await createHourlyBackup({ manual: true });
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
// #endregion
|
||||
}
|
||||
Reference in New Issue
Block a user