Bookmark this page

Lab: Archiving and Transferring Files

Performance Checklist

In this lab, you will use tar, rsync, and scp to archive and back up the contents of directories.

Outcomes

You should be able to:

  • Synchronize a remote directory to a local directory.

  • Create an archive of the contents of a synchronized directory.

  • Securely copy an archive to a remote host.

  • Extract an archive.

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

From workstation, run the lab archive-review start command. The command runs a start script that determines whether hosts servera and serverb are reachable on the network. The script also ensures that the files and directories to be created in the lab do not exist on serverb, and workstation.

[student@workstation ~]$ lab archive-review start
  1. On serverb, synchronize the /etc directory tree from servera to the /configsync directory.

    1. Use the ssh command to log in to serverb as the student user.

      [student@workstation ~]$ ssh student@serverb
      ...output omitted...
      [student@serverb ~]$ 
    2. Use the su command to switch to the root user because creating the /configsync directory requires superuser privileges. In later steps, you will archive the files present in the /etc directory tree, which are owned by the root user this also requires superuser privileges.

      [student@serverb ~]$ su -
      Password: redhat
      [root@serverb ~]# 
    3. Create the /configsync directory to store the synchronized configuration files from servera.

      [root@serverb ~]# mkdir /configsync
    4. Use the rsync command to synchronize the /etc directory tree from servera to the /configsync directory on serverb.

      Be aware that only the root user can read all the content in the /etc directory on servera.

      [root@serverb ~]# rsync -av root@servera:/etc /configsync
      root@servera's password: redhat
      receiving incremental file list
      etc/
      etc/.pwd.lock
      ...output omitted...
      etc/yum/protected.d -> ../dnf/protected.d
      etc/yum/vars -> ../dnf/vars
      
      sent 10,958 bytes  received 21,665,987 bytes  3,334,914.62 bytes/sec
      total size is 21,615,767  speedup is 1.00
  2. Use gzip compression to create an archive named configfile-backup-servera.tar.gz with the contents of the /configsync directory.

    1. Use the tar command with the -czf options to create a gzip compressed archive.

      [root@serverb ~]# tar -czf configfile-backup-servera.tar.gz /configsync
      tar: Removing leading `/' from member names
      [root@serverb ~]# 
    2. Use the tar command with the -tzf options to list the contents of the configfile-backup-servera.tar.gz archive.

      [root@serverb ~]# tar -tzf configfile-backup-servera.tar.gz
      ...output omitted...
      configsync/etc/vimrc
      configsync/etc/wgetrc
      configsync/etc/xattr.conf
  3. Securely copy the /root/configfile-backup-servera.tar.gz archive file from serverb to the /home/student directory on workstation as the student user using student as the password.

    [root@serverb ~]# scp ~/configfile-backup-servera.tar.gz \
    student@workstation:/home/student
    ...output omitted...
    student@workstation's password: student
    configfile-backup-servera.tar.gz            100% 5110KB  64.5MB/s   00:00
  4. On workstation, extract the contents of the /home/student/configfile-backup-servera.tar.gz archive to the /tmp/savedconfig/ directory.

    1. Exit from serverb.

      [root@serverb ~]# exit
      logout
      [student@serverb ~]$ exit
      logout
      Connection to serverb closed.
      [student@workstation]$ 
    2. Create the /tmp/savedconfig directory, where the contents of the /home/student/configfile-backup-servera.tar.gz archive will be extracted.

      [student@workstation ~]$ mkdir /tmp/savedconfig
    3. Change to the /tmp/savedconfig directory.

      [student@workstation ~]$ cd /tmp/savedconfig
      [student@workstation savedconfig]$ 
    4. Use the tar command with the -tzf options to list the contents of the configfile-backup-servera.tar.gz archive

      [student@workstation savedconfig]$ tar -tzf ~/configfile-backup-servera.tar.gz
      ...output omitted...
      configsync/etc/vimrc
      configsync/etc/wgetrc
      configsync/etc/xattr.conf
    5. Use the tar command with the -xzf options to extract the contents of the /home/student/configfile-backup-servera.tar.gz archive to the /tmp/savedconfig/ directory.

      [student@workstation savedconfig]$ tar -xzf ~/configfile-backup-servera.tar.gz
      [student@workstation savedconfig]$ 
    6. List the directory tree to verify that the directory contains files from the /etc directory.

      [student@workstation savedconfig]$ ls -lR
      .:
      total 0
      drwxr-xr-x. 3 student student 17 Feb 13 10:13 configsync
      
      ./configsync:
      total 12
      drwxr-xr-x. 95 student student 8192 Feb 13 09:41 etc
      
      ./configsync/etc:
      total 1212
      -rw-r--r--.  1 student student     16 Jan 16 23:41 adjtime
      -rw-r--r--.  1 student student   1518 Sep 10 17:21 aliases
      drwxr-xr-x.  2 student student    169 Feb  4 21:58 alternatives
      ...output omitted...
  5. On workstation return to the student home directory.

    [student@workstation savedconfig]$ cd

Evaluation

On workstation, run the lab archive-review grade script to confirm success on this lab.

[student@workstation ~]$ lab archive-review grade

Finish

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

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

This concludes the lab.

Revision: rh124-8.2-df5a585