How do I keep /var/www identical on two servers with minimal transfer?

Quick Linux Tip #25:

Try: rsync -avz --checksum --delete /var/www/ linuxteck@backup:/var/www/

Info: --checksum compares file contents rather than timestamps to catch true changes. --delete removes destination files that no longer exist on the source.

Examples:

  • $ rsync -avz --dry-run /src/ user@host:/dst/  # Dry-run preview
  • $ rsync -avz --exclude='*.log' --exclude='cache/' /src/ /dst/
  • $ rsync -avz --link-dest=/prev/backup /source/ /new/backup/  # Hardlink backups

Note: --checksum increases disk I/O as it reads both ends entirely. Always test destructive syncs with --dry-run first. Trailing slashes control whether contents or directories are copied.

Follow @LinuxTeck for more #LinuxTips




LinuxTeck.com
linuxteck@ubuntu:~$ rsync -avz --checksum --delete /var/www/ \
linuxteck@backup:/var/www/
sending incremental file list
deleting site/old.html
site/index.html
site/style.css

sent 234,567 bytes  received 12,345 bytes  8,231.07 bytes/sec
total size is 45,678,900  speedup is 185.02
linuxteck@ubuntu:~$

PREVIOUS ARTICLE Quick Linux Tip #24: My script is slow but I don't know why. How do I find the bottleneck? NEXT ARTICLE Quick Linux Tip #26: Which processes have connections to my database?
About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.