konsolidieren.sh hinzugefügt
This commit is contained in:
76
konsolidieren.sh
Normal file
76
konsolidieren.sh
Normal file
@ -0,0 +1,76 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Zielverzeichnis für die konsolidierten Monatsordner
|
||||
TARGET_DIR="./consolidated"
|
||||
mkdir -p "$TARGET_DIR"
|
||||
|
||||
# Zähle die Gesamtanzahl der zu verarbeitenden Verzeichnisse
|
||||
total_dirs=$(ls -d [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9] 2>/dev/null | wc -l)
|
||||
processed_dirs=0
|
||||
total_files=0
|
||||
copied_files=0
|
||||
|
||||
# Funktion zum Kopieren der neuesten Version einer Datei mit relativer Pfadstruktur
|
||||
copy_latest_file_with_path() {
|
||||
local source_file="$1"
|
||||
local base_dir="$2"
|
||||
local target_month_dir="$3"
|
||||
|
||||
# Relativen Pfad der Datei innerhalb des Basisverzeichnisses extrahieren
|
||||
local relative_path="${source_file#$base_dir/}"
|
||||
local target_file="$target_month_dir/$relative_path"
|
||||
|
||||
# Zielverzeichnis für die Datei erstellen (falls nicht vorhanden)
|
||||
mkdir -p "$(dirname "$target_file")"
|
||||
|
||||
# Prüfe, ob die Datei bereits existiert und ob die aktuelle Datei neuer ist
|
||||
if [ -f "$target_file" ]; then
|
||||
if [ "$source_file" -nt "$target_file" ]; then
|
||||
cp -f "$source_file" "$target_file"
|
||||
((copied_files++))
|
||||
fi
|
||||
else
|
||||
cp "$source_file" "$target_file"
|
||||
((copied_files++))
|
||||
fi
|
||||
((total_files++))
|
||||
}
|
||||
|
||||
# Fortschrittsbalken anzeigen
|
||||
print_progress() {
|
||||
local current=$1
|
||||
local total=$2
|
||||
local percent=$((current * 100 / total))
|
||||
local bar_length=50
|
||||
local filled=$((current * bar_length / total))
|
||||
local empty=$((bar_length - filled))
|
||||
|
||||
printf "\rFortschritt: ["
|
||||
printf "%${filled}s" | tr ' ' '='
|
||||
printf "%${empty}s" | tr ' ' ' '
|
||||
printf "] %d%% (%d/%d Verzeichnisse, %d Dateien kopiert)" "$percent" "$current" "$total" "$copied_files"
|
||||
}
|
||||
|
||||
# Durch alle Verzeichnisse im Format Jahr-Monat-Tag-Stunde iterieren
|
||||
for dir in [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]; do
|
||||
# Extrahiere Jahr und Monat aus dem Verzeichnisnamen
|
||||
if [[ "$dir" =~ ([0-9]{4})-([0-9]{2})-([0-9]{2})-([0-9]{2}) ]]; then
|
||||
year="${BASH_REMATCH[1]}"
|
||||
month="${BASH_REMATCH[2]}"
|
||||
|
||||
# Monatsverzeichnis im Zielverzeichnis erstellen
|
||||
month_dir="$TARGET_DIR/${year}-${month}"
|
||||
mkdir -p "$month_dir"
|
||||
|
||||
# Rekursiv durch alle Dateien im aktuellen Verzeichnis und seinen Unterverzeichnissen iterieren
|
||||
find "$dir" -type f | while read -r file; do
|
||||
copy_latest_file_with_path "$file" "$dir" "$month_dir"
|
||||
done
|
||||
|
||||
((processed_dirs++))
|
||||
print_progress "$processed_dirs" "$total_dirs"
|
||||
fi
|
||||
done
|
||||
|
||||
# Zeilenumbruch nach der Fortschrittsanzeige
|
||||
echo -e "\nFertig! $total_files Dateien geprüft, $copied_files Dateien kopiert."
|
||||
Reference in New Issue
Block a user