Now come on then,
let's go through and find our command line and take a look at
investigating some of the basics of our tar operations.
Oh, and look at this, a glorious AlmaLinux 8 device,
and we're ready at the command line.
Now if I go through and just take a look at du ‑s,
for a summary we're looking at the disk usage of a directory.
We don't want to see each individual file within that directory.
We're going to make it human readable,
and we're going to go through and take a look at the etc directory.
Now, you can see there that we can't see the complete etc directory,
so we're seeing 23 MB, but we're also getting some errors coming back,
indicating that we don't have access.
If we run the same command again to do a sudo and
then bang bang or exclamation mark, exclamation mark,
I can use Ctrl+l and move this to the top of the screen,
but that shortcut is repeating the same command with
all of its options and arguments, but this time with sudo in front of it.
We can see there's not a lot of difference from what I couldn't read,
but this way we are proving that we are reading everything,
and we see 23 MB of data.
Let's go through then and create ourselves a tar archive.
Again, I'm going to do it with sudo so we can back up everything.
So if I go through and use sudo and then tar,
now we've got long options or short options,
so I can use ‑‑create ‑‑file, but I can equally use ‑c and ‑f.
And obviously, with the short options, I can push them together.
The file is pointing through to our archive,
so I want to write to a new file, etc.tar.
We can then specify that we are backing up,
let's say, our etc directory, and then away we go.
Now importantly, don't ignore that line that we see on the screen,
removing the forward slash from member names.
We don't back up by default with a full path.
So if I go through and take a look inside of my archive,
I'm just going to up arrow key, and then we can go through and test our archive.
So this is really verifying, so it will be ‑t or ‑‑verify.
Take a look inside of our tar file, and obviously,
we don't need the directory there.
And again, there's nothing missing from the left‑hand side of my screen.
Believe me, it's not.
We are looking then at relative paths, etc and locale.
So if I clear the screen, now, having created my archive, before we forget,
I want to demonstrate the difference in the file sizes.
So if I go through and run an ls ‑lh for human readable and then take a
look at our etc.tar file, well, we can see this is 23 MB. This was the
same as the disk usage that we were looking at.
So you might not think that it's any smaller. But obviously, this is
convenient units for us to look at. It may well be a little bit smaller.
If I go through and just up arrow key, and we can then go through and
take a look at it in different units.
So if I go through, instead of human readable,
if I go through and put ‑‑block‑size,
see, even to commands you might be very familiar with, there's always extra
options that we can look at. And if I then go through and put, let's say,
=1K, now when we go through and look at it,
we can see then that it's in 22,620K.
So we've got a much smaller unit, but it's still quite readable.
Let's compare that when we do our sudo and du ‑summary, but instead of using ‑h,
we're now going to go through and specify the unit that we want.
So we want it in k for our /etc directory, and with that we
can see it's 23,000 instead of 22. Okay,
it's just short of 1000 difference.
We've probably got something like a difference of 800 or something like that.
So yeah,
we're 23,400 to 22,600, so about 800K difference when we take a look at it.
But even so, it's a difference, and this difference
is just better disk utilization.
Okay,
I'm going to clear the screen. Now with the file size
sorted out, we can look at extracting those files and not
forgetting about the relative path.
So I'm working in the vagrant user home directory, and I
can go through and extract the file or even take a look at
the file from this directory.
If I go through and use the tar and using the option ‑x,
we will extract, and when we go through and take a look at our file,
etc.tar, it will have extracted through to my current directory,
the working directory. So listing in here, now we can see that
we've got the etc directory is expanded to,
if you like an offline copy of etc. Then you're going to say,
well, that's okay, but what if I really did need to
go through and restore something?
We had a disaster in the etc directory.
Well, don't worry.
we can create disasters in the etc directory if that's really what you want.
Let's be careful and just do a sudo rm /etc/hosts.
And obviously, the host file isn't generally going to be too
much, so we can go through and see that we have removed it
and we don't have that file,
no such file or directory. Now moving out to our root
directory, then relative to the root directory,
we do have the etc directory, so I can then go from here as my
working directory, tar ‑xf, pointing through into the vagrant users
home directory, and then the etc.tar file.
And the reality is, I only need to extract etc/hosts, so again,
a relative path. Now as I go through and repeat the cat command,
so !ca, look at this, nobody's noticed we've got our host file back before it caused any damage.