Bookmark this page

Lab: Archive and Transfer Files

Use the tar, rsync, and sftp commands to archive and back up the contents of directories.

Outcomes

  • 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.

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. It also installs SSH keys on your systems so that you can transfer files without entering passwords.

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

Instructions

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

    1. Log in to serverb as the student user and switch to the root user.

      [student@workstation ~]$ ssh student@serverb
      ...output omitted...
      [student@serverb ~]$ sudo -i
      [sudo] password for student: student
      [root@serverb ~]#
    2. Create the /configsync directory to store the synchronized files from servera.

      [root@serverb ~]# mkdir /configsync
    3. Synchronize the /etc directory tree from servera to the /configsync directory on serverb.

      [root@serverb ~]# rsync -av root@servera:/etc /configsync
      receiving incremental file list
      etc/
      etc/.pwd.lock
      etc/.rht_authorized_keys
      ...output omitted...
      sent 11,519 bytes  received 20,203,285 bytes  40,429,608.00 bytes/sec
      total size is 20,150,298  speedup is 1.00
  2. Create a configfile-backup-servera.tar.gz archive with the /configsync directory contents.

    1. Create a gzip compressed archive.

      [root@serverb ~]# tar -czf configfile-backup-servera.tar.gz /configsync
      tar: Removing leading `/' from member names
    2. 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.

    [root@serverb ~]# sftp student@workstation
    student@workstation's password: student
    Connected to workstation.
    sftp> put configfile-backup-servera.tar.gz
    Uploading configfile-backup-servera.tar.gz to /home/student/configfile-backup-servera.tar.gz
    configfile-backup-servera.tar.gz                 100% 4933KB 359.5MB/s   00:00
    sftp> bye
  4. On workstation, extract the contents to the /tmp/savedconfig/ directory.

    1. Return to the workstation system as the student user.

      [root@serverb ~]# exit
      logout
      [student@serverb ~]$ exit
      logout
      Connection to serverb closed.
      [student@workstation]$
    2. Create the /tmp/savedconfig directory, to store the extracted contents. Change to the new directory.

      [student@workstation ~]$ mkdir /tmp/savedconfig
      [student@workstation ~]$ cd /tmp/savedconfig
      [student@workstation savedconfig]$
    3. 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
    4. Extract the archive contents to the /tmp/savedconfig/ directory.

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

      [student@workstation savedconfig]$ ls -lR
      .:
      total 0
      drwxr-xr-x. 3 student student 17 Mar 28 16:32 configsync
      
      ./configsync:
      total 12
      drwxr-xr-x. 105 student student 8192 Mar 28 16:03 etc
      ...output omitted...
    6. Return to the student user's home directory.

      [student@workstation savedconfig]$ cd
      [student@workstation ~]$

Evaluation

As the student user on the workstation machine, use the lab command to grade your work. Correct any reported failures and rerun the command until successful.

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

Finish

On the workstation machine, change to the student user home directory and use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

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

Revision: rh134-9.3-5fd2368