>_ IzzyLab

Hands-on task

This task is step 12 of the course “Archives and backups”

rsync: mirroring the site directory

medium~6 min

The site directory /var/www/shop has to be kept in a backup copy /mnt/backup/shop — the standby nginx serves the site straight from it. Open the Site tab above the terminal: it still shows Shop v1, the copy is stale — it has old versions of files and junk the site dropped long ago. Make /mnt/backup/shop an exact mirror of the site — the same contents, no extra files, the same permissions. Then reload the Site tab.

What you'll practise:
  • rsync
  • --delete
  • mirroring
  • trailing slash
  • file permissions

Topic breakdown

A mirror is a copy that matches the source completely: the same files with the same contents and attributes, and not one extra. rsync in archive mode (-a) transfers only the differences and keeps permissions, owners and times, while deleting files that vanished from the source is turned on separately with --delete — without it the "mirror" gradually collects junk. The main trap is the trailing slash on the source: src/ means the directory's contents, src the directory itself, which ends up one level deeper. The result is easy to check with a recursive diff -r, and permissions with stat.

What's checked

  1. /mnt/backup/shop matches the site
  2. file permissions are kept
  3. the site is unharmed
  4. the standby site serves the current version

What it looks like