Migrate a directory tree with rsync and prove nothing changed

short · 40 min · Objective 2.3

Task

Copy a directory tree from lin-srv to a second server with rsync so that contents, permissions, ownership and timestamps all survive, then prove it with counts and checksums. Start with a dry run, do a pre-seed, change the source, and finish with a delta sync -- the two-phase migration from the lesson.

Steps

  1. On lin-srv, create /srv/source with at least 200 files in nested folders, two owners, mixed permissions including one file mode 600, and a symbolic link. Save find /srv/source | wc -l and sha256sum of every file to lab/migrate/source.txt.
  2. Run rsync -aAXHn --delete /srv/source/ lin-dst:/srv/dest/ (a dry run) and save the output to lab/migrate/dry-run.txt.
  3. Run the same command without -n as the pre-seed. Then add five files and modify two on the source, and run it again as the delta sync, saving the second run's output with --itemize-changes to lab/migrate/delta.txt.
  4. On lin-dst, save the file count and checksums of /srv/dest to lab/migrate/dest.txt, and stat -c '%U %a %y' for the mode-600 file to lab/migrate/perms.txt.
  5. Record in lab/migrate/trailing-slash.txt what /srv/source without the trailing slash would have created on the destination.

Verify

These checks run in a POSIX shell: Terminal on macOS or Linux, and on Windows Git Bash (it comes with Git for Windows) or WSL. A stock Windows PowerShell or Command Prompt has no awk or grep, so there the first line fails.

diff <(sort -k2 lab/migrate/source.txt | awk '{print $1}') <(sort -k2 lab/migrate/dest.txt | awk '{print $1}') && echo contents identical
grep -c '^<f' lab/migrate/delta.txt
grep -c ' 600 ' lab/migrate/perms.txt
grep -Eic 'source/|inside|extra level|nested' lab/migrate/trailing-slash.txt

The checksum lists match, the delta sync transferred only the files that changed (about seven lines starting <f -- the arrow points at the remote host, because this run pushes to lin-dst; a local copy would show >f -- not two hundred), and the private file kept mode 600. A delta that re-sent everything means the timestamps were not preserved on the pre-seed, which -a exists to prevent.

Notes

Robocopy is the Windows equivalent: /MIR /COPYALL /DCOPY:T /R:2 /W:5 /LOG:, with /L for the dry run. /MIR deletes at the destination just as --delete does, so the dry run matters just as much.

This is an independent study companion for CompTIA Server+ SK0-005 and is not produced by or endorsed by CompTIA.