Linux
is a really stable and powerful operating system,
just like its Unix cousins. It is also very secure
if set up properly and maintained well. However, despite
all this, accidents do happen, whether you accidentally
type "rm -R /" or someone breaks into your
machine from the internet. That's why you need a good
backup plan. If you have a cd burner and some blank
discs, then this tutorial is just for you. Do note
however that a full backup may not work well after
being restored to a machine with different hardware.
If your hardware is damaged for some reason and you
are forced to buy different hardware, your system
may not run as well as it should after restoration.
Chances are that you will encounter no problems though
and it can't really hurt anything to try, so don't
be afraid to try a complete restoration even if you
do have new hardware.
The
frequency at which you need to backup depends on how
quickly the data on your hard drive changes and how
important the data is. Obviously if you keep important
documents on your hard drive that are worth a lot
to you or your company, then you should probably keep
several sets of discs and rotate through them backing
up every day. That way if your computer had been compromised
a few days ago but you just found out, you'll have
a set of discs with an uncompromised backup to restore.
It may be a lot of work but what's it worth to you?
In my case, I have data on my computer that I don't
want to lose but it's collected over a long period
of time and doesn't change at a fast pace. Also I
don't mind if I have to redo a few things to get my
computer back to where it was. Therefore I only backup
every few weeks. The choice is up to you.
Now
there are two mediums that you can use to make backups.
The first is called cd-r. These discs can only be
written to once. They're cheap but for backup purposes,
will leave you paying more in the long run. The second
medium is called cd-rw. These discs are considerably
more expensive than cd-r discs, perhaps even twice
as much. However the extra cost is well worth it.
These discs can be recorded on thousands of times.
You're more likely to lose or break the discs than
have them wear out from too much recording. They usually
record a little slower too, but most people would
prefer the extra time over extra money. I went out
and bought a 25 pack of cd-rw discs and now I don't
have to worry about buying anymore until I have more
data than will fit on 25 discs.
First
of all, what we want to do is put all of the information
on your hard drive into a tarbell. This is a file
that contains many other files which have been compressed.
For Windows users, it's similar to a .zip file. To
do this, it helps to be in single user mode. This
way we don't have a lot of temporary files opened
that don't need to be backed up. To do this, you simply
log in as root at a terminal (type "su -"
if you're already logged in as your normal user) and
type "shutdown now". It will look like it's
rebooting but will never actually reset. Next it will
ask you for your root password. Go ahead and type
it in. It should then bring you to a command prompt.
At that point, you issue this command:
tar
-cvzf /backup.tar.gz /
This
will backup everything on your system into one tarbell
file. This will take a while and isn't very interesting
so go find something to eat or get some fresh air.
When it finished, you can switch back to multiuser
mode. Just type "telinit 2" replacing 2
with your default runlevel. If you don't know what
it is, just do "shutdown -r now".
You
should eventually get back to the login screen. Log
back in as root. Now this file is probably far too
large to fit on a single cd. Obviously you're going
to have to break it up into several pieces. That's
what the split command is for. You may think 650 megs
is 650 million bytes, but this is not exactly true.
It's actually a little over 681 million bytes. This
is because there are 1024 bytes in a kilobyte, and
1024 kilobytes in a megabyte. But I recommend going
a bit under the actual size of the cd because it has
to make a table of contents and all that jazz. I think
675 million bytes is a good size for each of the split
files. If you have 700 meg cd's, I'd go with 725 million
bytes per split.
Well
first, you have to be at the root directory where
the backup is. Simply type "cd /". Now we'll
use the split command. At the command line, type this:
split
-b 675000000 backup.tar.gz
This
will split our huge files into cd-sized fragments.
It will leave a series of files called xaa, xab, xac,
etc depending on how large your original file was.
Run "ls" to see all the files.
Now
that we have our fragmented files, it's safe to delete
the monolithic file. This can be accomplished with
"rm backup.tar.gz". It may take a few seconds
since it's a big file. Next we want to make iso images
of all of the fragmented files. Iso images are files
that are an exact copy of what have been or should
be on a cd. All burning software makes iso images
before it starts burning, even if it isn't obvious.
For this, Linux has a mkisofs command. There's not
really much to the command. I'm going to give you
a compound command that can take care of all the files
in one command.
for
i in `ls xa*`; do echo -e "$i"; mkisofs
-o $i.iso $i; done
The
echo part of the command will help you keep up with
the progress. This could also take a while. When it's
finally finished, you can finally burn the images
to cd's. Make sure you label the discs. Your backup
will be worthless if you don't remember which order
they go in. There are several burning programs available
for Linux like X-cd-roast. If you want to use one
of these, that's fine, but they're beyond the scope
of this document. I am sticking to the command line.
Now to record cd's, you'll need to know where your
burner is on the SCSI device(s). If you don't already
know, you can execute "cdrecord -scanbus"
to find out. It will display an array of numbers.
On one of these lines, it should display the manufacturer
and model of your burner. You'll need the preceding
three numbers for using cdrecord. If your burner doesn't
show up, then you probably have an IDE burner. You'll
need to set up SCSI emulation into the kernel, but
that also is beyond the scope of this tutorial. Now
you hopefully know where your burner is on the SCSI
chain. From xaa.iso to the final iso, run this command:
cdrecord
-v blank=fast speed=2 dev=0,0,0 xaa.iso
Make
sure you have a blank cd in the drive before each
time you run this command. Each time you run it, change
xaa.iso to the next file in line. I need to explain
some of the options in this command. First of all,
the "dev=0,0,0" specifies the logical location
of your burner. Replace this with the number you got
from earlier. The "speed=2" option specifies
how fast your burner can burn cd's. As you can tell,
I have an old slow burner. Do realize that most burners
burn at a different speed for cd-r discs and cd-rw
discs. Consult the manual or the box it came in for
the speed of it. Last of all, the "blank=fast"
option is used to erase a cd-rw disc if there is data
on it. Even if the disc is new and hasn't yet been
written to, it's safe to use this option. If you use
cd-r discs, you can omit this option.
Congratulations!
You should now have a cd backup of your system. If
you would like to combine all of that into a script
file, it's quite simple. I won't go into how to make
a script file since it involves many steps, but I
will give you the contents of my script file. The
first step of creating the tarbell needs to be done
in single-user mode, so I have left that part out
of the script.
cd /
echo -e "splitting tar"
split -b 675000000 backup.tar.gz
echo -e "removing original tar"
rm backup.tar.gz
echo -e "making iso images"
for i in `ls xa*`
do echo -e "$i"
mkisofs -o $i.iso $i
done
echo -e "removing broken tars"
rm xa[a-z]
echo -e "start recording to cd"
for i in `ls xa[a-z].iso`
do echo -e "insert blank disc and press ctrl+d"
cat >> /dev/null
cdrecord -v blank=fast speed=2 dev=0,0 $i
done
echo -e "removing iso images"
rm xa[a-z].iso
Now
that you have backups, you need to know how to restore
them. Well luckily it's a bit less complicated than
backing them up. However, you will need a partly functioning
Linux system in order to restore. As long as you can
get to the command line as root, you're probably good
to go. Otherwise you may have to reinstall Linux before
you can proceed with restoration. I'll assume you
have Linux working already and proceed with the tutorial.
First of all, you have to get those split files off
of the cd's and put them onto your hard drive. You
can either copy them all from your cd's and then join
them together, or you can join them as you copy them.
The latter choice requires less free hard drive space
so I'll explain that method.
First,
you must mount your cd-rom. For me, it is done like
this:
mount
/cdrom
On
many Linux distros, you would replace /cdrom with
/mnt/cdrom. If neither of these will mount, then your
cd-rom is probably not set up and you'll need to take
care of that. But again, that's not directly related
to this tutorial so I won't go into that.
Next,
you need to copy the files one by one into a massive
zip file on your hard drive. We named the file backup.tar.gz
before it was split, so why not name it the same thing
again? It really doesn't matter what you name it though
as long as it ends with .tar.gz. Moving right along,
to copy the first fragment to the file, type this:
cp
/cdrom/xaa /backup.tar.gz
Again,
depending on your distro, you may need to change /cdrom
to whereever your cd-rom gets mounted to. It could
take a few minutes because this file is huge. This
is where it's nice to have something else to do (like
watch television) while the file is copying, especially
if you have a lot of cd's to go through.
After
the first file is finished, you will need to unmount
your cd-rom drive. You cannot remove the cd until
you unmount it. Simply use the umount command like
so:
umount
/cdrom
Note
that umount does not have an 'n' in it. Don't ask
me why. I can only guess that some programmer wasn't
all that great at spelling. If your backup is on only
one cd, you can skip the next few steps and continue
to extracting the file.
Otherwise,
next you'll need to put the second cd in and mount
it just like before. What is different though is that
you won't be copying the file to the hard drive, you'll
be appending it to the one that's already there. You
go about that like this:
cat
/cdrom/xab >> backup.tar.gz
Just
like before, this can take a few minutes. Continue
swapping cd's and concatenating (joining) the files
until you've ran out of cd's. Now you have your original
zip file.
To
extract that baby, type:
tar
-xvpzf backup.tar.gz
This
will extract the monolithic zip file to your hard
drive, returning your system to roughly the way it
was before the backup. This also could take a little
while, but not as long as all the cd's did. Note that
if there's currently a file on your hard drive that
wasn't in the backup, that file will continue to remain
like it is. However, if there's a file both on the
hard drive and the backup, it will be overwritten.
If you do not want this, you can add the k flag somewhere
among those crazy letters after the hyphen. I do not
recommend it when doing a full restoration though
because if there are corrupt files on the disk, they
will remain corrupt and if you've reinstalled, it
may add programs and files without notifying other
programs of their existance. (For instance, in Debian,
it could install a program but since it doesn't overwrite
dpkg's database file, dpkg wouldn't know it was installed
and that could have serious consequences.) So unless
you're just restoring /home or something that won't
affect how the system works, or you really know what
you're doing, don't use the k option.
Also,
if you've reinstalled Linux since the backup or you've
compiled another kernel, you'll need to run lilo to
avoid crashes during reboot. Even if you haven't done
either of these, it still wouldn't be a bad idea.
Simply type "/sbin/lilo" at the command
line as root and hopefully all will go well. I can't
think of any reason it wouldn't unless the configuration
was misconfigured before backup.
That's
it! If you follow this tutorial, you should be safe
should disaster hit. If you want more information
on specific commands, type "man" followed
by a space and the command name. If you have questions
or problems that the man pages couldn't help, contact
me at snailboy1@yahoo.com. I usually respond within
a day. Enjoy the power and versatility of Linux.
|