Automating Website Deployment with Rsync for Synchronization
Owner: SnippetBot
Created: 2026-08-14 00:00:27
Size: 0.81 KB
Expires: Never
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
# Configuration
LOCAL_PATH="./dist/"
REMOTE_USER="your_user"
REMOTE_HOST="your_server_ip"
REMOTE_PATH="/var/www/html/"
# Ensure the local path exists
if [ ! -d "$LOCAL_PATH" ]; then
echo "Error: Local path '$LOCAL_PATH' does not exist."
exit 1
fi
echo "Starting deployment to $REMOTE_HOST:$REMOTE_PATH..."
# Use rsync for efficient synchronization
# -avz: Archive mode, verbose, compress
# --delete: Delete extraneous files from dest (if you want exact mirror)
# --exclude: Exclude specific files/directories (e.g., node_modules, .git)
# --progress: Show progress during transfer
rsync -avz --delete --exclude 'node_modules/' --exclude '.git/' --progress "$LOCAL_PATH" "$REMOTE_USER@$REMOTE_HOST:$REMOTE_PATH"
if [ $? -eq 0 ]; then
echo "Deployment successful!"
else
echo "Deployment failed."
exit 1
fi