User Tools

Site Tools


virtualisierung:proxmox:pom_repo

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
virtualisierung:proxmox:pom_repo [2025/07/23 14:24] stonevirtualisierung:proxmox:pom_repo [2025/09/01 14:22] (current) – [Sync Script] stone
Line 339: Line 339:
  
  
-===== Medium für Clients konfigurieren ===== +===== NGINX vorbereiten ===== 
-Damit die Clients dann auch auf die Daten zugreifen können muss man ein Medium erstellen+Damit die Repos abgeholt werden können wird NGINX als Webserver her halten.
  
-==== Anlegen eines Mediums ==== 
 <code> <code>
-proxmox-offline-mirror config media add \ +apt install nginx
-  --id repo_debian-12 \ +
-  --mirrors debian-12 \ +
-  --mirrors debian-12-update \ +
-  --mirrors debian-12-security \ +
-  --sync true --verify true \ +
-  --mountpoint /mnt/pom/client_repos/debian-12+
 </code> </code>
 +\\
 +
 +==== NGINX Config ====
 +/etc/nginx/sites-enabled/default
 +
 +<code>
 +root /var/www/html;
 +
 +location / {
 +    try_files $uri $uri/ =404;
 +    autoindex on;
 +    autoindex_exact_size off;
 +    autoindex_localtime on;
 +    gzip off;
 +    add_header Cache-Control no-cache;
 +}
 +</code>
 +
 +\\
 +
 +===== Sync Script =====
 +Dieses Script synct die Repos und verlinkt den aktuellen Snapshot zum NGINX.
 +
 +<code>
 +#!/bin/bash
 +
 +#####################
 +### Configuration ###
 +#####################
 +BASE_DIR="/opt/pom"
 +WEB_DIR="/var/www/html/bookworm"
 +REPOS=("debian-12-main" "debian-12-updates" "debian-12-security" "pve-8-non-sub")
 +SYMLINK_NAMES=("debian" "debian-updates" "debian-security" "pve-non-sub")
 +KEEP_SNAPSHOTS=3  # How many snapshots to keep per repo
 +
 +
 +
 +##############
 +### Colors ###
 +##############
 +RED='\033[0;31m'
 +GREEN='\033[0;32m'
 +NC='\033[0m' # No Color
 +
 +echo_info() {
 +    echo -e "${GREEN}[INFO] $1${NC}"
 +}
 +
 +echo_error() {
 +    echo -e "${RED}[ERROR] $1${NC}" >&2
 +}
 +
 +
 +
 +########################
 +### Sync all mirrors ###
 +########################
 +echo_info "Syncing all configured mirrors..."
 +if ! proxmox-offline-mirror mirror snapshot create-all; then
 +    echo_error "Failed to sync mirrors with 'snapshot create-all'."
 +    exit 1
 +fi
 +
 +
 +
 +###########################################
 +### Remove existing symlinks in WEB_DIR ###
 +###########################################
 +echo_info "Removing old symlinks in $WEB_DIR..."
 +for link in "${SYMLINK_NAMES[@]}"; do
 +    if [[ -L "$WEB_DIR/$link" || -e "$WEB_DIR/$link" ]]; then
 +        rm -rf "$WEB_DIR/$link" || {
 +            echo_error "Failed to remove $WEB_DIR/$link"
 +            exit 1
 +        }
 +    fi
 +done
 +
 +
 +
 +##################################################
 +### Create new symlinks to the latest snapshot ###
 +##################################################
 +echo_info "Creating symlinks to latest snapshots..."
 +for i in "${!REPOS[@]}"; do
 +    REPO="${REPOS[$i]}"
 +    LINK_NAME="${SYMLINK_NAMES[$i]}"
 +    SNAPSHOT_DIR="$BASE_DIR/$REPO/"
 +
 +    if [[ ! -d "$SNAPSHOT_DIR" ]]; then
 +        echo_error "Snapshot directory $SNAPSHOT_DIR does not exist."
 +        continue
 +    fi
 +
 +    # Find latest snapshot (sorted lexically, newest last)
 +    LATEST_SNAPSHOT=$(ls -1 "$SNAPSHOT_DIR" | sort | tail -n 1)
 +
 +    if [[ -z "$LATEST_SNAPSHOT" ]]; then
 +        echo_error "No snapshots found for $REPO."
 +        continue
 +    fi
 +
 +    SNAPSHOT_PATH="$SNAPSHOT_DIR/$LATEST_SNAPSHOT"
 +
 +    if [[ ! -d "$SNAPSHOT_PATH" ]]; then
 +        echo_error "Snapshot path $SNAPSHOT_PATH is not a directory."
 +        continue
 +    fi
 +
 +    ln -s "$SNAPSHOT_PATH" "$WEB_DIR/$LINK_NAME" || {
 +        echo_error "Failed to create symlink for $LINK_NAME"
 +        exit 1
 +    }
 +    echo_info "Linked $SNAPSHOT_PATH → $WEB_DIR/$LINK_NAME"
 +done
 +
 +
 +
 +############################
 +### Delete old snapshots ###
 +############################
 +echo_info "Pruning old snapshots (keeping latest $KEEP_SNAPSHOTS)..."
 +for REPO in "${REPOS[@]}"; do
 +    SNAPSHOT_LIST=$(proxmox-offline-mirror mirror snapshot list "$REPO" | grep '^-' | sed 's/- //' | sort)
 +
 +    TOTAL=$(echo "$SNAPSHOT_LIST" | wc -l)
 +
 +    if (( TOTAL > KEEP_SNAPSHOTS )); then
 +        TO_DELETE=$(echo "$SNAPSHOT_LIST" | head -n -$KEEP_SNAPSHOTS)
 +        while read -r SNAP_ID; do
 +            if [[ -n "$SNAP_ID" ]]; then
 +                echo_info "Deleting snapshot $SNAP_ID from $REPO..."
 +                proxmox-offline-mirror mirror snapshot remove "$REPO" "$SNAP_ID" || {
 +                    echo_error "Failed to delete snapshot $SNAP_ID for $REPO"
 +                }
 +            fi
 +        done <<< "$TO_DELETE"
 +    else
 +        echo_info "No old snapshots to delete for $REPO."
 +    fi
 +done
 +
 +
 +
 +##########################
 +### Garbage collection ###
 +##########################
 +echo_info "Running garbage collection..."
 +if ! proxmox-offline-mirror mirror gc; then
 +    echo_error "Garbage collection failed."
 +    exit 1
 +fi
 +
 +echo_info "Mirror update and cleanup done."
 +exit 0
 +</code>
 +\\
 +
 +
 +
 +
  
  
  
  
virtualisierung/proxmox/pom_repo.1753280659.txt.gz · Last modified: by stone