netgescon-day0/scripts/sync-to-prod.sh

36 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Sincronizza modifiche da DEV verso produzione in modo controllato
# Uso: ./scripts/sync-to-prod.sh --confirm oppure --dry-run
set -euo pipefail
if [[ "${1:-}" == "--dry-run" ]]; then DRY=1; else DRY=0; fi
if [[ $DRY -eq 0 && "${1:-}" != "--confirm" ]]; then
echo "ERRORE: specifica --dry-run per test o --confirm per eseguire" >&2
exit 1
fi
SRC="/home/michele/netgescon/netgescon-laravel"
DST="/var/www/netgescon"
EXCLUDES=(
".git/"
"vendor/"
"node_modules/"
"public/build/"
"storage/app/private/"
"storage/app/public/"
"storage/app/reports/"
"storage/app/archivi-import/"
"storage/logs/"
"storage/framework/cache/"
"storage/framework/views/"
"storage/framework/sessions/"
"storage/framework/testing/"
"public/storage/"
"scripts/sync-to-prod.sh"
"scripts/sync-to-dev.sh"
)
EX_ARGS=()
for e in "${EXCLUDES[@]}"; do EX_ARGS+=("--exclude=${e}"); done
RSYNC_FLAGS="-rltDz --delete --no-owner --no-group"
[[ $DRY -eq 1 ]] && RSYNC_FLAGS+=" --dry-run"
rsync $RSYNC_FLAGS "${EX_ARGS[@]}" "$SRC/" "$DST/"
echo "Sync to PROD completato $([[ $DRY -eq 1 ]] && echo '(dry-run)' || echo '(APPLICATO)')"