Files
workstation-config/temp-cleanup/README.md
T
2026-04-24 10:32:22 +00:00

127 lines
2.7 KiB
Markdown

# 🧹 Temp Cleanup Script
Dieses Repository enthält ein automatisiertes Cleanup-System für temporäre Dateien im Nextcloud-synchronisierten Dokumente-Ordner.
Es entfernt automatisch Dateien und leere Ordner nach 30 Tagen und sorgt so für eine saubere, schlanke Synchronisationsstruktur.
---
# 📁 Projektstruktur
```
workstation-config/
└── temp-cleanup/
├── cleanup_temp.sh
├── cleanup_temp.log
└── systemd/
└── cleanup-temp.service
```
---
# ⚙️ Zweck
Das Script bereinigt automatisch das definierte `temp`-Verzeichnis.
Ziel:
- Verhindern von Datenmüll in synchronisierten Nextcloud-Ordnern
- Automatisches Entfernen alter temporärer Dateien
- Aufräumen leerer Verzeichnisse
---
# 🚀 Ausführung des Services
Der Service wird über **systemd (User oder System Service)** ausgeführt.
## 📍 Installationspfade (Laptop)
### Script
/home/kai/workstation-config/temp-cleanup/cleanup_temp.sh
### Service Datei (im Repo)
/home/kai/workstation-config/temp-cleanup/systemd/cleanup-temp.service
### Zielort für systemd (User Service)
~/.config/systemd/user/cleanup-temp.service
👉 Die Service-Datei muss bei Änderungen manuell kopiert werden.
---
# 🔄 Service Installation / Reload
Nach Änderungen der Service-Datei:
cp ~/workstation-config/temp-cleanup/systemd/cleanup-temp.service ~/.config/systemd/user/
systemctl --user daemon-reload
systemctl --user restart cleanup-temp.service
---
# 🕒 Ausführungszeitpunkt
Der Service wird ausgeführt über systemd Trigger, z. B.:
- beim Login (User Service)
- beim Systemstart (optional System Service)
- manuell über systemctl start
---
# 📜 Logfile
Alle Aktionen werden protokolliert in:
/home/kai/cleanup_temp.log
Enthält:
- gelöschte Dateien
- gelöschte Ordner
- Zeitstempel
- Fehlerausgaben (falls vorhanden)
---
# 🧪 Manueller Test
## Script direkt ausführen
~/workstation-config/temp-cleanup/cleanup_temp.sh
## Testdateien erstellen (älter als 30 Tage simulieren)
mkdir -p ~/Dokumente/temp
touch -d "40 days ago" ~/Dokumente/temp/test_old_file.txt
## Testlauf starten
~/workstation-config/temp-cleanup/cleanup_temp.sh
## Ergebnis prüfen
ls -la ~/Dokumente/temp
cat ~/cleanup_temp.log
## Leere Ordner testen
mkdir -p ~/Dokumente/temp/old_folder
~/workstation-config/temp-cleanup/cleanup_temp.sh
---
# 🧠 Designprinzip
- Script ist portabel und läuft auf allen Workstations identisch
- Service wird bewusst nicht automatisch installiert
- Änderungen an Service-Dateien müssen manuell synchronisiert werden
- Logs bleiben lokal und werden nicht versioniert
---
# 🔄 Versionierung
git add .
git commit -m "Update cleanup system"
git push origin main
---
# 🧩 Zielbild
git clone <repo>