mirror of
https://github.com/R0m1k3/Regisflow.git
synced 2026-10-22 22:58:16 +02:00
Enable automatic data backups to secure user information regularly
Implements automatic database backups every 12 hours using node-cron, retaining only the 10 most recent backups in server/backup-scheduler.ts. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 91318273-c764-4fd4-be04-bdc12c38af32 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/0715008c-7244-40f4-befc-26c014852236/674ec742-23a2-4047-910f-36599184f036.jpg
This commit is contained in:
1 parent
546ba12e89
commit
a78d648c01
9 files changed
+594
-5
No files matched your search
+33
-2
@@ -5,6 +5,7 @@ import session from "express-session";
|
||||
import connectPg from "connect-pg-simple";
|
||||
import { loginSchema, insertUserSchema, insertStoreSchema, insertSaleSchema } from "@shared/schema";
|
||||
import { z } from "zod";
|
||||
import { createAutomaticBackup, getBackupStats } from "./backup-scheduler";
|
||||
|
||||
declare module 'express-session' {
|
||||
interface SessionData {
|
||||
@@ -483,13 +484,43 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
message: "Backup imported successfully",
|
||||
imported: {
|
||||
stores: backupData.data.stores.length,
|
||||
users: backupData.data.users.filter(u => u.username !== 'admin').length,
|
||||
users: backupData.data.users.filter((u: any) => u.username !== 'admin').length,
|
||||
sales: backupData.data.sales.length
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Import backup error:', error);
|
||||
res.status(500).json({ error: "Failed to import backup", details: error.message });
|
||||
res.status(500).json({ error: "Failed to import backup", details: error instanceof Error ? error.message : 'Unknown error' });
|
||||
}
|
||||
});
|
||||
|
||||
// Manual backup trigger route
|
||||
app.post('/api/admin/backup/create', requireRole(['admin']), async (req, res) => {
|
||||
try {
|
||||
const result = await createAutomaticBackup();
|
||||
if (result.success) {
|
||||
res.json({
|
||||
message: "Manual backup created successfully",
|
||||
filename: result.filename,
|
||||
stats: result.stats
|
||||
});
|
||||
} else {
|
||||
res.status(500).json({ error: "Failed to create backup", details: result.error });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Manual backup error:', error);
|
||||
res.status(500).json({ error: "Failed to create backup" });
|
||||
}
|
||||
});
|
||||
|
||||
// Backup statistics route
|
||||
app.get('/api/admin/backup/stats', requireRole(['admin']), async (req, res) => {
|
||||
try {
|
||||
const stats = getBackupStats();
|
||||
res.json(stats);
|
||||
} catch (error) {
|
||||
console.error('Backup stats error:', error);
|
||||
res.status(500).json({ error: "Failed to get backup statistics" });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user