Files
HomeAudit/cleanup_nextcloud_logs.sh
admin 45363040f3 feat: Complete infrastructure cleanup phase documentation and status updates
## Major Infrastructure Milestones Achieved

###  Service Migrations Completed
- Jellyfin: Successfully migrated to Docker Swarm with latest version
- Vaultwarden: Running in Docker Swarm on OMV800 (eliminated duplicate)
- Nextcloud: Operational with database optimization and cron setup
- Paperless services: Both NGX and AI running successfully

### 🚨 Duplicate Service Analysis Complete
- Identified MariaDB conflict (OMV800 Swarm vs lenovo410 standalone)
- Identified Vaultwarden duplication (now resolved)
- Documented PostgreSQL and Redis consolidation opportunities
- Mapped monitoring stack optimization needs

### 🏗️ Infrastructure Status Documentation
- Updated README with current cleanup phase status
- Enhanced Service Analysis with duplicate service inventory
- Updated Quick Start guide with immediate action items
- Documented current container distribution across 6 nodes

### 📋 Action Plan Documentation
- Phase 1: Immediate service conflict resolution (this week)
- Phase 2: Service migration and load balancing (next 2 weeks)
- Phase 3: Database consolidation and optimization (future)

### 🔧 Current Infrastructure Health
- Docker Swarm: All 6 nodes operational and healthy
- Caddy Reverse Proxy: Fully operational with SSL certificates
- Storage: MergerFS healthy, local storage for databases
- Monitoring: Prometheus + Grafana + Uptime Kuma operational

### 📊 Container Distribution Status
- OMV800: 25+ containers (needs load balancing)
- lenovo410: 9 containers (cleanup in progress)
- fedora: 1 container (ready for additional services)
- audrey: 4 containers (well-balanced, monitoring hub)
- lenovo420: 7 containers (balanced, can assist)
- surface: 9 containers (specialized, reverse proxy)

### 🎯 Next Steps
1. Remove lenovo410 MariaDB (eliminate port 3306 conflict)
2. Clean up lenovo410 Vaultwarden (256MB space savings)
3. Verify no service conflicts exist
4. Begin service migration from OMV800 to fedora/audrey

Status: Infrastructure 99% complete, entering cleanup and optimization phase
2025-09-01 16:50:37 -04:00

98 lines
3.4 KiB
Bash
Executable File

#!/bin/bash
# Nextcloud Log Cleanup Script
# Cleans up old log files to free up disk space
# Created: $(date)
set -e
echo "=== Nextcloud Log Cleanup Script ==="
echo ""
# Get container ID
echo "Getting Nextcloud container ID..."
CONTAINER_ID=$(ssh root@omv800 "docker ps -q -f name=nextcloud" | head -1)
if [ -z "$CONTAINER_ID" ]; then
echo "❌ Nextcloud container not found"
exit 1
fi
echo "✅ Container found: $CONTAINER_ID"
# Check current log files and sizes
echo ""
echo "Current log files and sizes:"
ssh root@omv800 "docker exec -u 33 $CONTAINER_ID find /var/www/html/data/ -name '*.log*' -type f -exec ls -lah {} \;"
# Calculate total size before cleanup
echo ""
echo "Calculating total log size before cleanup..."
TOTAL_SIZE_BEFORE=$(ssh root@omv800 "docker exec -u 33 $CONTAINER_ID find /var/www/html/data/ -name '*.log*' -type f -exec du -ch {} + | tail -1 | cut -f1")
echo "Total log size before cleanup: $TOTAL_SIZE_BEFORE"
# Backup current log before cleanup (optional)
echo ""
echo "Creating backup of current log..."
ssh root@omv800 "docker exec -u 33 $CONTAINER_ID cp /var/www/html/data/nextcloud.log /var/www/html/data/nextcloud.log.backup.$(date +%Y%m%d_%H%M%S)"
# Clean up old log files
echo ""
echo "Cleaning up old log files..."
# Remove old rotated logs (keep only current log)
echo "Removing old rotated log files..."
ssh root@omv800 "docker exec -u 33 $CONTAINER_ID find /var/www/html/data/ -name '*.log.[0-9]*' -type f -delete"
# Clear current log file content (keep file but empty it)
echo "Clearing current log file content..."
ssh root@omv800 "docker exec -u 33 $CONTAINER_ID truncate -s 0 /var/www/html/data/nextcloud.log"
# Check if there are any other large log files
echo "Checking for other large log files..."
ssh root@omv800 "docker exec -u 33 $CONTAINER_ID find /var/www/html/data/ -name '*.log*' -type f -size +10M -exec ls -lah {} \;"
# Verify cleanup
echo ""
echo "Verifying cleanup..."
ssh root@omv800 "docker exec -u 33 $CONTAINER_ID find /var/www/html/data/ -name '*.log*' -type f -exec ls -lah {} \;"
# Calculate total size after cleanup
echo ""
echo "Calculating total log size after cleanup..."
TOTAL_SIZE_AFTER=$(ssh root@omv800 "docker exec -u 33 $CONTAINER_ID find /var/www/html/data/ -name '*.log*' -type f -exec du -ch {} + | tail -1 | cut -f1")
echo "Total log size after cleanup: $TOTAL_SIZE_AFTER"
# Check available disk space
echo ""
echo "Checking available disk space on data directory..."
ssh root@omv800 "df -h /srv/dev-disk-by-uuid-0f772f0b-917d-4337-a3c5-5cc5d3badac9/nextcloud-db"
# Set up log rotation for future
echo ""
echo "Setting up log rotation configuration..."
ssh root@omv800 "docker exec -u 33 $CONTAINER_ID cat > /var/www/html/data/.logrotate.conf << 'EOF'
/var/www/html/data/nextcloud.log {
daily
rotate 7
compress
delaycompress
missingok
notifempty
create 644 www-data www-data
postrotate
/usr/bin/docker exec -u 33 $CONTAINER_ID php /var/www/html/occ log:rotate
endscript
}
EOF"
echo ""
echo "=== Log Cleanup Complete ==="
echo "✅ Old log files removed"
echo "✅ Current log cleared"
echo "✅ Log rotation configured"
echo ""
echo "To monitor log growth in the future:"
echo " ssh root@omv800 'docker exec -u 33 $CONTAINER_ID du -sh /var/www/html/data/*.log*'"
echo ""
echo "To manually rotate logs:"
echo " ssh root@omv800 'docker exec -u 33 $CONTAINER_ID php /var/www/html/occ log:rotate'"