Chapter 14: Archives and file transfer

Exercise: Move a tree between servers

Create data on servera, send it to serverb through a pipe, prove it arrived intact, then pull a copy to the workstation with rsync and check that nothing differs.

Move a tree between servers

  • Stream a tar archive between hosts through ssh.
  • Verify a transfer with sha256sum.
  • Mirror with rsync and confirm identity with a dry run.

Start the exercise

On workstation, start the exercise. It creates /tmp/arch/work/docs with three small files on servera, and removes leftovers of an earlier run.

[student@workstation ~]$ lab start sa-moving

Later tasks assume that you are logged in to the server they name: ssh student@servera from workstation, then sudo -i for a root shell.

Stream it to serverb

Use a pipe of two ssh commands to create a gzip tar archive of /tmp/arch/work on servera and extract it directly into /tmp/recv on serverb. List what arrived.

[student@workstation ~]$ ssh root@servera 'cd /tmp/arch && tar -czf - work' | ssh root@serverb 'mkdir -p /tmp/recv && tar -xzf - -C /tmp/recv && find /tmp/recv -type f | sort'
/tmp/recv/work/docs/a.txt
/tmp/recv/work/docs/c.txt
/tmp/recv/work/docs/d.txt

Prove it

Compute the checksums of the three files on servera, save them on workstation, and verify them on serverb.

[student@workstation ~]$ ssh root@servera 'cd /tmp/arch/work && sha256sum docs/*' > sums.txt
[student@workstation ~]$ ssh root@serverb 'cd /tmp/recv/work && sha256sum -c -' < sums.txt
docs/a.txt: OK
docs/c.txt: OK
docs/d.txt: OK

Damage and detect

On serverb change one of the files, then verify again. Which file fails?

[student@workstation ~]$ ssh root@serverb 'echo oops >> /tmp/recv/work/docs/c.txt'
[student@workstation ~]$ ssh root@serverb 'cd /tmp/recv/work && sha256sum -c -' < sums.txt
docs/a.txt: OK
docs/c.txt: FAILED
docs/d.txt: OK
sha256sum: WARNING: 1 computed checksum did NOT match

Pull a copy with rsync and compare

Pull /tmp/arch/work/ from servera into ~/xfer/work/ on workstation with rsync -aHAX. Then run rsync -avc --dry-run for the same pair. What does an empty file list mean?

[student@workstation ~]$ mkdir -p ~/xfer/work
[student@workstation ~]$ rsync -aHAX root@servera:/tmp/arch/work/ ~/xfer/work/
[student@workstation ~]$ rsync -avc --dry-run root@servera:/tmp/arch/work/ ~/xfer/work/ | tail -3

sent 21 bytes  received 185 bytes  412.00 bytes/sec
total size is 23  speedup is 0.11 (DRY RUN)

No files were listed, so the content is identical to the source. Change a file in ~/xfer/work/docs/ and run the dry run again: the changed file is listed.

Grade and finish

Check your work with lab grade sa-moving, then put the exercise away with lab finish sa-moving.