Menus

Jun 4, 2016

Explain The Backup Process In Linux

What to back up?

The file-based nature of Linux is a great advantage when backing up and restoring the system.
Configuration files are text based and, except for when they deal directly with hardware, are largely system independent. The modern approach to hardware drivers is to have them available as modules that are dynamically loaded, so kernels are becoming more system independent.
Rather than a backup having to deal with the intricacies of how the operating system is installed on your system and hardware, Linux backups are about packaging and unpackaging files.

In general, there are some directories that you want to back up:
  • /etc
contains all of your core configuration files. This includes your network configuration, system name, firewall rules, users, groups, and other global system items.
  • /var
contains information used by your systems daemons (services) including DNS configurations, DHCP leases, mail spool files, HTTP server files, db2 instance configuration, and others.
  • /home
contains the default user home directories for all of your users. This includes their personal settings, downloaded files, and other information your users don’t want to lose.
  • /root
is the home directory for the root user.
  • /opt
is where a lot of non-system software will be installed. IBM software goes in here. OpenOffice, JDKs, and other software is also installed here by default.
There are directories that you should consider not backing up.
  • /proc
should never be backed up. It is not a real-file system, but rather a virtualized view of the running kernel and environment. It includes files such as /proc/kcore, which is a virtual view of the entire running memory. Backing these up only wastes resources.
  • /dev
contains the file representations of your hardware devices. If you are planning to restore to a blank system, then you can back up /dev. However, if you are planning to restore to an installed Linux base, then backing up /dev will not be necessary.


Using FTAPE
The ftape package is a collection of command line tools for accessing and managing magnetic tape drives. These utilities are useful if you are using tape drives to store your backups.
USING THE CDRECORD PACKAGE
In order to make backups on CDs under Red Hat Linux, you need the cdrecord package to be installed.

you must first create a CD image on the file system and then copy the CD image to the actual CD all in one step. This process requires that you have empty space on a single file system partition which is large enough to hold a CD image (up to 650MB). You create a CD image with the mkisofs command:

mkisofs –o /tmp/cd.image /home/blanu
This command makes a CD image file in the /tmp directory called cd.image. The CD image file contains all the files in the /home/blanu directory.

USING MIRRORDIR
The mirrordir command (in the mirrordir package) is a tool that enables you to easily back up a file system to an additional hard drive. In order to use mirrordir you must first mount the additional hard drive.

mount /dev/hdb1 /mnt

Then you can back up a given directory to the mounted hard drive using the mirrordir command.

mirrordir /home /mnt
The command backs up the /home directory, which contains all of the users’ personal files, to the backup hard drive.
To recover lost files if the partition containing /home crashes, the arguments to the mirrordir command are simply reversed. The following command overwrites the contents of /home with the contents of /mnt.

mirrordir /mnt /home

Note that any files extant in /home that are not also in /mnt are erased.

Using DUMP
dump can perform functions similar to tar. However, dump tends to look at file systems rather than individual files. Quoting from the dump man file: "dump examines files on an ext2/3/4 filesystem and determines which files need to be backed up.
These files are copied to the given disk, tape, or other storage medium for safe keeping.
The dump command is used to do backups of either entire partitions
or individual directories.

The restore command is used to restore an entire partition, individual directories, or individual files.

SAMPLE DUMP COMMAND

dump 0uf /dev/rft0 /dev/hda3

This command specifies that the file system on /dev/hda3 should be backed up on the magnetic tape on device /dev/rft0.
It specifies that the backup should use backup level 0 (full backup) and write the time of the backup to the /etc/ dumpdates file.
Running a backup with dump is fairly straightforward. The following command does a full backup of Linux with all ext2 and ext3 file systems to a SCSI tape device:
dump 0f /dev/nst0 /boot
dump 0f /dev/nst0 /
In this example, our system has two file systems. One for /boot and another for / — a common configuration.
They must be referenced individually when a backup is executed.
The /dev/nst0 refers to the first SCSI tape, but in a non-rewind mode.
This ensures that the volumes are put back-to-back on the tape.
An interesting feature of dump is its built-in incremental backup functionality.
In the example above, the 0 indicates a level 0, or base-level, backup.
This is the full system backup.
On subsequent backups you can use other numbers (1-9) in place of the 0 to change the level of the backup.
A level 1 backup would save all of the files that had changed since the level 0 backup was done.
Level 2 would backup everything that had changed from level 1 and so on.
USING RESTORE

The restore command is used to retrieve files from the backups created with dump.

You can use restore to restore an entire file system or you can use it to interactively select which files you want to restore.

The restore command is used to retrieve files from the backups created with dump.

You can use restore to restore an entire file system or you can use it to
interactively select which files you want to restore.

The syntax for the restore command is the same as for the dump command, although it has different options.

Restore must be run inside the directory that is going to be restored. So,
restore can restore the /home directory with the following commands:

cd /home

restore rf /dev/rft0

The r flag tells restore to restore the entire archive rather than just some files.

The f flag tells restore that the archive is located on the device /dev/rft0.

USING RESTORE INTERACTIVELY The restore command, in addition to being used to restore an entire file system, can also be used in an interactive mode, which enables you to restore individual files.
Extract (-x)

If you need to work with individual files, rather than full file systems, you must use the 
-xswitch to extract them. For example, to extract only the /etc directory from our tape backup, use the following command:
restore -xf /dev/nst0 /etc

USING TAR

tar is short for tapearchive, and was originally designed for packaging files onto tape.

It is a file-based command that essentially serially stacks the files end to end.

Entire directory trees can be packaged with tar, which makes it especially suited to backups.

Archives can be restored in their entirety, or files and directories can be expanded individually.

Backups can go to file-based devices or tape devices. Files can be redirected upon restoration to replace to a different directory (or system) from where they were originally saved. 

tar is file system-independent. It can be used on ext2, ext3, jfs, Reiser, and other file systems.

Using tar is very much like using a file utility, such as PKZip. You point it toward a destination, which is a file or a device, and then name the files that you want to package.

Archives can be restored in their entirety, or files and directories can be expanded individually.

Backups can go to file-based devices or tape devices. Files can be redirected upon restoration to replace to a different directory (or system) from where they were originally saved. tar is file system-independent.

It can be used on ext2, ext3, jfs, Reiser, and other file systems.
To back up the entire file system using tar to a SCSI tape drive, excluding the /proc directory:
tar -cpf /dev/st0 / --exclude=/proc
In the above example, the -c switch indicates that the archive is being created.
The -pswitch indicates that we want to preserve the file permissions, critical for a good backup.
The -f switch points to the filename for the archive. In this case, we are using the raw tape device, /dev/st0.
The / indicates what we want to back up. Since we wanted the entire file system, we specified the root. 
tar automatically recurses when pointed to a directory (ending in a /). Finally, we exclude the /proc directory, since it doesn’t contain anything we need to save.
To restore a file or files, the tar command is used with the extract switch (-x):
tar -xpf /dev/st0 -C /
The -f switch again points to our file, and -p indicates that we want to restore archived permissions.
The -x switch indicates an extraction of the archive. The -C / indicates that we want the restore to occur from /. 

tar normally restores to the directory from which the command is run. The -C switch makes our current directory irrelevant.

No comments:

Post a Comment

Contact Form

Name

Email *

Message *