Bookmark this page

Guided Exercise: Managing Compressed Tar Archives

In this exercise, you will create archive files and extract their contents with the tar command.

Outcomes

You should be able to archive a directory tree and extract the archive content to another location.

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

From workstation, run the lab archive-manage start command. The command runs a start script that determines if the host, servera, is 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-manage 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. Switch to the root user as only the root user can access all of the content of the /etc directory.

    [student@servera ~]$ su -
    Password: redhat
    [root@servera ~]# 
  3. Use the tar command with the -czf options to create an archive of the /etc directory using gzip compression. Save the archive file as /tmp/etc.tar.gz.

    [root@servera ~]# tar -czf /tmp/etc.tar.gz /etc
    tar: Removing leading `/' from member names
    [root@servera ~]# 
  4. Use the tar command with the -tzf options to verify that the etc.tar.gz archive contains the files from the /etc directory.

    [root@servera ~]# tar -tzf /tmp/etc.tar.gz
    etc/
    etc/mtab
    etc/fstab
    etc/crypttab
    etc/resolv.conf
    ...output omitted...
  5. On servera, create a directory named /backuptest. Verify that the etc.tar.gz backup file is a valid archive by decompressing the file to the /backuptest directory.

    1. Create the /backuptest directory.

      [root@servera ~]# mkdir /backuptest
    2. Change to the /backuptest directory.

      [root@servera ~]# cd /backuptest
      [root@servera backuptest]# 
    3. List the contents of the etc.tar.gz archive before extracting.

      [root@servera backuptest]# tar -tzf /tmp/etc.tar.gz
      etc/
      etc/mtab
      etc/fstab
      etc/crypttab
      etc/resolv.conf
      ...output omitted...
    4. Extract the /tmp/etc.tar.gz archive to the /backuptest directory.

      [root@servera backuptest]# tar -xzf /tmp/etc.tar.gz
      [root@servera backuptest]# 
    5. List the content of the /backuptest directory. Verify that the directory contains the files from the /etc directory.

      [root@servera backuptest]# ls -l
      total 12
      drwxr-xr-x. 95 root root 8192 Feb  8 10:16 etc
      [root@servera backuptest]# cd etc
      [root@servera etc]# ls -l
      total 1204
      -rw-r--r--.  1 root root       16 Jan 16 23:41 adjtime
      -rw-r--r--.  1 root root     1518 Sep 10 17:21 aliases
      drwxr-xr-x.  2 root root      169 Feb  4 21:58 alternatives
      -rw-r--r--.  1 root root      541 Oct  2 21:01 anacrontab
      ...output omitted...
  6. Exit from servera.

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

Finish

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

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

This concludes the guided exercise.

Revision: rh124-8.2-df5a585