Immich Backup Monitoring Integration #3

Open
opened 2025-10-29 19:44:53 -07:00 by peterwood · 0 comments
Owner

Originally created by @acedanger on GitHub (May 27, 2025).

Immich Backup Monitoring Integration

Issue Summary

Integrate the Telegram bot with the Immich backup system to provide monitoring and status reporting for both database and upload directory backups with B2 cloud storage integration.

Description

Develop Telegram bot commands that interface with the Immich backup scripts to monitor database backups, upload directory synchronization, and B2 cloud storage status. The Immich system handles both local backups and cloud storage replication.

Requirements

Command Implementation

  • /immich_status - Show current Immich backup status
  • /immich_last - Display last backup summary
  • /immich_db - Database backup status
  • /immich_uploads - Upload directory backup status
  • /immich_b2 - B2 cloud storage sync status
  • /immich_logs - Show recent backup logs
  • /immich_health - Run health check on backups

Advanced Commands (Admin only)

  • /immich_backup_now - Trigger immediate backup
  • /immich_validate - Run backup validation
  • /immich_sync_b2 - Force B2 sync operation
  • /immich_restore - List available backups for restoration

Integration Points

Existing Scripts to Interface With

# Main Immich backup script
/home/acedanger/shell/immich/backup-immich.sh

# Backup validation script
/home/acedanger/shell/immich/validate-immich-backups.sh

# Restoration script (template ready)
/home/acedanger/shell/immich/restore-immich.sh

Log Files to Monitor

# Centralized logging
/home/acedanger/shell/logs/immich-backup.log
/home/acedanger/shell/logs/immich-validation.log
/home/acedanger/shell/logs/immich-restore.log

# B2 sync logs (when implemented)
/home/acedanger/shell/logs/immich-b2-sync.log

Backup Directories

# Local backup storage
/home/acedanger/shell/immich_backups/

# B2 cloud storage path
# immich-backups/ (configured in B2 bucket)

Technical Implementation

Status Monitoring

def get_immich_status():
    """Parse logs to determine current Immich backup status"""
    # Check latest backup completion
    # Verify database and uploads status
    # Check B2 sync status
    # Return comprehensive status

def get_last_immich_backup():
    """Get summary of most recent backup operation"""
    # Parse latest log entries
    # Extract database backup info
    # Extract upload directory sync info
    # Format for display

Component-Specific Monitoring

def get_immich_db_status():
    """Check database backup status specifically"""
    # Parse database backup logs
    # Check backup file integrity
    # Return database-specific status

def get_immich_uploads_status():
    """Check upload directory backup status"""
    # Check upload directory sync
    # Verify file counts and sizes
    # Return upload-specific status

def get_immich_b2_status():
    """Check B2 cloud storage sync status"""
    # Parse B2 sync logs
    # Check cloud storage status
    # Return B2-specific information

Health Monitoring

def run_immich_health_check():
    """Execute comprehensive health check"""
    # Run validate-immich-backups.sh
    # Check backup freshness
    # Verify B2 connectivity
    # Return health assessment

Command Examples

/immich_status

🟢 Immich Backup Status

Database Backup:
├── Status: ✅ Completed
├── Last Run: 2025-05-27 02:30:15
├── Size: 245 MB
└── Files: 1 SQL dump

Upload Directory:
├── Status: ✅ Synced
├── Last Sync: 2025-05-27 02:45:22
├── Size: 12.4 GB
└── Files: 2,847 photos/videos

B2 Cloud Storage:
├── Status: ✅ Synced
├── Last Upload: 2025-05-27 02:50:11
└── Storage Used: 12.6 GB

/immich_db

🗄️ Immich Database Status

Latest Backup: 2025-05-27 02:30:15
Database Size: 245 MB
Backup Location: /home/acedanger/shell/immich_backups/
B2 Cloud: ✅ Synced

Health: ✅ Healthy
├── Backup Fresh: ✅ (4 hours ago)
├── File Integrity: ✅ Verified
└── Cloud Sync: ✅ Up to date

/immich_uploads

📁 Immich Uploads Status

Directory: /mnt/immich/uploads
Total Size: 12.4 GB
File Count: 2,847 items
Last Modified: 2025-05-27 01:15:33

Backup Status:
├── Local Backup: ✅ Complete
├── B2 Sync: ✅ Synced
└── Integrity: ✅ Verified

Recent Activity:
├── New Files: 3 (last 24h)
├── Size Change: +47 MB
└── Last Backup: 2 hours ago

/immich_health

🔍 Immich Health Check

