weekly-maintenance.sh
1 #!/usr/bin/env bash 2 3 # Weekly Maintenance Script 4 # Runs weekly maintenance tasks including CLAUDE.md optimization 5 # 6 # Usage: 7 # ./scripts/weekly-maintenance.sh 8 # 9 # Add to crontab: 10 # 0 2 * * 0 cd /home/jason/SyncThing.Code/333Method && ./scripts/weekly-maintenance.sh >> logs/weekly-maintenance.log 2>&1 11 12 set -euo pipefail 13 14 # Colors for output 15 RED='\033[0;31m' 16 GREEN='\033[0;32m' 17 YELLOW='\033[1;33m' 18 NC='\033[0m' # No Color 19 20 # Get script directory 21 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 22 PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" 23 24 # Change to project directory 25 cd "$PROJECT_ROOT" 26 27 echo -e "${GREEN}=== Weekly Maintenance - $(date) ===${NC}\n" 28 29 # Note: Scripts that need .env will load it themselves using dotenv 30 # We don't need to export it here since npm scripts handle it 31 32 # 1. Analyze CLAUDE.md for duplication 33 echo -e "${YELLOW}1. Analyzing CLAUDE.md for duplication...${NC}" 34 if npm run maint:claude; then 35 echo -e "${GREEN}✓ CLAUDE.md analysis complete${NC}\n" 36 else 37 echo -e "${RED}✗ CLAUDE.md analysis failed${NC}\n" 38 fi 39 40 # 2. Run security audit 41 echo -e "${YELLOW}2. Running security audit...${NC}" 42 if npm run security:audit; then 43 echo -e "${GREEN}✓ Security audit complete${NC}\n" 44 else 45 echo -e "${RED}✗ Security audit found issues${NC}\n" 46 fi 47 48 # 3. Database maintenance 49 echo -e "${YELLOW}3. Running database maintenance...${NC}" 50 if npm run maint:db; then 51 echo -e "${GREEN}✓ Database maintenance complete${NC}\n" 52 else 53 echo -e "${RED}✗ Database maintenance failed${NC}\n" 54 fi 55 56 # 4. Clean up old analysis reports (keep last 4 weeks) 57 echo -e "${YELLOW}4. Cleaning up old analysis reports...${NC}" 58 if [ -d .claude-analysis ]; then 59 find .claude-analysis -name "analysis-*.md" -mtime +28 -delete 60 echo -e "${GREEN}✓ Old analysis reports cleaned up${NC}\n" 61 fi 62 63 # 5. Report disk usage 64 echo -e "${YELLOW}5. Disk usage report:${NC}" 65 du -sh db/ screenshots/ .claude-analysis/ .security-reports/ 2>/dev/null || true 66 echo "" 67 68 echo -e "${GREEN}=== Weekly Maintenance Complete ===${NC}"