Add data retention configuration and cleanup functionality

- Introduced a new `[Data_Retention]` section in `config.ini.example` to manage retention periods for various database tables, including packet stream, daily stats, and observed paths.
- Updated `mkdocs.yml` and `configuration.md` to include documentation for the new data retention settings.
- Implemented data retention cleanup methods in `mesh_graph.py`, `repeater_manager.py`, and `scheduler.py` to enforce retention policies automatically.
- Enhanced the web viewer's data cleanup logic to utilize the new retention settings, ensuring efficient database management.
This commit is contained in:
agessaman committed 2026-02-24 22:01:49 -08:00
1 parent 513d1ec65b
commit fcfde7ea33
9 files changed
+233 -8

No files matched your search

+13 -3
View File
@@ -11,6 +11,7 @@ import sys
import os
import re
from pathlib import Path
from typing import Optional
from ..utils import resolve_path
@@ -295,12 +296,21 @@ class BotIntegration:
except Exception as e:
self.bot.logger.debug(f"Error storing routing data: {e}")
def cleanup_old_data(self, days_to_keep: int = 7):
"""Clean up old packet stream data to prevent database bloat"""
def cleanup_old_data(self, days_to_keep: Optional[int] = None):
"""Clean up old packet stream data to prevent database bloat.
Uses [Data_Retention] packet_stream_retention_days when days_to_keep is not provided."""
try:
import sqlite3
import time
if days_to_keep is None:
days_to_keep = 3
if self.bot.config.has_section('Data_Retention') and self.bot.config.has_option('Data_Retention', 'packet_stream_retention_days'):
try:
days_to_keep = self.bot.config.getint('Data_Retention', 'packet_stream_retention_days')
except (ValueError, TypeError):
pass
cutoff_time = time.time() - (days_to_keep * 24 * 60 * 60)
db_path = self._get_web_viewer_db_path()