Backup & Restore Mechanisms
Relevant source files
The following files were used as context for generating this wiki page:
Backup and Restore mechanisms ensure data persistence and recovery for the Telegram Summary Bot ecosystem. The system supports high-level data exports through the MiniApp control panel and configuration persistence via environment files. This functionality protects administrative settings, channel configurations, and member data from accidental loss.
Sources: README.md:195-198
Data Export and Recovery
The system provides tools for manual and automated data preservation. Administrators use the MiniApp dashboard to perform one-click exports of the underlying database.
Export Formats
The system supports two primary formats for data preservation:
- JSON Export: Generates a portable JavaScript Object Notation file containing system data.
- SQL Export: Produces a structured Query Language file for direct database restoration.
Sources: README.md:196
Restore Workflow
The restoration process allows for a full database recovery using previously exported files. This ensures that channel settings, custom categories, and moderation rules remain intact after a system migration or failure.
Sources: README.md:197
The diagram shows the administrative workflow for moving data between the live system and external backup files.
Sources: README.md:195-198
Configuration Persistence
The bot relies on environment variables for operational state. Persistence of these settings is managed through local files and deployment configurations.
Environment Management
The .env file stores critical operational tokens and limits. While the bot.py script maintains a temporary in-memory cache of messages, the primary bot configuration is persisted via the environment.
| Component | Persistence Method | File Reference |
|---|---|---|
| Bot Token | Environment Variable | .env |
| Message Buffer | In-Memory Deque | bot.py |
| System Logic | Container Image | Dockerfile |
Sources: bot.py:20-24, README.md:31-35
Memory Limits
To prevent resource exhaustion during operation, the bot limits the amount of data held in the temporary message cache.
MAX_STORED_MESSAGES = int(os.getenv("MAX_STORED_MESSAGES", "100"))
chat_messages: dict[int, deque[str]] = defaultdict(lambda: deque(maxlen=MAX_STORED_MESSAGES))
Deployment Resilience
Backup and restore operations are supported by resilient deployment strategies. The system uses containerization and service managers to maintain the availability of the backup interfaces.
Docker and Volume Support
When deployed via Docker, the --restart unless-stopped flag ensures the bot service remains active to handle management tasks. Although the minimal bot uses in-memory storage for recent messages, the full MiniApp suite utilizes a MySQL backend for persistent storage of management data.
Sources: README.md:52, README.md:214
The sequence diagram illustrates how the service manager and database interaction maintains system state across restarts.
Sources: README.md:65-75, README.md:214
Security of Backups
The system includes security layers to protect backup data and administrative access.
- Role-Based Access: Only users with Super Admin or Admin roles can access the export and restore functions.
- Audit Logs: The system records backup and restore actions in the full audit log to track data movements.
- 2FA Protection: Two-Factor Authentication secures the dashboard where backup tools are located.
Sources: README.md:190-193
The Backup & Restore mechanisms provide a dual-layer protection strategy. For the local bot, persistence is focused on environment configuration and process management. For the enterprise management suite, it offers comprehensive database exports and imports to ensure zero data loss across unlimited channels and groups.