Red Hat System Administration II
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/etcdirectory tree fromserverato the/configsyncdirectory.Log in to
serverbas thestudentuser and switch to therootuser.[student@workstation ~]$
ssh student@serverb...output omitted... [student@serverb ~]$sudo -i[sudo] password for student:student[root@serverb ~]#Create the
/configsyncdirectory to store the synchronized files fromservera.[root@serverb ~]#
mkdir /configsyncSynchronize the
/etcdirectory tree fromserverato the/configsyncdirectory onserverb.[root@serverb ~]#
rsync -av root@servera:/etc /configsyncreceiving 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
Create a
configfile-backup-servera.tar.gzarchive with the/configsyncdirectory contents.Create a
gzipcompressed archive.[root@serverb ~]#
tar -czf configfile-backup-servera.tar.gz /configsynctar: Removing leading `/' from member namesList the contents of the
configfile-backup-servera.tar.gzarchive.[root@serverb ~]#
tar -tzf configfile-backup-servera.tar.gz...output omitted... configsync/etc/vimrc configsync/etc/wgetrc configsync/etc/xattr.conf
Securely copy the
/root/configfile-backup-servera.tar.gzarchive file fromserverbto the/home/studentdirectory onworkstation.[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>byeOn
workstation, extract the contents to the/tmp/savedconfig/directory.Return to the
workstationsystem as thestudentuser.[root@serverb ~]#
exitlogout [student@serverb ~]$exitlogout Connection to serverb closed. [student@workstation]$Create the
/tmp/savedconfigdirectory, 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.gzarchive.[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
etcfiles.[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
studentuser's home directory.[student@workstation savedconfig]$
cd[student@workstation ~]$