Dateien nach "/" hochladen

This commit is contained in:
2025-12-30 23:52:08 +01:00
parent 2702d689d8
commit 660f3fa3af
4 changed files with 190 additions and 84 deletions

View File

@@ -7,6 +7,9 @@ CFG="$SCRIPT_DIR/config.sh"
# shellcheck disable=SC1090
source "$CFG"
# User, der das Script gestartet hat (auch wenn via sudo)
RUN_USER="${SUDO_USER:-$USER}"
# --- helpers ---
LOG_FILE="$SCRIPT_DIR/raspi-backup.log"
LOCK_FILE="$SCRIPT_DIR/.raspi-backup.lock"
@@ -38,13 +41,13 @@ need_cmd rsync
need_cmd ssh
need_cmd tee
# validate config vars
: "${NAS_HOST:?}" "${NAS_USER:?}" "${NAS_PORT:?}" "${SSH_USER:?}" "${NAS_BACKUP_BASE:?}" "${KEEP_DAYS:?}" "${KEY_TYPE:?}"
# validate config vars (OHNE SSH_USER)
: "${NAS_HOST:?}" "${NAS_USER:?}" "${NAS_PORT:?}" "${NAS_BACKUP_BASE:?}" "${KEEP_DAYS:?}" "${KEY_TYPE:?}"
hn="$(host_short)"
ssh_user="$SSH_USER"
ssh_user="$RUN_USER"
# Keypfad: gehört SSH_USER
# Keypfad: gehört RUN_USER
key_path="$(eval echo "~${ssh_user}/.ssh/id_${KEY_TYPE}_${hn}")"
[[ -f "$key_path" ]] || die "Key fehlt: $key_path (erst 02_setup_ssh.sh ausführen)"
@@ -54,6 +57,7 @@ remote_dest="${remote_root}/${run_ts}"
log "============================================================"
log "BACKUP START"
log "Run user : ${ssh_user}"
log "Host : ${hn}"
log "NAS : ${NAS_USER}@${NAS_HOST}:${NAS_PORT}"
log "Key (local): ${key_path}"
@@ -64,15 +68,23 @@ log "Logfile : ${LOG_FILE}"
log "============================================================"
acquire_lock
start_epoch="$(date +%s)"
# Common SSH options (no alias dependency)
# ---- Performance / SSH tuning ----
SSH_CIPHER="chacha20-poly1305@openssh.com"
SSH_COMPRESS_OPT="-o Compression=no"
if [[ "${BACKUP_SSH_COMPRESS:-no}" == "yes" ]]; then
SSH_COMPRESS_OPT="-o Compression=yes -o CompressionLevel=3"
fi
SSH_BASE=(ssh -p "$NAS_PORT" -i "$key_path"
-o IdentitiesOnly=yes
-o BatchMode=yes
-o StrictHostKeyChecking=yes
-o ConnectTimeout=20
-o Ciphers="$SSH_CIPHER"
$SSH_COMPRESS_OPT
)
log "Phase 1/5: Remote Ordner anlegen..."
@@ -91,13 +103,40 @@ if declare -p RSYNC_EXTRA >/dev/null 2>&1; then
for o in "${RSYNC_EXTRA[@]}"; do extra_args+=( "$o" ); done
fi
ssh_cmd="ssh -p ${NAS_PORT} -i ${key_path} -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=yes -o ConnectTimeout=20"
# ---- Fix: --inplace kollidiert mit --partial-dir / --partial ----
use_inplace=1
for o in "${extra_args[@]}"; do
case "$o" in
--partial-dir*|--partial)
use_inplace=0
;;
esac
done
inplace_args=()
if [[ "$use_inplace" -eq 1 ]]; then
inplace_args=(--inplace)
log "rsync: --inplace aktiv"
else
log "rsync: --inplace deaktiviert (Konflikt mit --partial/--partial-dir aus RSYNC_EXTRA)"
fi
ssh_cmd="ssh -p ${NAS_PORT} -i ${key_path} \
-o IdentitiesOnly=yes \
-o BatchMode=yes \
-o StrictHostKeyChecking=yes \
-o ConnectTimeout=20 \
-o Ciphers=${SSH_CIPHER} \
${SSH_COMPRESS_OPT}
"
log "Phase 2/5: rsync START (Live-Progress sichtbar)..."
log "Hinweis: Das kann je nach Datenmenge sehr lange dauern."
# WICHTIG: --omit-dir-times verhindert, dass der frische Backup-Ordner durch alte mtime sofort von Retention gelöscht wird
rsync -aAXH --numeric-ids \
--omit-dir-times \
--no-inc-recursive \
"${inplace_args[@]}" \
--info=progress2,stats2 \
"${exclude_args[@]}" \
"${extra_args[@]}" \