mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
Fix automatic database backup system for production
Resolves an issue where the automatic backup service was not initialized in the production environment, preventing daily backups. Updates `docker-compose.yml` to include a backup directory and volume, modifies `index.production.ts` to import and initialize the backup service, and enhances `replit.md` with details of the fix. A new verification script `scripts/verify-backup-system.sh` is added to confirm the system's functionality. Replit-Commit-Author: Agent Replit-Commit-Session-Id: cc2d271b-82f0-4d6a-9302-a0b067ffb429 Replit-Commit-Checkpoint-Type: full_checkpoint
This commit is contained in:
1 parent
b3ad47fe83
commit
c851aacb28
4 files changed
+114
-1
No files matched your search
@@ -16,6 +16,7 @@ services:
|
||||
POSTGRES_USER: logiflow_admin
|
||||
POSTGRES_PASSWORD: LogiFlow2025!
|
||||
POSTGRES_DB: logiflow_db
|
||||
BACKUP_DIR: /app/backups
|
||||
ports:
|
||||
- "3000:3000"
|
||||
networks:
|
||||
@@ -25,6 +26,7 @@ services:
|
||||
condition: service_healthy
|
||||
volumes:
|
||||
- ./migrations:/app/migrations
|
||||
- backup_data:/app/backups
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/api/health"]
|
||||
interval: 30s
|
||||
@@ -57,6 +59,8 @@ services:
|
||||
volumes:
|
||||
postgres_data:
|
||||
driver: local
|
||||
backup_data:
|
||||
driver: local
|
||||
|
||||
networks:
|
||||
nginx_default:
|
||||
|
||||
@@ -24,7 +24,7 @@ The platform is built with a clear separation of concerns, utilizing a modern fu
|
||||
- **Database:** PostgreSQL is used as the primary data store, with Drizzle ORM facilitating interaction. Database migrations ensure schema consistency.
|
||||
- **Authentication:** Secure role-based access control (RBAC) is implemented for granular permissions.
|
||||
- **Multi-tenancy:** The system supports multi-tenant operations with group and permission management.
|
||||
- **Module for Backup:** An integrated PostgreSQL backup manager allows manual and scheduled backups, with tracking in a `DATABASE_BACKUPS` table.
|
||||
- **Module for Backup:** An integrated PostgreSQL backup manager allows manual and scheduled backups, with tracking in a `DATABASE_BACKUPS` table. **PRODUCTION FIX (Août 2025)** : Correction critique du système de sauvegarde automatique en production - le service de sauvegarde n'était pas initialisé dans `index.production.ts`, empêchant la planification automatique quotidienne à 2h00. Fix appliqué avec import du service et configuration Docker complète (répertoire `/app/backups`, variables d'environnement, volumes persistants).
|
||||
- **Error Handling:** Robust error management ensures graceful degradation and informative logging, especially for production environments. API responses are logged conditionally to reduce console clutter in production.
|
||||
- **Data Synchronization:** Logic is implemented to ensure data consistency between development (in-memory storage) and production (PostgreSQL) environments, particularly for order status and relationships.
|
||||
|
||||
|
||||
Executable
+105
@@ -0,0 +1,105 @@
|
||||
#!/bin/bash
|
||||
# Script de vérification du système de sauvegarde automatique
|
||||
# Usage: ./scripts/verify-backup-system.sh
|
||||
|
||||
set -e
|
||||
|
||||
echo "🔍 VÉRIFICATION DU SYSTÈME DE SAUVEGARDE AUTOMATIQUE"
|
||||
echo "=================================================="
|
||||
|
||||
# 1. Vérifier que les containers sont en cours d'exécution
|
||||
echo "1. Vérification des containers Docker..."
|
||||
if docker-compose ps | grep -q "logiflow.*Up"; then
|
||||
echo "✅ Container LogiFlow en cours d'exécution"
|
||||
else
|
||||
echo "❌ Container LogiFlow non disponible"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if docker-compose ps | grep -q "logiflow-db.*Up"; then
|
||||
echo "✅ Container PostgreSQL en cours d'exécution"
|
||||
else
|
||||
echo "❌ Container PostgreSQL non disponible"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 2. Vérifier la connectivité à la base de données
|
||||
echo ""
|
||||
echo "2. Vérification de la connectivité à la base de données..."
|
||||
if docker-compose exec logiflow-db pg_isready -U logiflow_admin -d logiflow_db > /dev/null 2>&1; then
|
||||
echo "✅ Base de données accessible"
|
||||
else
|
||||
echo "❌ Base de données non accessible"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 3. Vérifier la présence de pg_dump dans le container
|
||||
echo ""
|
||||
echo "3. Vérification de pg_dump..."
|
||||
if docker-compose exec logiflow which pg_dump > /dev/null 2>&1; then
|
||||
echo "✅ pg_dump disponible"
|
||||
docker-compose exec logiflow pg_dump --version
|
||||
else
|
||||
echo "❌ pg_dump non disponible"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 4. Vérifier le répertoire de sauvegarde
|
||||
echo ""
|
||||
echo "4. Vérification du répertoire de sauvegarde..."
|
||||
if docker-compose exec logiflow ls -la /app/backups > /dev/null 2>&1; then
|
||||
echo "✅ Répertoire /app/backups accessible"
|
||||
echo "Contenu du répertoire de sauvegarde :"
|
||||
docker-compose exec logiflow ls -la /app/backups
|
||||
else
|
||||
echo "❌ Répertoire de sauvegarde non accessible"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 5. Vérifier la table database_backups
|
||||
echo ""
|
||||
echo "5. Vérification de la table database_backups..."
|
||||
if docker-compose exec logiflow-db psql -U logiflow_admin -d logiflow_db -c "SELECT COUNT(*) FROM database_backups;" > /dev/null 2>&1; then
|
||||
echo "✅ Table database_backups accessible"
|
||||
echo "Sauvegardes enregistrées :"
|
||||
docker-compose exec logiflow-db psql -U logiflow_admin -d logiflow_db -c "SELECT filename, created_at, backup_type, status FROM database_backups ORDER BY created_at DESC LIMIT 5;" 2>/dev/null || echo "Aucune sauvegarde trouvée"
|
||||
else
|
||||
echo "❌ Table database_backups non accessible"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 6. Vérifier les logs du service de sauvegarde
|
||||
echo ""
|
||||
echo "6. Vérification des logs du service de sauvegarde..."
|
||||
echo "Recherche du message d'initialisation du service de sauvegarde :"
|
||||
if docker-compose logs logiflow | grep -q "Backup service initialized for automatic daily backups"; then
|
||||
echo "✅ Service de sauvegarde initialisé"
|
||||
else
|
||||
echo "⚠️ Message d'initialisation non trouvé dans les logs récents"
|
||||
fi
|
||||
|
||||
if docker-compose logs logiflow | grep -q "Automatic backup scheduled"; then
|
||||
echo "✅ Planification automatique configurée"
|
||||
else
|
||||
echo "⚠️ Message de planification non trouvé dans les logs récents"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "7. Test de création d'une sauvegarde manuelle..."
|
||||
echo "Pour tester une sauvegarde manuelle, connectez-vous à l'application et utilisez l'API :"
|
||||
echo "curl -X POST http://localhost:3000/api/backups -H 'Content-Type: application/json' -d '{\"type\": \"manual\"}'"
|
||||
|
||||
echo ""
|
||||
echo "🎉 VÉRIFICATION TERMINÉE"
|
||||
echo "========================"
|
||||
echo ""
|
||||
echo "💡 INFORMATIONS IMPORTANTES :"
|
||||
echo "- Les sauvegardes automatiques sont programmées quotidiennement à 2h00"
|
||||
echo "- Les sauvegardes sont stockées dans le volume Docker 'backup_data'"
|
||||
echo "- Maximum 10 sauvegardes conservées (les plus anciennes sont supprimées automatiquement)"
|
||||
echo "- Les sauvegardes sont également enregistrées en base dans la table 'database_backups'"
|
||||
echo ""
|
||||
echo "🔧 EN CAS DE PROBLÈME :"
|
||||
echo "- Redémarrez les containers : docker-compose restart"
|
||||
echo "- Vérifiez les logs : docker-compose logs logiflow"
|
||||
echo "- Vérifiez les variables d'environnement : docker-compose config"
|
||||
@@ -41,6 +41,10 @@ app.use((req, res, next) => {
|
||||
// Import all routes for production
|
||||
import { registerRoutes } from "./routes.js";
|
||||
|
||||
// Initialize backup service for automatic backups
|
||||
import { backupService } from "./backupService.js";
|
||||
console.log('💾 [PRODUCTION] Backup service initialized for automatic daily backups');
|
||||
|
||||
async function registerProductionRoutes(app: Express): Promise<void> {
|
||||
console.log('🔧 Registering all production routes...');
|
||||
|
||||
|
||||
Reference in new issue
Block a user