Rsync vs Git for Website Backup: Performance Benchmark and Best Practices


3 views

When maintaining disaster recovery setups with multiple servers, the backup strategy becomes critical. As shown in the test cases, both rsync and git have their advantages depending on the scenario:

// Sample rsync command used in testing
rsync -azP --delete /var/www/ backup-server:/var/www/

// Git commands sequence
git add .
git commit -a -m "snapshot $(date +'%Y-%m-%d %H:%M')"
git push backup live_branch

From the provided benchmarks, we can observe interesting patterns:

  • For small text file changes (500KB): git was significantly faster (0.074s vs 0.718s)
  • For medium image folders (18MB): rsync performed better (5.311s vs 15.334s)
  • For no-change scenarios: git checks were faster due to its internal tracking

Git's advantage comes from its content-addressable storage and delta compression. However, it has limitations:

# Git configuration for handling large binary files
git config --global core.compression 9
git config --global pack.depth 50
git config --global pack.windowMemory 256m

Rsync shines when dealing with:

  • Large binary files (images, videos)
  • Entire directory structures that change frequently
  • Cases where you don't need version history

A potential solution combining both technologies:

#!/bin/bash
# Backup script using both git and rsync

# Rsync for uploads and large media
rsync -azP --delete /var/www/uploads/ backup-server:/var/www/uploads/

# Git for code and configuration
cd /var/www/
git add .
git commit -a -m "Daily backup $(date)"
git push origin master

When dealing with 50+ repositories, consider these optimizations:

# Parallel processing with xargs
ls -d /var/www/*/.git | xargs -P10 -I{} dirname {} | xargs -P10 -I{} git -C {} push

# Git maintenance
git config --global maintenance.auto false
git maintenance start --auto

The optimal solution depends on your specific workload characteristics. For predominantly code changes, git provides better efficiency and version tracking. For media-heavy sites, rsync remains the better performer. A hybrid approach might offer the best of both worlds.


When maintaining disaster recovery setups with multiple web servers, the backup strategy becomes crucial. The fundamental question is whether traditional file synchronization (rsync) or version control systems (git) provide better performance and reliability for website backups.

From the test data provided, we can observe some interesting patterns:

// Sample rsync command
rsync -avz --delete /var/www/ user@backup-server:/var/www/

// Sample git workflow
git add .
git commit -m "Backup $(date)"
git push backup-server master

Key observations:

  • For small text file changes (500k), git is significantly faster (0.074s vs 0.718s)
  • With larger binary files (18M images), rsync performs better (5.311s vs 15.334s)
  • When no changes exist, git checks are slightly faster

Git's delta compression works exceptionally well for text files but becomes inefficient with binary files. Rsync's block-level transfer shines with large binary assets.

For a LAMP stack, consider this hybrid approach:

#!/bin/bash
# Backup script for mixed content
DATE=$(date +%Y-%m-%d-%H%M)

# Backup code via git
cd /var/www/html
git add .
git commit -m "Code backup $DATE"
git push backup master

# Backup uploads via rsync
rsync -av --delete /var/www/uploads/ backup-server:/var/www/uploads/

Managing 50 separate git repositories introduces complexity. Consider these alternatives:

// Option 1: Git submodules
git submodule add ssh://backup-server/path/to/repo.git

// Option 2: Monorepo approach
git init /var/www
# Add all websites as subdirectories

Git repositories grow indefinitely unless maintained. Regular garbage collection is essential:

git gc --aggressive
git repack -a -d --depth=250 --window=250

Both methods require SSH key authentication. For rsync:

rsync -e "ssh -i /path/to/private_key" ...

For git, configure SSH wrappers or use deploy keys with restricted permissions.

For complete system backups, consider:

  • LVM snapshots + rsync
  • Btrfs send/receive
  • Restic or Borg for encrypted backups

Each website's characteristics should dictate the backup strategy. A static marketing site might work perfectly with git, while an e-commerce site with thousands of product images might benefit more from rsync.