Database Backup: ✅ PASS
├── Freshness: ✅ (4 hours old)
├── Integrity: ✅ Verified
└── Size: 245 MB (normal)

Upload Directory: ✅ PASS
├── Sync Status: ✅ Complete
├── File Count: 2,847 (expected)
└── Size: 12.4 GB (normal)

B2 Cloud Storage: ✅ PASS
├── Connectivity: ✅ Online
├── Sync Status: ✅ Current
└── Storage Usage: 12.6 GB

Overall: ✅ All systems healthy

File Structure

telegram/bot/commands/
├── immich/
│   ├── __init__.py
│   ├── status.py           # Status monitoring commands
│   ├── database.py         # Database-specific commands
│   ├── uploads.py          # Upload directory commands
│   ├── b2_storage.py       # B2 cloud storage commands
│   └── health.py           # Health check commands
└── utils/
    ├── immich_parser.py    # Log parsing utilities
    ├── b2_utils.py         # B2 integration utilities
    └── file_utils.py       # File system utilities

B2 Integration Considerations

  • Monitor B2 sync status and bandwidth usage
  • Check B2 authentication and bucket access
  • Report cloud storage usage and costs (if available)
  • Handle B2 sync failures and retries

Security Considerations

  • Secure B2 credentials handling
  • Safe script execution with proper error handling
  • Admin-only access to backup triggers
  • Input validation for all parameters

Success Criteria

  • Database backup monitoring functional
  • Upload directory monitoring working
  • B2 cloud storage integration complete
  • Health checks comprehensive
  • Log parsing accurate
  • Admin controls secured

Dependencies

  • Depends on: Issue #01 (Core Infrastructure)
  • B2 SDK/CLI tools for cloud storage integration
  • File system monitoring capabilities
  • PostgreSQL utilities for database operations

Estimated Effort

Time: 2-3 days
Complexity: Medium

Testing Requirements

  • Test with various backup states
  • Verify B2 integration functionality
  • Test database backup validation
  • Validate upload directory monitoring
  • Test error handling for network issues
  • Performance testing with large upload directories

Notes

The Immich backup system focuses on database and file synchronization with cloud storage. The integration should handle both local and cloud backup aspects, providing visibility into the complete backup pipeline.

