Red Hat System Administration II
Synchronize the contents of a local directory with a copy on a remote server, by using the rsync command.
Outcomes
Use the
rsynccommand 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
workstationmachine, use thesshcommand to log in to theserveramachine as thestudentuser, and then switch to therootuser.[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
serverbmachine as thestudentuser.[student@workstation ~]$
ssh student@serverb...output omitted... [student@serverb ~]$Create the
/home/student/serverlogsdirectory on theserverbmachine. Use thersynccommand to securely create an initial copy of the/var/logdirectory tree on theserveramachine in the/home/student/serverlogsdirectory on theserverbmachine.On the
serverbmachine, create the/home/student/serverlogsdirectory to store the synchronized log files from theserveramachine.[student@serverb ~]$
mkdir ~/serverlogsOn the
serveramachine, use thersynccommand to synchronize the/var/logdirectory tree on theserveramachine to the/home/student/serverlogsdirectory on theserverbmachine. Only therootuser can read all the/var/logdirectory contents on theserveramachine. 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
serveramachine, execute thelogger "Log files synchronized"command to add an entry in the/var/log/messageslog file to reflect when the last synchronization occurred.[root@servera ~]#
logger "Log files synchronized"Use the
rsynccommand to securely synchronize from the/var/logdirectory tree on theserveramachine to the/home/student/serverlogsdirectory on theserverbmachine. 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.26On the
serverbmachine, verify the contents of the/home/student/serverlogs/log/messagesfile with thetailcommand.[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 synchronizedExit and close the extra terminal.
[student@serverb ~]$
exitlogout Connection to serverb closed. [student@workstation]$Return to the
workstationmachine as thestudentuser.[student@servera ~]$
exitlogout Connection to servera closed. [student@workstation]$