Archivierung automatisch am 2025-06-25 20:42:36
This commit is contained in:
60
testworm/commit-wrapper.sh
Normal file
60
testworm/commit-wrapper.sh
Normal file
@ -0,0 +1,60 @@
|
||||
### commit-wrapper.sh (für Cron)
|
||||
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
LOGFILE="archiv.log"
|
||||
TIMESTAMP() { date '+%Y-%m-%d %H:%M:%S'; }
|
||||
|
||||
log() {
|
||||
echo "[$(TIMESTAMP)] $1" | tee -a "$LOGFILE"
|
||||
}
|
||||
|
||||
RESTORE_SCRIPT="./restore-archiv.sh"
|
||||
|
||||
log "➔ Starte Archivierungslauf (cron-tauglich, rekursiv)..."
|
||||
|
||||
# 1. Dateien rekursiv aus Neu nach Archiv kopieren, falls sie nicht existieren
|
||||
find Neu/ -type f | while read -r file; do
|
||||
relative_path="${file#Neu/}"
|
||||
target="Archiv/$relative_path"
|
||||
|
||||
if [ -e "$target" ]; then
|
||||
log "⚠️ Datei '$relative_path' existiert bereits im Archiv. Übersprungen."
|
||||
continue
|
||||
fi
|
||||
|
||||
mkdir -p "$(dirname "$target")"
|
||||
cp "$file" "$target"
|
||||
log "✅ '$file' nach '$target' kopiert."
|
||||
rm "$file"
|
||||
log "🛋 '$file' gelöscht."
|
||||
|
||||
done
|
||||
|
||||
# 2. Aufräumen leerer Unterverzeichnisse, aber nicht Neu/ selbst
|
||||
find Neu/ -mindepth 1 -type d -empty -delete
|
||||
|
||||
# 3. Alles zum Commit vormerken
|
||||
git add --all
|
||||
log "📍 Alle Änderungen vorgemerkt."
|
||||
|
||||
# 4. Commit-Versuch
|
||||
if git status --porcelain | grep . >/dev/null; then
|
||||
if git commit -m "Archivierung automatisch am $(TIMESTAMP)"; then
|
||||
log "✅ Commit erfolgreich."
|
||||
else
|
||||
log "❌ Commit fehlgeschlagen. Starte Restore."
|
||||
if [ -x "$RESTORE_SCRIPT" ]; then
|
||||
"$RESTORE_SCRIPT"
|
||||
log "♻️ Restore ausgeführt."
|
||||
else
|
||||
log "⚠️ Restore-Skript nicht gefunden."
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
log "📥 Keine Änderungen zum Committen."
|
||||
fi
|
||||
Reference in New Issue
Block a user