Hey guys and welcome back. So the first tool or utility that I want to talk to you about
with respect to our backup operations is the tar command. This is the tape archive utility.
So we can with this tool ultimately group together files and or directories into one
particular archived file otherwise known as a tar ball. Now like I say the original
medium for this tool was going to be those magnetic tapes but we do not have to use such
a medium of course. We can still get the benefits of the tar utility no matter where we want
to copy our data to eventually. So when we use the tar command we have some particular
options we have to know about the dash C flag is going to allow us to create an archive.
This is going to be a very valuable one to understand. Whereas if we want to extract
an archive we would use the dash X flag for extraction. If we want to list the contents
of an archive we can use the dash T flag which is not very intuitive. You would expect something
like say dash L but no in fact it is dash T. When we want to specify and target a particular
file we will use the dash F flag to point to a particular file. Now when we want to
actually extract the archive to another directory when we're doing the extraction we want to
use dash capital C. So small case C is going to allow us to create an archive. Capital
C is going to allow us to choose a directory to extract that archive to. Now you also may
remember tar does not have to be used with compression but of course it very often is
because this is very efficient. If we want to invoke different types of compression we
have particular flags. The dash Z flag is going to allow us to use the GZ compression.
Whereas the dash lowercase J that is going to allow us to use BZ2 base compression and
if we want to use dash capital J that will allow us to use XZ compression. So how about
we actually use this utility and try some backups then. So what we'll do here is I'll
go to my command line here we have right here. Now remember we talked about in the very first
nugget some of the locations whereby we would want to backup. So that may be things like
the etsy directory. It also may be your actual home directory. We also might want to go into
the var directory and backup maybe say the mail file or perhaps maybe backup the backups
directory. So how about we actually give an example of doing such a thing then. So I'll
go back to my main directory right here and what I will do is I will say tar and I will
use dash C that's going to create an archive. We will use V to be verbose. We will use dash
lowercase J. This means that the archive will be filtered via the BZ2 compression and we'll
use F to target a particular file IE. What will the file actually be called. So what I'll call
this is just simply backup and I'll give it the extension TBZ. That is because it's going to be a
tar ball with BZ compression. Keep things nice and clear and now what I want to do is to specify
what it is I actually want to backup. So I could target say for example the home IPv0 directory.
I could target the var log directory as well as maybe the var mail directory and maybe say the var
backup directory and maybe say also the etsy directory. So these are all the targets that I
want to include. So if I just hit enter check this out. What we're actually going to be doing here
is creating this particular archive. So this may take a little bit of time. Oh and we actually
have a failure status. This will no doubt be because I need to have super user privileges to
access some of these locations. So what I'll do here is I'll just delete this backup. Let's go up
the errors. Let's arrow up and I'll use super user privileges. Type in my password. Try that again.
Okay perfect. So now we actually don't get our errors and we can see here we actually have
our backup tar ball which is being compressed with BZ compression. Now like I say if I wanted to
extract this backup then I could do that using the X flag. Now also if I wanted to target a
particular backup directory let's maybe create a directory just called my backups. Now we have
this new directory right here. What I can now do is I can use that same command tar. This time I'm
not going to say dash C to create a directory or to create an archive. Should I say I'm going to use
dash X to extract a tar ball and I will use V to be verbose. You want to use J because it is using
BZ to compression and I will say F to target the file and now just specify the file backup.tbz. Now
I actually want to extract this to a particular location. My backups. Can you remember the flag
we're going to use to extract to a particular directory that is going to be dash capital C
and now I can just give the path of home IPv0 my backups. So if I hit enter this is going to
extract all this information which will take a little bit of time and it's going to dump that
information into that directory. Okay so if we do an LS we can see what we have here if I go into
my backups now. I do an LS check this out we actually have my home directory the var directory
and the exit directory so if I go into say for example CD var we don't have all the contents
of that but we do have the directories or the sub directories that we actually targeted say for
example the mail that we wanted to backup the log as well as the backups directory and again if we
go into these particular folders we can do an LS we can see we have all of these particular files
which are here and again go into log LS all these files we go back out same if I go into my home
directory we see the IPv0 directory and again we have a backup of my directory structure right here.
So as we can see here using the tar command it's going to be very valuable when we want to target
particular files and directories for backup we can ultimately group everything together
into one nice neat file and we can extract that file or if we want we can share that file or
transfer that file to another server. Now how on earth would we actually go about transferring
this file to say for example another remote server? Well the good news is that that is what we're going
to be talking about in the very next nuggets I hope this has been informative for you and I'd like
thank you for viewing.