Rsync Local Backup
rsync is excellent for local backups because it only copies differences, preserves metadata, and can mirror a directory tree quickly. For WordPress, it is most useful for copying site files to a local backup directory (or to a mounted secondary volume).
Quick Summary
- Mirror WordPress files locally with
rsync -a. - Use excludes to avoid caches and nested backups.
- Be cautious with
--delete(it removes files in the destination). - Prefer staging directories and restore drills.
A safe first copy (no deletion)
Start without --delete until you trust your paths and excludes.
rsync-local-copy-safe.sh
sudo mkdir -p /backups/files-current
sudo rsync -a \
--human-readable \
--info=stats2,progress2 \
--exclude 'wp-content/cache/' \
--exclude 'wp-content/*/cache/' \
--exclude 'wp-content/updraft/' \
--exclude '*.log' \
/var/www/html/ \
/backups/files-current/
Notes:
- The trailing slash on
/var/www/html/means "copy the contents of html". - Excludes are evaluated relative to the source root.
Mirror mode (with deletion)
When you are sure the destination is correct, mirror mode keeps destination identical to source.
warning
--delete permanently removes files in the destination that do not exist in the source. If you point to the wrong destination, you can wipe data.
rsync-local-mirror-with-delete.sh
sudo rsync -a \
--delete \
--exclude 'wp-content/cache/' \
--exclude 'wp-content/*/cache/' \
--exclude 'wp-content/updraft/' \
--exclude '*.log' \
/var/www/html/ \
/backups/files-mirror/
Verification
Quick sanity checks:
verify-rsync-local-backup.sh
sudo test -d /backups/files-current/wp-content
sudo find /backups/files-current -maxdepth 2 -type f -name wp-config.php -print
sudo du -sh /var/www/html /backups/files-current
To validate your restore path, practice extracting/copying into a staging directory:
rsync-restore-drill-to-staging.sh
sudo rm -rf /tmp/restore-test
sudo mkdir -p /tmp/restore-test
sudo rsync -a /backups/files-current/ /tmp/restore-test/
sudo find /tmp/restore-test -maxdepth 2 -type d -name wp-content -print
Common mistakes
- Forgetting trailing slashes and copying a directory into itself.
- Running
--deletebefore verifying the destination. - Backing up plugin caches and nested backup archives.
Next steps
- Snapshot-style rsync backups:
opt/docker-data/apps/docusaurus/site/docs/server/linux-server/10-backup-disaster-recovery/snapshot-style-backup-folder.mdx.