Bookmark this page

Guided Exercise: Synchronizing Files Between Systems Securely

In this exercise, you will synchronize the contents of a local directory with a copy on a remote server by using rsync over SSH.

Outcomes

You should be to use the rsync command to synchronize the content of a local directory with a copy on a remote server.

Log in as the student user on workstation using student as the password.

From workstation, run the lab archive-sync start command. The command runs a start script that determines if the hosts, servera and serverb, are reachable on the network. The script also ensures that the file and directory to be created in the exercise does not exist on servera.

[student@workstation ~]$ lab archive-sync start
  1. Use the ssh command to log in to servera as the student user.

    [student@workstation ~]$ ssh student@servera
    ...output omitted...
    [student@servera ~]$ 
  2. Create a directory named /home/student/serverlogs on servera. Use the rsync command to securely create an initial copy of the /var/log directory tree on serverb in the /home/student/serverlogs directory on servera.

    1. On servera, create the target directory named /home/student/serverlogs to store the log files synchronized from serverb.

      [student@servera ~]$ mkdir ~/serverlogs
    2. Use the rsync command to synchronize the /var/log directory tree on serverb to the /home/student/serverlogs directory on servera. Note that only the root user can read all the content in the /var/log directory on serverb. All files are transferred in the initial synchronization.

      [student@servera ~]$ rsync -av root@serverb:/var/log ~/serverlogs
      root@serverb's password: redhat
      receiving incremental file list
      log/
      log/README
      log/boot.log
      ...output omitted...
      log/tuned/tuned.log
      
      sent 992 bytes  received 13,775,064 bytes  2,119,393.23 bytes/sec
      total size is 13,768,109  speedup is 1.00
  3. As root on serverb, execute the logger "Log files synchronized" command to get a new entry in the /var/log/messages log file to reflect when the last synchronization took place.

    [student@servera ~]$ ssh root@serverb 'logger "Log files synchronized"'
    Password: redhat
    [student@servera ~]$ 
  4. Use the rsync command to securely synchronize from the /var/log directory tree on serverb to the /home/student/serverlogs directory on servera. Note that this time only log files that have changed are transferred.

    [student@servera ~]$ rsync -av root@serverb:/var/log ~/serverlogs
    root@serverb's password: redhat 
    receiving incremental file list
    log/messages
    log/secure
    log/audit/audit.log
    
    sent 3,496 bytes  received 27,243 bytes  8,782.57 bytes/sec
    total size is 11,502,695  speedup is 374.21
  5. Exit from servera.

    [student@servera ~]$ exit
    logout
    Connection to servera closed.
    [student@workstation]$ 

Finish

On workstation, run the lab archive-sync finish script to complete this exercise.

[student@workstation ~]$ lab archive-sync finish

This concludes the guided exercise.

Revision: rh124-8.2-df5a585