>_ IzzyLab

Hands-on task

This task is step 18 of the course “New server: setup from scratch”

Mirror the site to a second disk

medium~5 min

A second disk for backups has been attached to the server and mounted at /mnt/mirror. Make /mnt/mirror/shop an exact mirror of the site directory /var/www/shop: the contents match, file permissions are preserved, and everything that isn't in the source (leftovers of a previous deploy) is removed from the mirror.

What you'll practise:
  • rsync -a
  • --delete
  • mirroring
  • trailing slash
  • backups

Topic breakdown

rsync synchronizes directories and transfers only the differences, so repeated runs are fast. Archive mode preserves permissions, owners and modification times — without it, scripts in the copy lose their executable bit. An exact mirror also needs whatever isn't in the source to be removed from the destination: by default rsync deletes nothing. The main trap is the trailing slash on the source: it means "the contents of the directory", and without it the directory ends up nested one level deeper. The result is easy to check with a recursive diff -r.

What's checked

  1. /mnt/mirror/shop is an exact mirror of /var/www/shop
  2. file permissions preserved

What it looks like