pointcab_webexport/scripts/db-check.sh

80 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
# PointCab Webexport Server - Datenbank-Prüfungsscript
# Farben
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
DB_NAME="pointcab_db"
DB_USER="pointcab_user"
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}PointCab Webexport - Datenbank-Prüfung${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
# Root-Check
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}Bitte als Root ausführen: sudo ./db-check.sh${NC}"
exit 1
fi
echo -e "${YELLOW}[1/6] PostgreSQL Status...${NC}"
if systemctl is-active --quiet postgresql; then
echo -e "${GREEN}✓ PostgreSQL läuft${NC}"
else
echo -e "${RED}✗ PostgreSQL läuft NICHT${NC}"
exit 1
fi
echo -e "\n${YELLOW}[2/6] Datenbank-Verbindung prüfen...${NC}"
if sudo -u postgres psql -d $DB_NAME -c "SELECT 1" > /dev/null 2>&1; then
echo -e "${GREEN}✓ Verbindung zu $DB_NAME erfolgreich${NC}"
else
echo -e "${RED}✗ Verbindung zu $DB_NAME fehlgeschlagen${NC}"
exit 1
fi
echo -e "\n${YELLOW}[3/6] Benutzer prüfen...${NC}"
USER_EXISTS=$(sudo -u postgres psql -tAc "SELECT 1 FROM pg_roles WHERE rolname='$DB_USER'")
if [ "$USER_EXISTS" = "1" ]; then
echo -e "${GREEN}✓ Benutzer $DB_USER existiert${NC}"
else
echo -e "${RED}✗ Benutzer $DB_USER nicht gefunden${NC}"
fi
echo -e "\n${YELLOW}[4/6] Schema prüfen...${NC}"
echo -e "${YELLOW}Tabellen:${NC}"
sudo -u postgres psql -d $DB_NAME -c "\dt" 2>/dev/null || echo "Keine Tabellen gefunden"
echo -e "\n${YELLOW}project-Tabelle Schema:${NC}"
sudo -u postgres psql -d $DB_NAME -c "\d project" 2>/dev/null || echo "Tabelle 'project' nicht gefunden"
echo -e "\n${YELLOW}[5/6] htmlfilename Nullable-Status prüfen...${NC}"
NULLABLE=$(sudo -u postgres psql -d $DB_NAME -tAc "SELECT is_nullable FROM information_schema.columns WHERE table_name='project' AND column_name='htmlfilename';")
if [ "$NULLABLE" = "YES" ]; then
echo -e "${GREEN}✓ htmlfilename ist nullable (korrekt)${NC}"
else
echo -e "${RED}✗ htmlfilename ist NICHT nullable - Multi-HTML funktioniert nicht!${NC}"
echo -e "${YELLOW}Fix: ALTER TABLE project ALTER COLUMN htmlfilename DROP NOT NULL;${NC}"
fi
echo -e "\n${YELLOW}[6/6] Statistiken...${NC}"
echo -e "${YELLOW}Anzahl Projekte:${NC}"
sudo -u postgres psql -d $DB_NAME -tAc "SELECT COUNT(*) FROM project;" 2>/dev/null || echo "0"
echo -e "\n${YELLOW}Datenbank-Größe:${NC}"
sudo -u postgres psql -tAc "SELECT pg_size_pretty(pg_database_size('$DB_NAME'));"
echo -e "\n${YELLOW}Abgelaufene Projekte:${NC}"
sudo -u postgres psql -d $DB_NAME -c "SELECT id, name, shareid, expirydate FROM project WHERE expirydate < NOW();" 2>/dev/null || echo "Keine abgelaufenen Projekte"
echo -e "\n${YELLOW}Alle Datenbanken:${NC}"
sudo -u postgres psql -c "\l"
echo ""
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}Datenbank-Prüfung abgeschlossen!${NC}"
echo -e "${GREEN}========================================${NC}"