In this exercise, you synchronize the contents of a local directory with a copy on a remote server, by using the rsync command.
Outcomes
Use the rsync command to synchronize the contents of a local directory with a copy on a remote server.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command prepares your environment and ensures that all required resources are available.
[student@workstation ~]$ lab start archive-sync
Instructions
On the workstation machine, use the ssh command to log in to the servera machine as the student user, and then switch to the root user.
[student@workstation ~]$ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#
Open a new terminal window, and log in to the serverb machine as the student user.
[student@workstation ~]$ ssh student@serverb
...output omitted...
[student@serverb ~]$Create the /home/student/serverlogs directory on the serverb machine.
Use the rsync command to securely create an initial copy of the /var/log directory tree on the servera machine in the /home/student/serverlogs directory on the serverb machine.
On the serverb machine, create the /home/student/serverlogs directory to store the synchronized log files from the servera machine.
[student@serverb ~]$ mkdir ~/serverlogsOn the servera machine, use the rsync command to synchronize the /var/log directory tree on the servera machine to the /home/student/serverlogs directory on the serverb machine.
Only the root user can read all the /var/log directory contents on the servera machine.
Transfer all the files in the initial synchronization.
[root@servera ~]#rsync -av /var/log student@serverb:/home/student/serverlogs...output omitted... student@serverb's password:studentsending incremental file list log/ log/README -> ../../usr/share/doc/systemd/README.logs log/boot.log ...output omitted... sent 1,390,819 bytes received 508 bytes 309,183.78 bytes/sec total size is 1,388,520 speedup is 1.00
On the servera machine, execute the logger "Log files synchronized" command to add an entry in the /var/log/messages log file to reflect when the last synchronization occurred.
[root@servera ~]# logger "Log files synchronized"Use the rsync command to securely synchronize from the /var/log directory tree on the servera machine to the /home/student/serverlogs directory on the serverb machine.
This time, only the changed log files are transferred.
[root@servera ~]#rsync -av /var/log student@serverb:/home/student/serverlogsstudent@serverb's password:studentsending incremental file listlog/messagessent 3,854 bytes received 3,807 bytes 2,188.86 bytes/sec total size is 1,388,648 speedup is 181.26
On the serverb machine, verify the contents of the /home/student/serverlogs/log/messages file with the tail command.
[student@serverb ~]$tail -n 5 ~/serverlogs/log/messagesMar 22 04:25:08 servera systemd[1]: systemd-hostnamed.service: Deactivated successfully. Mar 22 04:25:09 servera systemd[1066]: Starting Mark boot as successful... Mar 22 04:25:09 servera systemd[1066]: Finished Mark boot as successful. Mar 22 04:25:47 servera chronyd[750]: Selected source 172.25.254.254 Mar 22 04:26:25 servera root[1213]:Log files synchronized
Exit and close the extra terminal.
[student@serverb ~]$ exit
logout
Connection to serverb closed.
[student@workstation]$Return to the workstation machine as the student user.
[student@servera ~]$ exit
logout
Connection to servera closed.
[student@workstation]$This concludes the section.