64 lines
2.4 KiB
Markdown
64 lines
2.4 KiB
Markdown
# worm
|
|
|
|
Write once, read many-Speicher
|
|
|
|
## 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
|
|
~~~
|
|
|
|
### pre-commit-hook einrichten ###
|
|
Siehe Datei "pre-commit"
|
|
|
|
### Das Cron-Script einrichten ###
|
|
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:
|
|
~~~
|
|
#!/bin/bash
|
|
|
|
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 |