Automatische Synchronisation mehrerer Ordnerpaare mit inotify-basierter Echtzeit-Überwachung.
cloud-sync/
├── lib/ # Scripte
│ └── cloud-sync.sh
├── deamon/ # Systemd Services
│ ├── cloud-sync.service
│ └── cloud-sync-web.service
├── conf/ # Konfiguration
│ └── cloud-sync.conf
├── web/ # Web-Dashboard
│ ├── server.py
│ ├── requirements.txt
│ ├── templates/
│ │ └── dashboard.html
│ └── static/
│ ├── style.css
│ └── app.js
├── install.sh # Automatisches Installations-Script
├── uninstall.sh # Deinstallations-Script
└── README.md
Das automatische Installations-Script richtet alles ein:
# 1. Projekt zum Server kopieren (z.B. via rsync oder scp)
# 2. Auf dem Server ausführen:
cd /pfad/zum/kopierten/projekt/cloud-sync
sudo chmod +x install.sh
sudo ./install.shDas Script führt automatisch aus:
- ✅ Ermittlung der Server-IP-Adresse
- ✅ Installation aller Abhängigkeiten (Python, Flask, inotify-tools, rsync)
- ✅ Kopieren der Dateien nach
/usr/local/bin/cloud-sync - ✅ Einrichtung der Systemd-Services
- ✅ Konfiguration des Web-Servers (Port: 8080, alle Interfaces)
- ✅ Start aller Services
Nach der Installation:
- Dashboard erreichbar unter: http://SERVER-IP:8080 (IP wird automatisch erkannt)
- Sync-Service läuft automatisch
- Server-IP wird in
/usr/local/bin/cloud-sync/web/config.pygespeichert
Anpassung des Ports:
# Öffne das Script VOR der Installation und ändere die Zeile:
WEB_PORT="8080" # Gewünschter Port
# Die IP wird automatisch erkannt (bindet auf 0.0.0.0 = alle Interfaces)Falls du die Installation lieber Schritt für Schritt durchführen möchtest:
sudo cp -r cloud-sync /usr/local/bin/
sudo chmod +x /usr/local/bin/cloud-sync/lib/cloud-sync.shsudo cp /usr/local/bin/cloud-sync/deamon/cloud-sync.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable cloud-sync.servicesudo systemctl start cloud-sync.serviceDas Web-Dashboard bietet eine Live-Übersicht aller Sync-Jobs:
Installation:
# Python-Abhängigkeiten installieren
sudo apt-get install python3-flask # Debian/Ubuntu
# oder
sudo pip3 install flask
# Web-Service einrichten
sudo cp /usr/local/bin/cloud-sync/deamon/cloud-sync-web.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable cloud-sync-web.service
sudo systemctl start cloud-sync-web.serviceZugriff:
Dashboard ist erreichbar unter: http://SERVER-IP:8080
Features:
- ✅ Live-Status aller Sync-Jobs
- ✅ Letzte 10 Synchronisationen pro Job
- ✅ Gesamt-Statistiken (Syncs, Fehler)
- ✅ Live-Log-Anzeige
- ✅ Automatische Aktualisierung alle 2 Sekunden
Die Sync-Paare werden in conf/cloud-sync.conf definiert:
# Globale Standardwerte für alle Jobs
[DEFAULTS]
new=true # Neue Dateien synchronisieren
change=true # Änderungen synchronisieren
delete=false # Löschungen synchronisieren
# Web-Dashboard Einstellungen
[WEB-UI]
refresh=10 # Aktualisierungs-Intervall in Sekunden (Standard: 10)
# Job-spezifische Konfiguration
[JobName]
source='/pfad/zum/quellordner'
destination='/pfad/zum/zielordner'
# Optional: Überschreibe DEFAULTS für diesen Job
# new=false
# change=true
# delete=trueSync-Parameter ([DEFAULTS] und [JobName]):
| Parameter | Beschreibung | Default |
|---|---|---|
new |
Neue Dateien werden synchronisiert | true |
change |
Änderungen an bestehenden Dateien werden synchronisiert | true |
delete |
Gelöschte Dateien werden auch im Ziel gelöscht | false |
Web-UI Parameter ([WEB-UI]):
| Parameter | Beschreibung | Default |
|---|---|---|
refresh |
Dashboard-Aktualisierungsintervall in Sekunden | 10 |
[DEFAULTS]
new=true
change=true
delete=false
[WEB-UI]
refresh=10
[Videos]
source='/mnt/hdd/nas/videos'
destination='/mnt/hdd/hetzner/videos'
# Verwendet DEFAULTS
[Backups]
source='/home/user/documents'
destination='/mnt/backup/documents'
delete=true # Überschreibt DEFAULTS für diesen JobNach Änderungen an der Konfiguration Service neu starten:
sudo systemctl restart cloud-sync.serviceStatus prüfen:
sudo systemctl status cloud-sync.serviceLogs anzeigen:
sudo tail -f /usr/local/bin/cloud-sync/log/cloud-sync.log
# oder
sudo journalctl -u cloud-sync.service -fService stoppen:
sudo systemctl stop cloud-sync.serviceService neu starten:
sudo systemctl restart cloud-sync.serviceStatus prüfen:
sudo systemctl status cloud-sync-web.serviceLogs anzeigen:
sudo tail -f /usr/local/bin/cloud-sync/log/cloud-sync-web.logService neu starten:
sudo systemctl restart cloud-sync-web.serviceDashboard öffnen:
# Im Browser: http://SERVER-IP:8080
# oder lokal auf dem Server:
curl http://localhost:8080inotify-tools(für inotifywait)rsyncbash- Systemd
python3(≥ 3.7)python3-flask
Debian/Ubuntu:
# Sync-Service
sudo apt-get install inotify-tools rsync
# Web-Dashboard (optional)
sudo apt-get install python3 python3-flaskRHEL/CentOS:
# Sync-Service
sudo yum install inotify-tools rsync
# Web-Dashboard (optional)
sudo yum install python3 python3-pip
sudo pip3 install flask- Initiale Synchronisation beim Start
new=true, change=true: Alle neuen und geänderten Dateien werden synchronisiertnew=true, change=false: Nur neue Dateien, keine Updates existierendernew=false, change=true: Nur Updates existierender Dateien, keine neuennew=false, change=false: Keine initiale Sync (nur Echtzeit-Überwachung)
- Echtzeit-Überwachung: Änderungen werden sofort erkannt und verarbeitet
new=true: Neue Dateien werden kopiert (inotify: create, moved_to)change=true: Änderungen an Dateien werden kopiert (inotify: modify)delete=true: Gelöschte Dateien werden auch im Ziel entfernt (inotify: delete, moved_from)
- Flexible Konfiguration: Globale Defaults mit job-spezifischen Überschreibungen
- Multi-Job: Mehrere Sync-Paare werden parallel überwacht
- Logging: Alle Aktivitäten werden nach
/usr/local/bin/cloud-sync/log/cloud-sync.logprotokolliert
Das Web-Dashboard bietet eine komfortable Oberfläche zur Überwachung aller Sync-Jobs in Echtzeit.
Übersichtsseite:
- 📊 Service-Status und Laufzeit
- 📈 Gesamt-Statistiken (Jobs, Syncs, Fehler)
- 🔄 Automatische Aktualisierung alle 2 Sekunden
Pro Job:
- ✅ Status-Indikator (Running/Error)
- 📁 Quell- und Zielpfade
- 📊 Statistiken (Sync-Anzahl, Fehler, letzte Aktivität)
- ⚙️ Aktive Parameter (new/change/delete)
- 📄 Letzte 10 Synchronisationen mit Timestamp
Live-Log:
- 📜 Echtzeit-Anzeige der letzten 50 Log-Zeilen
- 🔄 Auto-Scroll und Auto-Refresh
Der Web-Server:
- Läuft auf Port 8080
- Parst
/usr/local/bin/cloud-sync/log/cloud-sync.login Echtzeit - Keine Änderungen am Bash-Script erforderlich
- Geringer Ressourcenverbrauch (~20-30 MB RAM)
- REST-API für eigene Integrationen
API-Endpunkte:
GET /api/status- JSON mit allen Job-InformationenGET /api/logs- Letzte 100 Log-Zeilen
Falls du Cloud-Sync vollständig entfernen möchtest:
sudo chmod +x /pfad/zum/projekt/uninstall.sh
sudo ./uninstall.shDas Script entfernt:
- Alle Services (cloud-sync und cloud-sync-web)
- Installierte Dateien in
/usr/local/bin/cloud-sync - Systemd Service-Dateien
- Log-Dateien im Projektverzeichnis
Problem: systemctl status cloud-sync.service zeigt Fehler
# Prüfe Details
journalctl -u cloud-sync.service -n 50
# Häufige Ursachen:
# 1. Falsche Zeilenumbrüche (CRLF statt LF)
sed -i 's/\r$//' /usr/local/bin/cloud-sync/lib/cloud-sync.sh
# 2. Fehlende Abhängigkeiten
sudo apt-get install inotify-tools rsync
# 3. Quellordner existiert nicht
# Prüfe Pfade in /usr/local/bin/cloud-sync/conf/cloud-sync.confProblem: http://192.168.20.123 zeigt keine Seite
# Prüfe ob Service läuft
systemctl status cloud-sync-web.service
# Prüfe Logs
tail -f /usr/local/bin/cloud-sync/log/cloud-sync-web.log
# Prüfe ob Port 80 verfügbar ist
sudo netstat -tlnp | grep :80
# Falls Port blockiert, ändere in install.sh:
WEB_PORT="8080" # Alternativer Port
# Firewall prüfen
sudo ufw status
sudo ufw allow 80/tcp # Oder gewählten PortProblem: Dashboard lädt, aber zeigt keine Jobs
# Prüfe ob cloud-sync.service läuft
systemctl status cloud-sync.service
# Prüfe Log-Datei
ls -la /usr/local/bin/cloud-sync/log/cloud-sync.log
tail -f /usr/local/bin/cloud-sync/log/cloud-sync.log
# Prüfe Konfiguration
cat /usr/local/bin/cloud-sync/conf/cloud-sync.confProblem: Port 80 kann nicht ohne root geöffnet werden
# Option 1: Verwende Port > 1024 (z.B. 8080)
# Ändere in install.sh: WEB_PORT="8080"
# Option 2: Verwende authbind oder setcap
sudo apt-get install authbind
sudo touch /etc/authbind/byport/80
sudo chmod 500 /etc/authbind/byport/80
sudo chown root:root /etc/authbind/byport/80
# Dann in cloud-sync-web.service ändern:
# ExecStart=authbind --deep /usr/bin/python3 ...Das Projekt muss nach /usr/local/bin/cloud-sync installiert werden, damit die Service-Datei und relativen Pfade korrekt funktionieren.