Chapter 13: Archive and Transfer Files

In this blog post, I will be sharing my experience with the Archive and Transfer Files lab from Chapter 13 of RH124. This lab was focused on three main commands - tar, rsync, and sftp - and their usage for archiving and transferring files and directories. As someone who is always looking for efficient and secure ways to manage and back up my data, I found this lab particularly interesting and informative. The lab had four tasks in total, each of which involved working with one or more of these commands. The first task was to create a compressed archive of a directory using the tar command. The second task was to extract the contents of an existing tar archive. The third task was to securely transfer files to a remote system using the sftp command. And finally, the fourth task was to synchronize the contents of a local file or directory with a remote server copy using the rsync command. Throughout the lab, I gained a deeper understanding of how these commands work and how they can be used to streamline the process of backing up and transferring files. In the following sections, I will be sharing my step-by-step approach to each of the tasks, along with some tips and tricks that I learned along the way. So if you're interested in learning more about these powerful commands and how they can be used to manage your files more efficiently, keep reading!

Question 1: On serverb, synchronize the /etc directory tree from servera to the /configsync directory.

Solution:

To complete the task, I started by accessing serverb from my workstation using the ssh command with my username (student) and the hostname of serverb. Next, I switched to root on serverb using the sudo -i command to gain the necessary privileges to access the system directories, including /etc. To create the destination directory for the synchronization, I used the mkdir command to create the /configsync directory. To synchronize the directories, I used the rsync command, which is a utility for syncing files between directories. I used the -av options with the rsync command to ensure that the source directory is root@servera:/etc. The : separator in the root@servera:/etc argument is critical as it specifies the source directory on servera from which the files are being synchronized. The /etc directory is the directory we are synchronizing from and into the /configsync directory on serverb.

Question 2: Create a configfile-backup-servera.tar.gz archive with the /configsync directory contents.

Solution:

To create the configfile-backup-servera.tar.gz archive with the contents of the /configsync directory, I used the tar -czf configfile-backup-servera.tar.gz /configsync command. The tar utility with the appropriate options. The tar utility is used to create archives, and I used the -czf options with the tar command. The c option stands for create, and the z option allows for compression of the resulting archive, which helps to reduce its size. The f option is used to specify the name of the resulting archive, which in this case is configfile-backup-servera.tar.gz. I specified the directory to be included in the archive by providing the path to the /configsync directory as an argument to the tar command.


Question 3: Securely copy the /root/configfile-backup-servera.tar.gz archive file from serverb to the /home/student directory on workstation.

Solution:

To securely copy the configfile-backup-servera.tar.gz archive file from serverb to the /home/student directory on the workstation, I used the sftp command. First, I connected to the workstation using sftp and logged in as the student user. Then, once I was connected, I used the put command to transfer the configfile-backup-servera.tar.gz file from serverb to the /home/student directory on the workstation.

Question 4: On workstation, extract the contents to the /tmp/savedconfig/ directory.

Solution:

After logging out of serverb, I switched back to the workstation and used the command mkdir /tmp/savedconfig to create the directory where the contents of the configfile-backup-servera.tar.gz archive will be extracted to. Then, I changed to that directory using cd /tmp/savedconfig. Finally, I extracted the contents of the configfile-backup-servera.tar.gz archive into the current directory using the command tar -xzf ~/configfile-backup-servera.tar.gz. The x option tells tar to extract files, the z option specifies that the archive is compressed with gzip, and the f option specifies the name of the archive to extract from (~/configfile-backup-servera.tar.gz).

Conclusion:

In conclusion, the tar, rsync, and sftp commands are powerful tools that can simplify file management tasks, especially when dealing with large and complex directory structures. With these tools, you can easily archive and back up the contents of directories, transfer files securely between systems, and synchronize the contents of local and remote directories efficiently and securely. I hope that this guide has been helpful in providing step-by-step instructions for using these tools. However, if you have any questions or feedback on this post, please feel free to leave your comments below. I appreciate your input and I am always looking for ways to improve my content to better serve my readers.