Skip to content

Instantly share code, notes, and snippets.

@MaskeZen
Last active October 21, 2020 02:45
Show Gist options
  • Save MaskeZen/2c7f45fe0df2ece7a44792c5fbb25016 to your computer and use it in GitHub Desktop.
Save MaskeZen/2c7f45fe0df2ece7a44792c5fbb25016 to your computer and use it in GitHub Desktop.
Publicador con rsync
#!/bin/bash
# $ ssh-keygen -t rsa -b 2048
# If you already have an SSH key, you can skip this step… Just hit Enter for the key and both passphrases:
# Copy your keys to the target server:
# $ ssh-copy-id id@server
# You may also want to look into using ssh-agent if you want to try keeping your keys protected with a passphrase.
# CONFIGURACIÓN --------------------
local='/d/wamp64/www/project/'
local_rsyncignore='/d/wamp64/www/project/.rsyncignore'
remote_sync='/apps/myapp_rsync'
remote_path='/apps/myapp'
remote_user='root'
remote_host='192.168.1.165'
# ----------------------------------
# rlptgoD
echo 'Sincronizando el directorio de intercambio:'
rsync -av --exclude-from $local_rsyncignore $local $remote_user@$remote_host:$remote_sync
# rsync -rlptDv --exclude-from $local_rsyncignore $local $remote_user@$remote_host:$remote_sync
status=$?
echo "codigo de estado: $status"
echo "----------------------------------------------------------------------"
if [ $status != 0 ]
then
echo 'Error al intentar sincronizar el directorio de intercambio.'
exit $status
fi
# Cambia el usuario del directorio
echo "Estado actual del directorio de sincronización:"
ssh $remote_user@$remote_host chown $remote_user:$remote_user -R $remote_sync
ssh $remote_user@$remote_host ls -l $remote_sync
status=$?
echo "codigo de estado: $status"
echo "----------------------------------------------------------------------"
# DRY RUN
ssh $remote_user@$remote_host rsync -avn $remote_sync $remote_path
echo "----------------------------------------------------------------------"
read -p 'Desea confirmar la sincronización?, si/no: ' confirmar
if [ "$confirmar" == "si" ]
then
ssh $remote_user@$remote_host rsync -av $remote_sync $remote_path
status=$?
if [ $status == 0 ]
then
echo "Sincronización realizada con éxito."
else
echo "codigo de estado: $status"
echo "Falló la sincronización."
fi
else
echo 'Se canceló la sincronización'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment