↑ ↓ select, Enter open, Esc close

Mirror a directory exactly with rsync --delete

Adjust the values, the command updates live
user@server
rsync -av --delete /var/www/vhosts/example.com/httpdocs/ /backup/example.com/httpdocs/

Transfers new and changed files and, with --delete, removes everything at the destination that no longer exists in the source. The result is an exact mirror. Files deleted in the source also disappear from the backup on the next run.

Note: Swapped source and destination or a missing slash can delete entire directories in the worst case. Always check with --dry-run first what is reported as deleting.

Also searched as

  • rsync mirror directory
  • make destination identical to source
  • delete removed files from backup too
  • rsync delete extraneous files

Related one-liners

All in rsync and backup

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.