About rsync command generator
rsync copies only the differences between source and destination, which makes repeated backups and deployments fast.
Common flags
- -a keeps permissions and times (archive mode).
- -v shows what is happening and -z compresses in transit.
- --delete removes files at the destination that are gone from the source.
- --dry-run shows what would change without doing it.
Trailing slash
A trailing slash on the source copies the contents; without it, the folder itself is copied.
A worked example
rsync -avz --delete --dry-run ./dist/ [email protected]:/var/www/site/ shows what would be copied and deleted. Remove --dry-run when you are happy. The trailing slash on ./dist/ means copy the contents, not the folder itself.
Excluding files
- --exclude 'node_modules' and --exclude '.env' keep them out.
- --progress shows file-by-file progress.
- -e 'ssh -p 2222' uses a custom SSH port.
