README.md aktualisiert
This commit is contained in:
67
README.md
67
README.md
@ -2,14 +2,63 @@
|
|||||||
|
|
||||||
Write once, read many-Speicher
|
Write once, read many-Speicher
|
||||||
|
|
||||||
## Aufsetzen ##
|
## Ablauf ##
|
||||||
|
### Projektverzeichnisse vorbereiten ###
|
||||||
|
~~~
|
||||||
|
mkdir mein_repo
|
||||||
|
cd mein_repo
|
||||||
|
git init
|
||||||
|
mkdir Archiv # Das ist dein WORM-Speicher im Git-Repo
|
||||||
|
mkdir Neu # Hier legst du temporär neue Dateien ab
|
||||||
|
~~~
|
||||||
|
|
||||||
1. Erstelle ein lokales git
|
### pre-commit-hook einrichten ###
|
||||||
1. Speichere den hook im Verzeichnis .git/hooks/
|
Siehe Datei "pre-commit"
|
||||||
1. Nutze die bash-Scripte zum regelmäßigen Hinzufügen von Dateien.
|
|
||||||
|
|
||||||
## Benötigt ##
|
### Das Cron-Script einrichten ###
|
||||||
Es werden drei Verzeichnisse benötigt:
|
Um automatisiert Dateien dem WORM-Speicher zuzuführen, werden sie im Verzeichnis "Neu" gespeichert (auch Unterverzeichnisse). Cron sorgt für die Übertragung der Dateien, die noch nicht im WORM-Speicher vorhanden sind. Hier das Script:
|
||||||
1. Das Projektverzeichnis
|
~~~
|
||||||
1. Darunter die beiden Verzeichnisse "Neu"
|
#!/bin/bash
|
||||||
11. und "Archiv"
|
|
||||||
|
GIT_REPO_PATH="/home/alf/MEINWORM"
|
||||||
|
NEW_FILES_DIR="Neu"
|
||||||
|
ARCHIVE_TARGET_DIR="Archiv"
|
||||||
|
LOG_FILE="/home/alf/archive_sync.log" # Pfad anpassen
|
||||||
|
|
||||||
|
log_message() { echo "[$(date +"%Y-%m-%d %H:%M:%S")] $1" | tee -a "$LOG_FILE"; }
|
||||||
|
|
||||||
|
log_message "--- Archive Sync Script Started ---"
|
||||||
|
cd "$GIT_REPO_PATH" || { log_message "ERROR: Could not change to Git repository directory. Exiting."; exit 1; }
|
||||||
|
mkdir -p "$ARCHIVE_TARGET_DIR"
|
||||||
|
|
||||||
|
find "$NEW_FILES_DIR" -type f | while read FILE_PATH_IN_NEW
|
||||||
|
do
|
||||||
|
FILE_FULL_NAME=$(basename "$FILE_PATH_IN_NEW")
|
||||||
|
TARGET_FILE_PATH="$ARCHIVE_TARGET_DIR/$FILE_FULL_NAME"
|
||||||
|
|
||||||
|
if git ls-files --error-unmatch -- "$TARGET_FILE_PATH" &>/dev/null; then
|
||||||
|
log_message " File '$FILE_FULL_NAME' already exists in '$ARCHIVE_TARGET_DIR/'. Skipping."
|
||||||
|
else
|
||||||
|
log_message " File '$FILE_FULL_NAME' is new to '$ARCHIVE_TARGET_DIR/'. Adding..."
|
||||||
|
cp "$FILE_PATH_IN_NEW" "$TARGET_FILE_PATH"
|
||||||
|
git add "$TARGET_FILE_PATH"
|
||||||
|
if ! git diff --cached --quiet --exit-code; then
|
||||||
|
git commit -m "Add new file: $FILE_FULL_NAME to archive" "$TARGET_FILE_PATH" || {
|
||||||
|
log_message " WARNING: Commit for '$FILE_FULL_NAME' failed. (Pre-commit hook active?)"
|
||||||
|
git restore --staged "$TARGET_FILE_PATH"
|
||||||
|
git restore "$TARGET_FILE_PATH"
|
||||||
|
}
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
log_message " Successfully committed '$FILE_FULL_NAME'."
|
||||||
|
# rm "$FILE_PATH_IN_NEW" # Optional: Originaldatei aus Neu/ löschen
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
log_message " No changes staged for $FILE_FULL_NAME. Skipping commit for this file."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
log_message "No new files committed. Skipping push." # Da kein Remote genutzt wird
|
||||||
|
log_message "--- Archive Sync Script Finished ---"
|
||||||
|
exit 0
|
||||||
|
~~~
|
||||||
|
Es gibt ein weiteres Script, bei dem bei Vorhandensein
|
||||||
Reference in New Issue
Block a user