Skip to content

Instantly share code, notes, and snippets.

@kigawas
Last active March 25, 2024 16:12
Show Gist options
  • Save kigawas/4cecbf7e8bf2cca3e49686589e9d6217 to your computer and use it in GitHub Desktop.
Save kigawas/4cecbf7e8bf2cca3e49686589e9d6217 to your computer and use it in GitHub Desktop.
Automatically rsync local folder to server's folder behind http proxy on Linux
LOCAL=$1 # /home/user/test/
REMOTE=$2 # /home/remoteuser/test/
if [[ -z "$LOCAL" || -z "$REMOTE" ]]; then
echo 'No src/dst folder'
exit
fi
while inotifywait -r -e modify,create,delete $LOCAL; do
rsync -avuz --delete -e "ssh -o \"ProxyCommand=connect-proxy -H YOUR_PROXY_HOST:YOUR_PROXY_PORT %h %p\"" $LOCAL YOUR_USERNAME@YOUR_SERVER_IP:$REMOTE
done
# -avuz means archive mode, verbose output, skip newer files on server, compress
# --delete means if local folder does not have a file "a.txt", then remote folder's file "a.txt" will be deleted if it exists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment