Exercise

Synchronizing Directories with rsync Exercise

Task

In this hands-on exercise, synchronize servera's log directory into /tmp, generate changes, and compare the first and second transfers.

Local host
workstation
Remote host
servera
Privileges
sudo access on both hosts
  1. Install rsync on both machines

    rsync must be present on both ends of the transfer, and it is not part of a minimal installation.

    sudo dnf install -y rsync
    ssh student@servera
    sudo dnf install -y rsync
    exit
  2. Preview and run the first synchronization

    -n is a dry run: it reports what would move and changes nothing. -a is archive mode and -v names each file as it goes.

    rsync -avn root@servera:/var/log /tmp

    The first pass copies everything, exactly as scp would. Note the byte counts printed at the end.

    rsync -av root@servera:/var/log /tmp
  3. Generate changes and synchronize again

    logger writes a message into the system log.

    ssh root@servera
    logger -t rsync-exercise "Generating a new log entry for the transfer exercise"
    logger -t rsync-exercise "And one more"
    tail -n 2 /var/log/messages
    exit

    Run exactly the same command again and compare the byte counts with the first run.

    rsync -av root@servera:/var/log /tmp
  4. Verify the changes and clean up

    Search your local copy for the messages you generated.

    grep 'rsync-exercise' /tmp/log/messages

    Remove the local copy of the log directory.

    sudo rm -rf /tmp/log
    ls /tmp