Instructor: System backups.
There are many different ways
that you could do your system backup.
But one particular way that I wanted to cover
in this lesson is through the dd command.
dd command comes all the way during the beginning
when they started doing the backups on tapes.
So that's when they would run the dd command.
So basically there are five different type
of backups in every system.
The first type of backup is the actual entire system backup,
where you take the entire image using tools
like third party tools.
People have built third party tools
and such as acronis, Veeam, Commvault
and many other different software out there.
One of them is also that I worked in the past
was NetBackup.
So just like that there are so many software
people have or built and sell to the companies
that allow them to perform system backups.
And that is to again, to create the entire system backup
and put it like an image, just like an ISO,
an entire system.
And whenever there's a need, it does the restore
of everything and put it into the same existing system
if it has crashed or to a new system.
The second type of backup is the application backup.
Application backup are the ones
like you have your Linux machine running, right?
Or even Windows machine running, that's a operating system,
but you use that operating system to have some kind
of application installed on it, right?
So again, as I said in the very beginning,
that the purpose of hardware
is to have the operating system on it
and the purpose of having an operating system
is to run certain applications.
So that's the primary reason we all use computers.
So anyway, the second type of backup
are the application backups.
Any application that you're running in the system.
So to do the backup of the application,
most of the people use
the third party application solutions.
Then we have the database backup.
So if your system is running any kind of database,
for example Oracle or SQL or Informix,
most of these companies who actually deal with database
or provide databases also provide backup solution
for that database.
For example, Oracle has a solution called Dataguard
and SQL would have a solution for SQL backup.
It does the backup of the entire database.
Now remember this is not the backup
of your file system or even of your system.
This is the backup of only the data that is being generated
by the application running on your system.
Okay, so the fourth type of backup
is the file system backup.
The file system backup, meaning backing up your files,
your folders, your directories,
and you could use the commands for those type of backup.
And those commands could be like Tar, Gzip to compress it,
compress the entire directory, and then you could,
once you have a backup, with a tarball
you could actually transfer it
to another machine or copy it to a remote machine.
So in case you need to restore your file or directory
you could go back to that tarball
and extract it from that zip file.
Now you could use that manually
as a manual process to tar it
and transfer to another system
if you do not have a professional third party product
to do that for you.
If you do have a third party backup software
then most likely those third party backup software
would also let you do the file system backup.
The fifth type of backup, which is the main concern
for this lesson, is the disk backup
or doing a disK cloning using the dd command.
What is disk backup or disk cloning?
Well, if you think of it as if you have a disk, right?
Let's say just a physical disk and it is,
let's say 146 gig of disk and it has all the data inside,
file system, partition or whatever,
when you use the dd command, you could actually copy
or clone the entire disk and clone it to another disk.
Now keep one thing in mind, that dd command does not
know what's inside of that clone
or what the file looks like.
It would be, even if you try to open that file,
it would be just garbage, you won't see anything.
So it actually does the backup of your entire disk
and put it in some kind of image.
It is either just image file or ISO file
and exactly takes that, exactly the disk copy or image
or snap of your disk and put it and slap it on another disk.
So this is what we're gonna do in this lesson.
So dd is a command line utility for Unix
and Unix-like operating systems
whose primary purpose is to convert and copy files.
As a result, dd can be used for tasks
such as backing up the boot sector of a hard drive
and obtaining a fixed amount of random data.
Moving on to backup or clone an entire disk
to another hard disk connected to the same system,
execute the dd command as shown below.
And the command is dd if= the source file name.
And if you have a source partition or a source disk,
to, which in this case we don't use the to we use
of= target file name,
which could be the file name itself
or the disk or the disk partition.
And then you could also use different options
that are available with dd command.
As an example, if you see right here,
it look like this, dd if=/dev/sda,
of=/dev/sdb.
What this is doing right here is it's copying,
right here, is copying the entire desk,
not the partition, copying the entire desk, which is sda
and actually slapping it
or putting that entire image on sdb.
But also keep in mind if you are copying sda,
which is two gig, and copying it over sdb,
which is one gig, then of course it's not gonna work.
Make sure the sda and sdb
both have the exact same size of disks.
To copy backup the disk partition,
now we are talking about partition,
you know, each disk could have multiple partitions,
you could use a command like dd if, dev, sda1
and copy it to a disk or a file system
using the name of the file.
You could use the name as sda1.img.
Now to do the restore, restoring this image file
to other machine after copying the img,
meaning if you already have this command ran
and you already copied this entire partition
and you copied it and named it an sda1.img
and you put it in /root,
now once that copy or dd cloning process is done
you could take this image and transfer over
to another machine if you wanted to copy the entire content.
Once it's transferred over to another machine
then you could run a command on the destination machine
as dd if, /root/sda1 and you could put it on sdb3
or 4 or whichever partition that you want to put
that file system on.
So that's how the dd command works.
Let's try it out, practically,
how it looks like on our Linux machine.
Okay, so I am logged in as myself
I am in root directory and I am in the correct server.
To run the dd command, you will have to be root.
Okay, so in my example, let's see, df -h.
Let's say if I wanted to copy, let's say this /boot
which is about, the size is one gig.
I want to copy this partition to another disk
which is sdb1, /data.
So what I could do is dd if, sorry, if=sda1
to, I will copy it over to data
because I'm doing the partition
I'm not copying the disk to disk.
So if I were to copy disk to disk
I would do /dev/sda, sorry, sdb1.
So this is copying partition to partition, sorry.
If I'm copying disk to disk I'll take out the 1
and I'll take out the 1 here.
So anyway, I'm copying partition to file system
which is data and I want to call it boot.img.
So this is the image of the boot.img, hit Enter.
Okay, it says unrecognized operand data.
Oh, see I missed one thing.
I did not specify of=.
It's okay, it happens.
Even people like me make mistakes, that's fine.
Okay, so I'll hit Enter now.
Okay, now you'll see it is actually working
and the reason it's working is because you did not
get an error message right away.
Now depending on the size of your source,
the size of my source as you see here, is used, is 157
and the size is 1014.
Now you're probably thinking,
"Hey, this partition is only has 157M
"and why it's taking that long?"
Well, when you do dd command
it does not care what is used and what is available.
It only looks for the size, which is this,
and it thinks that this is the complete size,
and I'm gonna copy this size exactly as is.
As you can see right here it says,
this is the size, 1.1 gig copied.
See, it doesn't care what is used and what is not used.
It thinks of it as, oh,
I'm gonna take a snapshot of this entire disk and that's it.
Now it did copy it.
Now let's verify it because it copied it to /data/boot.img.
And you hit Enter.
You'll see this is the size, this is a copy.
Now you have a copy of your boot.
Now in case something goes wrong to your system
or your /boot, file system gets corrupted,
you could actually do this and restore here.
And to do the restore, you would have to do
dd if=/data/boot.img.
Where? To /dev/sda1.
That's how you would do it.
But I do not want to do it.
I don't want to mess up my system right now it's just a lab.
But you know, I wouldn't recommend you to try
on your production system as well.
But if your system is down
then that's how you will recover your file system.
But what you could do is you could try to do that
to another file system
if you have a file system
that is just used for testing.
Anyway, so this is how the dd command works
and this is how the dd command is used
to perform system backup to do the disk copying
or disk cloning.
Again, I'll go back real quick to my previous slide.
There are five different type of backups
and that is something that you should know,
what are the different type of backups
and how backups are performed.