ids.alfacom.it/extracted_idf/GUIDA_MARIADB_CLEANUP.md
marco370 0bfe3258b5 Saved progress at the end of the loop
Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 1c71ce6e-1a3e-4f53-bb5d-77cdd22b8ea3
2025-11-11 09:15:10 +00:00

194 lines
4.4 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 🚀 GUIDA MARIADB - PULIZIA IP DATABASE
## ✅ PROBLEMA RISOLTO
**Errore MariaDB**: Sintassi delimiter non riconosciuta
**Soluzione**: File SQL specifico per MariaDB con `DELIMITER $$`
---
## 🛠️ INSTALLAZIONE RAPIDA
### 1. Connettiti al database MariaDB:
```bash
mysql -h TUO_SERVER_IP -u USERNAME -p DATABASE_NAME
```
### 2. Esegui il file SQL per MariaDB:
```bash
# Da command line:
mysql -h SERVER_IP -u USERNAME -p DATABASE_NAME < cleanup_ddos_ips_mariadb.sql
# Oppure all'interno di mysql:
SOURCE cleanup_ddos_ips_mariadb.sql;
```
### 3. Verifica installazione:
```sql
SHOW PROCEDURE STATUS WHERE Db = DATABASE() AND Name LIKE 'cleanup%';
```
---
## 🎯 COMANDI RAPIDI DISPONIBILI
### ⚡ Pulizie Ultra-Rapide:
```sql
-- Simulazioni (dry run):
CALL cleanup_1h_dry(); -- Test pulizia 1 ora
CALL cleanup_12h_dry(); -- Test pulizia 12 ore
CALL cleanup_24h_dry(); -- Test pulizia 24 ore
-- Pulizie reali:
CALL cleanup_1h(); -- Pulisci IP > 1 ora
CALL cleanup_12h(); -- Pulisci IP > 12 ore
CALL cleanup_24h(); -- Pulisci IP > 24 ore
```
### 🔧 Comandi Completi:
```sql
-- Pulizie orarie personalizzate:
CALL cleanup_ddos_ips_hours_fixed(6, 'ddos_detect_v03', TRUE); -- Dry run 6h
CALL cleanup_ddos_ips_hours_fixed(8, 'ddos_detect_v03', FALSE); -- Pulizia 8h
-- Pulizie basate su giorni:
CALL cleanup_ddos_ips_fixed(3, 'ddos_detect_v03', TRUE); -- Dry run 3 giorni
CALL cleanup_ddos_ips_fixed(7, 'ddos_detect_v03', FALSE); -- Pulizia 7 giorni
```
---
## 📊 VERIFICA RISULTATI
### 1. Controlla log recenti:
```sql
SELECT * FROM ip_cleanup_log
WHERE operation_time >= DATE_SUB(NOW(), INTERVAL 1 HOUR)
ORDER BY operation_time DESC
LIMIT 5;
```
### 2. Statistiche IP per lista:
```sql
SELECT
list_name,
COUNT(*) as total_ips,
MIN(retrieved_at) as oldest_ip,
MAX(retrieved_at) as newest_ip
FROM ip_list
GROUP BY list_name;
```
### 3. IP vecchi da pulire:
```sql
-- IP più vecchi di 1 ora
SELECT COUNT(*) as ip_1h_old
FROM ip_list
WHERE list_name = 'ddos_detect_v03'
AND retrieved_at < DATE_SUB(NOW(), INTERVAL 1 HOUR);
-- IP più vecchi di 12 ore
SELECT COUNT(*) as ip_12h_old
FROM ip_list
WHERE list_name = 'ddos_detect_v03'
AND retrieved_at < DATE_SUB(NOW(), INTERVAL 12 HOUR);
```
---
## 📈 OUTPUT ESEMPI
### ✅ Successo Dry Run:
```
🔍 DRY RUN ORARIO: Verrebbero rimossi 245 IP dalla lista ddos_detect_v03 (>1h)
```
### ✅ Successo Pulizia:
```
✅ PULIZIA ORARIA COMPLETATA: Rimossi 245 IP dalla lista ddos_detect_v03 (>1h)
```
### Nessuna Pulizia:
```
NESSUNA PULIZIA ORARIA NECESSARIA: Tutti gli IP in ddos_detect_v03 sono più recenti di 1 ore
```
---
## 🔄 WORKFLOW SUGGERITO
### 1. Test Iniziale:
```sql
-- Vedi quanti IP hai
SELECT list_name, COUNT(*) FROM ip_list GROUP BY list_name;
-- Test dry run per vedere cosa succede
CALL cleanup_1h_dry();
```
### 2. Prima Pulizia:
```sql
-- Pulizia conservativa di 24 ore
CALL cleanup_24h();
-- Verifica risultato
SELECT * FROM ip_cleanup_log WHERE operation_time >= DATE_SUB(NOW(), INTERVAL 10 MINUTE);
```
### 3. Pulizie Regolari:
```sql
-- Pulizia quotidiana automatica (più aggressiva)
CALL cleanup_12h();
-- Pulizia settimanale completa
CALL cleanup_ddos_ips_fixed(7, 'ddos_detect_v03', FALSE);
```
---
## 🛡️ SICUREZZA
-**Transazioni**: Rollback automatico su errori
-**Logging**: Ogni operazione tracciata
-**Dry Run**: Test sempre prima di cancellare
-**Backup**: Fai backup prima di pulizie massive
---
## 🐛 TROUBLESHOOTING
### Errore "Table doesn't exist":
```sql
-- Verifica tabelle esistenti
SHOW TABLES LIKE '%ip%';
SHOW TABLES LIKE '%log%';
```
### Procedure non trovata:
```sql
-- Lista tutte le procedure
SHOW PROCEDURE STATUS WHERE Db = DATABASE();
```
### Nessun IP cancellato:
```sql
-- Verifica permessi DELETE
SHOW GRANTS FOR CURRENT_USER();
-- Test query manuale
SELECT COUNT(*) FROM ip_list
WHERE list_name = 'ddos_detect_v03'
AND retrieved_at < DATE_SUB(NOW(), INTERVAL 1 HOUR);
```
---
## 🎯 COMANDI PREFERITI
```sql
-- I 3 comandi che userai di più:
CALL cleanup_1h_dry(); -- Test veloce
CALL cleanup_12h(); -- Pulizia normale
CALL cleanup_24h_dry(); -- Verifica pulizia giornaliera
```
💡 **Ora dovrebbe funzionare perfettamente con MariaDB!** 🚀