Migrate a directory tree with rsync and prove nothing changed
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
- On lin-srv, create
/srv/sourcewith at least 200 files in nested folders, two owners, mixed permissions including one file mode 600, and a symbolic link. Savefind /srv/source | wc -landsha256sumof every file tolab/migrate/source.txt. - Run
rsync -aAXHn --delete /srv/source/ lin-dst:/srv/dest/(a dry run) and save the output tolab/migrate/dry-run.txt. - Run the same command without
-nas 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-changestolab/migrate/delta.txt. - On lin-dst, save the file count and checksums of
/srv/desttolab/migrate/dest.txt, andstat -c '%U %a %y'for the mode-600 file tolab/migrate/perms.txt. - Record in
lab/migrate/trailing-slash.txtwhat/srv/sourcewithout 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.