mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-21 14:08:15 +02:00
Add database backup and restore functionality for administrators
Introduce endpoints and UI for managing PostgreSQL database backups, including automatic nightly backups, manual backups, and the ability to download and delete backup files. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 7c468936-2a88-4686-ac0a-84921a45222d Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/7c468936-2a88-4686-ac0a-84921a45222d/B7k6m01
This commit is contained in:
1 parent
3b46f945a4
commit
bfc90053f0
3 files changed
+555
No files matched your search
@@ -39,6 +39,7 @@ import {
|
||||
import { hasPermission } from "@shared/permissions";
|
||||
import { z } from "zod";
|
||||
import { invoiceVerificationService } from "./invoiceVerification";
|
||||
import { backupService } from "./backupService";
|
||||
|
||||
export async function registerRoutes(app: Express): Promise<Server> {
|
||||
// Health check endpoint for Docker
|
||||
@@ -2338,6 +2339,55 @@ RÉSUMÉ DU SCAN
|
||||
}
|
||||
});
|
||||
|
||||
// Backup management routes (Admin only)
|
||||
app.get('/api/backups', isAuthenticated, requireAdmin, async (req: any, res) => {
|
||||
try {
|
||||
const backups = await backupService.getBackupList();
|
||||
res.json(backups);
|
||||
} catch (error) {
|
||||
console.error("Error fetching backups:", error);
|
||||
res.status(500).json({ message: "Failed to fetch backups" });
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/backups', isAuthenticated, requireAdmin, async (req: any, res) => {
|
||||
try {
|
||||
const backup = await backupService.createBackup('manual');
|
||||
res.json(backup);
|
||||
} catch (error) {
|
||||
console.error("Error creating backup:", error);
|
||||
res.status(500).json({ message: "Failed to create backup" });
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/api/backups/:filename/download', isAuthenticated, requireAdmin, async (req: any, res) => {
|
||||
try {
|
||||
const { filename } = req.params;
|
||||
const filepath = await backupService.downloadBackup(filename);
|
||||
|
||||
res.download(filepath, filename, (err) => {
|
||||
if (err) {
|
||||
console.error("Error downloading backup:", err);
|
||||
res.status(404).json({ message: "Backup file not found" });
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error downloading backup:", error);
|
||||
res.status(500).json({ message: "Failed to download backup" });
|
||||
}
|
||||
});
|
||||
|
||||
app.delete('/api/backups/:filename', isAuthenticated, requireAdmin, async (req: any, res) => {
|
||||
try {
|
||||
const { filename } = req.params;
|
||||
await backupService.deleteBackup(filename);
|
||||
res.json({ message: "Backup deleted successfully" });
|
||||
} catch (error) {
|
||||
console.error("Error deleting backup:", error);
|
||||
res.status(500).json({ message: "Failed to delete backup" });
|
||||
}
|
||||
});
|
||||
|
||||
// Create server instance
|
||||
const httpServer = createServer(app);
|
||||
|
||||
|
||||
Reference in new issue
Block a user