In this lab, you 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
On serverb, synchronize the /etc directory tree from servera to the /configsync directory.
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 ~]#
Create the /configsync directory to store the synchronized files from servera.
[root@serverb ~]# mkdir /configsyncSynchronize 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.00Create a configfile-backup-servera.tar.gz archive with the /configsync directory contents.
Create a gzip compressed archive.
[root@serverb ~]# tar -czf configfile-backup-servera.tar.gz /configsync
tar: Removing leading `/' from member namesList 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.confSecurely copy the /root/configfile-backup-servera.tar.gz archive file from serverb to the /home/student directory on workstation.
[root@serverb ~]#sftp student@workstationstudent@workstation's password:studentConnected to workstation. sftp>put configfile-backup-servera.tar.gzUploading 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
On workstation, extract the contents to the /tmp/savedconfig/ directory.
Return to the workstation system as the student user.
[root@serverb ~]#exitlogout [student@serverb ~]$exitlogout Connection to serverb closed. [student@workstation]$
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]$
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.confExtract the archive contents to the /tmp/savedconfig/ directory.
[student@workstation savedconfig]$ tar -xzf ~/configfile-backup-servera.tar.gzList 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...Return to the student user's home directory.
[student@workstation savedconfig]$ cd
[student@workstation ~]$This concludes the section.