Originally created by @acedanger on GitHub (May 27, 2025). # Immich Backup Monitoring Integration ## Issue Summary Integrate the Telegram bot with the Immich backup system to provide monitoring and status reporting for both database and upload directory backups with B2 cloud storage integration. ## Description Develop Telegram bot commands that interface with the Immich backup scripts to monitor database backups, upload directory synchronization, and B2 cloud storage status. The Immich system handles both local backups and cloud storage replication. ## Requirements ### Command Implementation - [ ] `/immich_status` - Show current Immich backup status - [ ] `/immich_last` - Display last backup summary - [ ] `/immich_db` - Database backup status - [ ] `/immich_uploads` - Upload directory backup status - [ ] `/immich_b2` - B2 cloud storage sync status - [ ] `/immich_logs` - Show recent backup logs - [ ] `/immich_health` - Run health check on backups ### Advanced Commands (Admin only) - [ ] `/immich_backup_now` - Trigger immediate backup - [ ] `/immich_validate` - Run backup validation - [ ] `/immich_sync_b2` - Force B2 sync operation - [ ] `/immich_restore` - List available backups for restoration ### Integration Points #### Existing Scripts to Interface With ```bash # Main Immich backup script /home/acedanger/shell/immich/backup-immich.sh # Backup validation script /home/acedanger/shell/immich/validate-immich-backups.sh # Restoration script (template ready) /home/acedanger/shell/immich/restore-immich.sh ``` #### Log Files to Monitor ```bash # Centralized logging /home/acedanger/shell/logs/immich-backup.log /home/acedanger/shell/logs/immich-validation.log /home/acedanger/shell/logs/immich-restore.log # B2 sync logs (when implemented) /home/acedanger/shell/logs/immich-b2-sync.log ``` #### Backup Directories ```bash # Local backup storage /home/acedanger/shell/immich_backups/ # B2 cloud storage path # immich-backups/ (configured in B2 bucket) ``` ### Technical Implementation #### Status Monitoring ```python def get_immich_status(): """Parse logs to determine current Immich backup status""" # Check latest backup completion # Verify database and uploads status # Check B2 sync status # Return comprehensive status def get_last_immich_backup(): """Get summary of most recent backup operation""" # Parse latest log entries # Extract database backup info # Extract upload directory sync info # Format for display ``` #### Component-Specific Monitoring ```python def get_immich_db_status(): """Check database backup status specifically""" # Parse database backup logs # Check backup file integrity # Return database-specific status def get_immich_uploads_status(): """Check upload directory backup status""" # Check upload directory sync # Verify file counts and sizes # Return upload-specific status def get_immich_b2_status(): """Check B2 cloud storage sync status""" # Parse B2 sync logs # Check cloud storage status # Return B2-specific information ``` #### Health Monitoring ```python def run_immich_health_check(): """Execute comprehensive health check""" # Run validate-immich-backups.sh # Check backup freshness # Verify B2 connectivity # Return health assessment ``` ### Command Examples #### `/immich_status` ``` 🟢 Immich Backup Status Database Backup: ├── Status: ✅ Completed ├── Last Run: 2025-05-27 02:30:15 ├── Size: 245 MB └── Files: 1 SQL dump Upload Directory: ├── Status: ✅ Synced ├── Last Sync: 2025-05-27 02:45:22 ├── Size: 12.4 GB └── Files: 2,847 photos/videos B2 Cloud Storage: ├── Status: ✅ Synced ├── Last Upload: 2025-05-27 02:50:11 └── Storage Used: 12.6 GB ``` #### `/immich_db` ``` 🗄️ Immich Database Status Latest Backup: 2025-05-27 02:30:15 Database Size: 245 MB Backup Location: /home/acedanger/shell/immich_backups/ B2 Cloud: ✅ Synced Health: ✅ Healthy ├── Backup Fresh: ✅ (4 hours ago) ├── File Integrity: ✅ Verified └── Cloud Sync: ✅ Up to date ``` #### `/immich_uploads` ``` 📁 Immich Uploads Status Directory: /mnt/immich/uploads Total Size: 12.4 GB File Count: 2,847 items Last Modified: 2025-05-27 01:15:33 Backup Status: ├── Local Backup: ✅ Complete ├── B2 Sync: ✅ Synced └── Integrity: ✅ Verified Recent Activity: ├── New Files: 3 (last 24h) ├── Size Change: +47 MB └── Last Backup: 2 hours ago ``` #### `/immich_health` ``` 🔍 Immich Health Check Database Backup: ✅ PASS ├── Freshness: ✅ (4 hours old) ├── Integrity: ✅ Verified └── Size: 245 MB (normal) Upload Directory: ✅ PASS ├── Sync Status: ✅ Complete ├── File Count: 2,847 (expected) └── Size: 12.4 GB (normal) B2 Cloud Storage: ✅ PASS ├── Connectivity: ✅ Online ├── Sync Status: ✅ Current └── Storage Usage: 12.6 GB Overall: ✅ All systems healthy ``` ### File Structure ``` telegram/bot/commands/ ├── immich/ │ ├── __init__.py │ ├── status.py # Status monitoring commands │ ├── database.py # Database-specific commands │ ├── uploads.py # Upload directory commands │ ├── b2_storage.py # B2 cloud storage commands │ └── health.py # Health check commands └── utils/ ├── immich_parser.py # Log parsing utilities ├── b2_utils.py # B2 integration utilities └── file_utils.py # File system utilities ``` ### B2 Integration Considerations - Monitor B2 sync status and bandwidth usage - Check B2 authentication and bucket access - Report cloud storage usage and costs (if available) - Handle B2 sync failures and retries ### Security Considerations - Secure B2 credentials handling - Safe script execution with proper error handling - Admin-only access to backup triggers - Input validation for all parameters ### Success Criteria - [ ] Database backup monitoring functional - [ ] Upload directory monitoring working - [ ] B2 cloud storage integration complete - [ ] Health checks comprehensive - [ ] Log parsing accurate - [ ] Admin controls secured ## Dependencies - Depends on: Issue #01 (Core Infrastructure) - B2 SDK/CLI tools for cloud storage integration - File system monitoring capabilities - PostgreSQL utilities for database operations ## Estimated Effort **Time**: 2-3 days **Complexity**: Medium ## Testing Requirements - [ ] Test with various backup states - [ ] Verify B2 integration functionality - [ ] Test database backup validation - [ ] Validate upload directory monitoring - [ ] Test error handling for network issues - [ ] Performance testing with large upload directories ## Notes The Immich backup system focuses on database and file synchronization with cloud storage. The integration should handle both local and cloud backup aspects, providing visibility into the complete backup pipeline.
peterwood added the enhancement label 2025-10-29 19:44:53 -07:00
Sign in to join this conversation.