Sync from remote server: 2025-10-12 18:56:41
This commit is contained in:
53
sync_server_file.sh
Executable file
53
sync_server_file.sh
Executable file
@@ -0,0 +1,53 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script per sincronizzare file .m da un server remoto a una directory locale
|
||||
# e fare il commit delle modifiche in un repository Git locale.
|
||||
|
||||
REMOTE_USER="alex"
|
||||
REMOTE_HOST="80.211.60.65"
|
||||
REMOTE_PORT="2022"
|
||||
REMOTE_SRC="/usr/local/matlab_func"
|
||||
LOCAL_DST="/home/alex/devel/matlab-ase"
|
||||
# ------------------------------------------------
|
||||
# 1. Esecuzione di Rsync (Mirroring dal remoto al locale)
|
||||
# Include: -a (archive), -v (verbose), -z (compress), --delete (mirroring)
|
||||
# Filtri: include directory (*/), include solo *.m, esclude *mcrCache*, esclude tutto il resto (*)
|
||||
echo "Inizio sincronizzazione da ${REMOTE_HOST}..."
|
||||
|
||||
rsync -avz --delete -e "ssh -p ${REMOTE_PORT}" \
|
||||
--include='*/' \
|
||||
--include='*.m' \
|
||||
--exclude='*' \
|
||||
"${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_SRC}" "${LOCAL_DST}"
|
||||
|
||||
# 2. Verifica se rsync è andato a buon fine
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Sincronizzazione completata con successo."
|
||||
else
|
||||
echo "Errore durante la sincronizzazione Rsync."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 3. Preparazione del messaggio di commit con la data attuale
|
||||
SYNC_DATE=$(date +"%Y-%m-%d %H:%M:%S")
|
||||
COMMIT_MSG="Sync from remote server: ${SYNC_DATE}"
|
||||
|
||||
# 4. Aggiungi tutte le modifiche (nuovi file, modificati, eliminati) all'area di staging
|
||||
# Usiamo 'git add .' per nuovi/modificati e 'git add -u' per le eliminazioni/modifiche.
|
||||
# 'git add -A' (o 'git add --all') è la soluzione più semplice e completa.
|
||||
echo "Aggiungo modifiche al Git staging area..."
|
||||
git add -A "${LOCAL_DST}"
|
||||
|
||||
# 5. Esegui il commit con il messaggio datato
|
||||
echo "Eseguo il commit con messaggio: \"${COMMIT_MSG}\""
|
||||
git commit -m "${COMMIT_MSG}"
|
||||
|
||||
# 6. Verifica se il commit ha prodotto modifiche
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Commit completato con successo."
|
||||
else
|
||||
# Questo succede se non ci sono state modifiche (rsync non ha trovato nulla da aggiornare)
|
||||
echo "Nessuna modifica rilevata; commit saltato."
|
||||
fi
|
||||
|
||||
echo "Processo completato."
|
||||
Reference in New Issue
Block a user