Files
worm/testworm/restore-archiv.sh

38 lines
1.1 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
cd "$(dirname "$0")"
LOGFILE="archiv.log"
log() {
local TIMESTAMP
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
echo "[$TIMESTAMP] $1" | tee -a "$LOGFILE"
}
log "🔄 Starte Wiederherstellung von Archiv-Dateien..."
# Alle geänderten oder gelöschten Dateien (im Arbeitsverzeichnis oder Index)
changed_files=$(git diff --name-only Archiv)
staged_files=$(git diff --cached --name-only Archiv)
all_files=$(echo -e "$changed_files\n$staged_files" | sort -u)
if [[ -z "$all_files" ]]; then
log " Keine Änderungen an Archiv-Dateien gefunden."
else
for file in $all_files; do
if [[ ! -f "$file" ]]; then
# Datei wurde gelöscht -> Wiederherstellen
log "⏪ Stelle gelöschte Datei '$file' wieder her"
git restore --staged "$file"
git restore "$file"
else
# Datei existiert (modifiziert) -> zurücksetzen
log "⏪ Setze geänderte Datei '$file' zurück"
git restore --staged "$file"
git restore "$file"
fi
done
log "✅ Alle Änderungen an Archiv-Dateien wurden rückgängig gemacht."
fi