
Rsync is one of the most reliable tools for moving website files between servers, from your computer to a host, or for creating clean backups. Unlike FTP clients, it only transfers changed data (delta transfers), preserves permissions and timestamps, and can keep source and destination in sync. This makes it ideal for migrating sites, deploying updates, or backing up production files with minimal downtime and bandwidth use.
This guide focuses on the most common needs of webmasters and site owners who have SSH access to their servers (cPanel, VPS, or unmanaged hosting).
Prerequisites
- SSH access to the source and/or destination server (username + hostname or IP).
- The rsync binary available on both ends (almost all modern Linux servers include it).
- Enough disk space on the destination.
- Basic familiarity with the terminal.
Always test with the --dry-run (or -n) option first so you can see what would happen without making changes.
Basic Rsync Syntax
rsync [options] source destination- Source and destination can be local paths or remote (
user@host:/path). - A trailing slash on the source directory matters:
/path/to/site/copies the contents./path/to/sitecopies the directory itself.
1. Transfer Website Files from Your Local Computer to a Remote Server
Useful when you develop locally or have a full site backup on your machine and need to push it live.
rsync -avz --delete --progress /path/to/local/website/ [email protected]:/home/username/public_html/What the options do:
-a– archive mode (recursive, preserves permissions, ownership, timestamps, symlinks).-v– verbose (shows what is happening).-z– compress data during transfer (helpful over slower connections).--delete– removes files on the destination that no longer exist on the source (keeps the two locations identical). Use with caution.--progress– shows transfer progress.
Example for HTML/static files only:
rsync -avz --delete --include='*.html' --include='*/' --exclude='*' /local/site/ user@server:/var/www/html/2. Pull Website Files from a Remote Server to Your Local Machine (Backup or Migration Prep)
rsync -avz --delete --progress [email protected]:/home/username/public_html/ /path/to/local/backup/This is an excellent way to create a local mirror of your live site before making major changes or before switching hosts.
3. Transfer a Site Directly Between Two Remote Servers
You can run the command from either server (or from your local machine if it has SSH access to both).
From the destination server:
rsync -avz --delete --progress [email protected]:/home/username/public_html/ /home/username/public_html/Or use SSH key authentication and run it from your laptop so neither server needs the other’s password:
rsync -avz -e ssh --delete user@oldserver:/path/to/site/ user@newserver:/path/to/site/Important Options for Webmasters
| Option | Purpose | When To Use It |
|---|---|---|
-a / --archive | Preserve permissions, ownership, times | Almost always for websites |
-z | Compress during transfer | Slower connections or large files |
--delete | Make destination match source exactly | Full migrations / clean syncs |
--exclude='dir/' | Skip specific folders | Exclude node_modules, .git, caches, uploads if needed |
--dry-run / -n | Simulate the transfer | Always test first |
--progress | Show file-by-file progress | Large transfers |
-e ssh | Force SSH transport | When needed for security or non-standard ports |
Common exclusions for WordPress or similar CMS sites:
rsync -avz --delete \
--exclude='wp-content/cache/' \
--exclude='wp-content/uploads/' \ # optional – sometimes you want media separately
--exclude='.git/' \
--exclude='node_modules/' \
user@old:/path/to/site/ user@new:/path/to/site/Why Prefer Rsync Over FTP/SFTP Clients for Site Transfers?
- Delta Transfers: After the first full copy, only changed files (or even parts of files) are sent. Subsequent updates are dramatically faster.
- Permission Preservation: Critical for PHP apps, WordPress, and scripts that rely on correct ownership.
- Scriptable & Schedulable: Put the command in a shell script and run it via cron for automated backups or deployments.
- Reliable Over Imperfect Connections: Rsync can resume interrupted transfers more gracefully than many GUI tools.
Safety Tips
- Always run with
--dry-runfirst and review the output. - Be careful with
--deletebecause it will permanently remove files on the destination. - Prefer SSH keys over passwords for automation.
- After a full site transfer, update configuration files (database credentials, domain paths, etc.) and clear any caches.
- For very large media libraries, consider transferring the database and application files first, then media in a second pass (or use a tool specialized for large binary data).
Quick Reference Commands
Push local site live (with dry-run first):
rsync -avzn --delete /local/site/ user@server:~/public_html/
# then remove the n to actually run itPull live site for backup:
rsync -avz --delete user@server:~/public_html/ ~/backups/mysite-$(date +%Y%m%d)/Full remote-to-remote migration:
rsync -avz --delete -e ssh user@oldserver:~/public_html/ user@newserver:~/public_html/Rsync is already installed on the vast majority of Linux hosting environments. Once you are comfortable with the basic options above, you can handle almost any site transfer or backup task efficiently and cleanly from the command line.