Tutorial: Windows to Linux: Part 1 backup and recovery

Source: Internet
Author: User
Quick Guide to Linux backup and recovery

Level: Entry

Chris Walden (cmwalden-at-us.ibm.com)
E-commerce architect, IBM developer relations
January 2004

IBM e-commerce architect Chris Walden willDeveloperWorksThe nine articles published in this article will guide you how to use your Windows Operating Skills in Linux. This section describes the content of the Linux system and schedules and implements regular backup while taking recovery and security into account.

Linux is a stable and reliable environment. However, any computing system has unexpected events, such as hardware faults. Reliable backup of critical configuration information is part of any responsible management plan. In Linux, you can perform backup in various ways. The technology involved ranges from very simple script-driven methods to well-designed commercial software. Backups can be saved to remote network devices, tape drives, and other removable media. Backup can be based on files or drive images. There are many options available. You can mix these technologies to design an ideal backup plan for your environment.

Determine policy
You can use many different methods to back up the system. For more information, see "Introduction to backing up and restoring data" at the end of this article.

The backup content depends largely on the reason for your backup. Are you trying to recover from a serious fault (such as a hard drive problem? Do you want to archive the archive so that you can restore the old files as needed? Do you plan to start from a cold system or a pre-loaded backup system?

Confirm the content to be backed up
During system backup and restoration, the file-based nature of Linux has become a great advantage. In Windows, the Registry is very related to the system. Configuration and software installation not only put files on the system. Therefore, restoring the system requires software that can handle features such as Windows. In Linux, the situation is different. Configuration files are text-based and, apart from directly processing hardware, they are largely irrelevant to the system. The modern approach to hardware drivers is to make them available in the form of Dynamically Loaded modules, so that the kernel becomes more irrelevant to the system. Different from the complex details about how to install the operating system on the system and hardware, Linux Backup processes package and package of files.

Generally, the following directories need to be backed up:

  • /Etc
    Contains all core configuration files. This includes network configuration, system name, firewall rules, users, groups, and other global system items.
  • /Var
    Contains information used by the system daemon (service), including DNS configuration, DHCP lease period, Mail Buffer file, HTTP Server File, db2 instance configuration, and so on.
  • /Home
    Contains the default home directories of all users. This includes their personal settings, downloaded files, and other information that users do not want to lose.
  • /Root
    Is the root user's home directory.
  • /Opt
    Is where many non-system files are installed. The IBM software is installed here. OpenOffice, JDK, and other software are installed here by default.

Some directories should be consideredNoBackup.

  • /Proc
    Never back up this directory. It is not a real file system, but a virtualization view that runs the kernel and environment. It includes files such as/proc/kcore, which is a virtual view of the entire running memory. Backing up these files is just a waste of resources.
  • /Dev
    Indicates the file that contains the hardware device. If you plan to restore to a blank system, you can back up/dev. However, if you plan to restore to an installed Linux system, it is unnecessary to back up/dev.

Other directories include system files and installed packages. In the server environment, many of the information is not customized. Most of the custom settings are in the/etc and/home directories. However, for integrity, you may want to back up them.

In the production environment, I want to ensure that data is not lost, so I will back up the entire system except the/proc directory. If you are most worried about users and configurations, I will only back up the/etc,/var,/home, And/root directories.

Backup tools
As mentioned above, Linux backup is, to a large extent, a package and a package file. This allows you to use existing system utilities and scripts to perform backups without buying commercial software packages. In many cases, such backups are sufficient and provide administrators with great control capabilities. Backup script can be usedcronCommand to automate. This command controls the scheduled events in Linux.

Tar
tarIs a classic UNIX Command that has been transplanted to Linux.tarYesTApeArThe abbreviation of chive (Tape archiving), originally designed to pack files on tape. If you have downloaded the Linux source code, you may have encountered a tar file. This is a file-based command, which essentially stacks files consecutively and at the beginning and end.

UsetarYou can package the entire directory tree, which makes it especially suitable for backup. You can restore all the archive files or expand separate files and directories from them. Backups can be saved to file-based devices or tape devices. Files can be redirected during restoration to put them in a directory (or system) different from the directory (or system) where they were originally saved ).tarIs irrelevant to the file system. It can be used on ext2, ext3, jfs, Reiser, and other file systems.

UsetarIt is very similar to using a file utility such as PKZip. You only need to point it to a target (a file or device) and specify the file you want to package. You can use the standard compression type to dynamically compress an archive file, or specify an external compression program of your choice. To use bzip2 to compress or extract files, use tar -zCommand.

To use tarBack up the entire file system except the/proc directory to the SCSI tape device:

tar -cpf /dev/st0 / --exclude=/proc

In the preceding example,-cThe switch indicates that the archive file is being created.-pThe switch indicates that we want to retain the file license permission, which is critical for good backup.-fSwitch to the file name of the archive file. In this example, we use the original tape device/dev/st0. /Indicates the content we want to back up. Since we want to back up the entire system, we need to specify this toggle as the root ). WhentarIt is automatically recursive when it points to a directory (ending with a slash. Finally, the/proc directory is excluded because it does not contain any content to be saved. If a single tape cannot accommodate this backup, we need to add-MSwitch (not shown in this example) for multi-volume backup.

Just in case
Do not forget that Linux is case sensitive. For example,tarThe command should always be executed in lower case. The command line switch can be a combination of upper-case, lower-case, or lower-case. For example,-tAnd-TExecute different functions. File or directory names can be case-sensitive in combination, and are case-sensitive just like the command and command line switch.

To restore one or more files, you can use the with extract switch (-x)tarCommand:

tar -xpf /dev/st0 -C /

Here-fThe switch also points to the archive file,-pThe switch indicates that we want to restore the archive permission.-xIndicates that files are extracted from the archive.-C /Indicates that we want to start the restoration from.tarIt is usually restored to the directory where the command is run.-CSwitch so that our current directory is no longer related.

The other twotarCommand is-tAnd-dSwitch.-tTo list the content of an archive object.-dSwitch to compare the content of the archive file with the current file on the system.

For ease of operation and editing, you can put the files and directories you want to archive into a text file, and then-TSwitch to reference this text file. These files and directories can be combined with other directories listed on the command line. The following command line backs up all files and directories listed in MyFiles, the/root directory, and all iso files in the/tmp directory.

tar -cpf /dev/st0 -T MyFiles /root /tmp/*.iso

The file list is just a text file that lists the files or directories. The following is an example:

/etc
/var
/home
/usr/local
/opt

Note:tar -T(Orfiles-from) The command cannot accept wildcards. Files must be explicitly listed. The above example shows a method to reference a file separately. You can also execute scripts to search for the system and create a list. The following is an example of a script:

#!/bin/sh
cat MyFiles > TempList
find /usr/share -iname *.png >> TempList
find /tmp -iname *.iso >> TempList
tar -cpzMf /dev/st0 -T TempList

The above script first copies the list of all existing files in MyFiles to TempList. Then it executes twofindCommand to search for files matching a certain pattern in the file system and attach them to the TempList. The first time is to search for the/usr/share directory tree.pngAll objects. The second is to search for the/tmp directory tree.isoAll objects. After the list is created,tarCreate a new archive file on the file device/dev/st0 (the first SCSI tape device ).ZAnd retain all file permissions. The archive file spans multiple volumes. The name of the file to be archived is extracted from the templist file.

You can also use scripts to perform more detailed operations, such as Incremental backup. Gerhard mourani in hisSecuring and Optimizing LinuxThis book provides an excellent script. You can find information about this book at the end of this article.

You can also write scripts to restore files, although the restoration is usually done manually. As mentioned above-xSwitch replaced-cSwitch. You can restore an entire archive file or a specified file or directory. You can use wildcards to reference files in an archive file. You can also use the switch to dump and restore data.

Dump and restore
dumpCan execute similartar. However,dumpTends to consider file systems rather than individual files. The following content is taken from the dump manual file: "Dump checks files on the ext2 file system and determines which files need to be backed up. These files will be copied to a given disk, tape, or other storage media for security protection ...... A dump larger than the output media capacity is divided into multiple volumes. In most media, the capacity is determined by writing until an end-of-media mark is returned ."

CooperationdumpThe program isrestoreWhich is used to restore a file from a dump image.

restoreCommand to execute the reverse function of the dump. You can restore the full backup of the file system first, and the subsequent Incremental Backup can overwrite the restored full backup. Individual files or directory trees can be restored from full or partial backups.

dumpAndrestoreCan be run on the network, so you can back up or restore through a remote device.dumpAndrestoreUse tape drives and file devices that provide a wide range of options. However, both are only applicable to ext2 and ext3 file systems. If you are using JFS, Reiser, or other file systems, you will need other utilities, suchtar.

Use dump for backup
UsedumpIt is quite simple to execute a backup. The following command executes a full Linux backup, which backs up all ext2 and ext3 file systems to a SCSI tape device.

dump 0f /dev/nst0 /boot
dump 0f /dev/nst0 /

In this example, there are two file systems. One for/boot and the other/This is a common configuration. They must be referenced separately during Backup. /Dev/nst0 references the first SCSI tape drive, but it is referenced in non-rewinding mode. This ensures that each volume is arranged one by one on the tape.

dumpAn interesting feature of is its built-in Incremental backup function. In the preceding example,0Indicates level 0 or basic backup. This is a full system backup. You need to regularly execute it to save the entire system. For subsequent backups, you can use other numbers (1-9) instead of 0 to change the backup level. Level 1 backup saves all files changed since the level 0 backup is executed. Level 2 backup saves all the files that have been changed since the level 1 backup is executed, and so on. UsetarIt can perform the same functions as the script, but requires the script creator to provide a mechanism to determine when the last backup was executed.dumpIt has its own mechanism, that is, it will output an Update file (/etc/dumpupdates) when performing the backup ). This update file will be reset every time a backup of level 0 is executed. Subsequent backups will keep their tags until another backup of level 0 is executed. If you are performing a tape-based backup,dumpMultiple volumes are automatically tracked.

Skip File
Mark will bedumpSkip files and directories. The command to achieve this ischattrIt changes the extended attributes of the ext2 and ext3 file systems.

chattr +d <filename>

The above command adds a tag to the file to makedumpThis file is skipped during Backup.

Use restore for restoration
Restore to usedumpSaved information, which can be usedrestoreCommand. ImagetarSame,dumpCan list (-t) The content of the archive file, and compare it with the current file (-C). UsedumpYou must be careful when restoring data. There are two very different restoration methods. You must use the correct method to obtain predictable results.

Reconstruction (-r)
Remember, in designdumpThe most important consideration is the file system, rather than a separate file. Therefore, there are two different file restoration styles. To recreate a file system, you can use-rCommand line switch. The purpose of design reconstruction is to operate on an empty file system and restore it to a saved state. You should have created, formatted, and mounted the file system before performing reconstruction. File systems that contain files should not be rebuilt.

The following is an example of using the dump executed above to perform full reconstruction.

restore -rf /dev/nst0

The above command needs to be executed separately for each file system to be restored.

When necessary, you can repeat this process to add incremental backup.

Extract (-x)
To use a separate file instead of the entire file system, you must use-xSwitch to extract them. For example, to extract only the/etc directory from our tape backup, run the following command:

restore -xf /dev/nst0 /etc

Interactive restoration (-I)
restoreAnother feature provided is the interactive mode. Run the following command:

restore -if /dev/nst0

You will be placed in the interactive shell, and items included in the archive file will also be displayed. Enter "help" to display a command list. Then you can browse and select the items you want to extract. Remember that any files you extract will go to the current directory.

Dump and tar
dumpAndtarThere are a group of advocates. Both have their own advantages and disadvantages. If you are running any file system except ext2 or ext3dumpIs not available to you. However, if this is not the case, you only need the least script to run it.dumpAnddumpIt also has an interactive mode that can be used to help restore.

I prefer to usetarBecause I like to write scripts to get additional control levels. In addition, there is a multi-platform tool for operating the. tar file.

Other tools
In Linux, any program that can copy files can be used to perform a certain degree of backup. It is used by someone.cpioAndddTo perform the backup.cpioIs anothertarSimilar packaging utility, but not widely used.ddIs a file system replication utility that generates binary copies of the file system.dd It can also be used to generate images of hard drive, similar to products such as Symantec's Ghost. However,ddIt is not file-based, so you can only use it to restore data to the same hard drive partition.

Commercial backup Products
There are many commercial backup products available for Linux. Commercial products generally provide convenient interfaces and reporting systems.dumpAndtarYou must take advantage of such a tool. Commercial products are widely used and usually provide a large number of features. The biggest benefit of using commercial software packages is that there is a pre-established policy for processing backups that you can immediately put into work. Commercial developers have made many mistakes you are about to make. The cost of their wisdom is cheaper than the cost of losing your valuable data.

Tivoli Storage Manager
Tivoli Storage Manager may be the best commercial backup and Storage management utility for Linux. The Tivoli Storage Manager server can run on multiple platforms, including Linux, while the client can run on more platforms.

In essence, the Storage Manager server is configured by a device suitable for backing up the environment. Any system involved in the backup must load a client that communicates with the server. Backup can be performed as planned, manually on the Tivoli Storage Manager Client Interface, or remotely on the Web-based interface.

The policy-based nature of TSM means that you can define central rules for backup behavior without having to adjust the file list frequently. In addition, IBM Tivoli Storage Resource Manager can identify, evaluate, control, and predict the utilization of enterprise Storage assets, detect potential problems, and automatically apply self-repair adjustments. For more details, see the Tivoli Web site (see the link in references ).

Figure 1. Tivoli Storage Manager menu

Then backup and restoration are processed by remote devices..

Figure 2. Tivoli Storage Manager page

Foresight and review
The first step to good backup is to have plans. First, you need to know the data you want to save and what recovery policies you need, and then use the most suitable tool for this policy.

Linux comes with some out of the box useful backup tools. Two of the most commonly usedtarAnddump/restore. Both of them can perform full system backup. With creative scripts, you can design a custom solution to back up the system locally and remotely.

However, writing your own backup script may be a heavy task, especially for complicated enterprises. Commercial software such as Tivoli Storage Manager reduces the learning difficulty and allows you to immediately control your backup, but you may have to adjust your policies to adapt to the features of these tools.

References

  • Read Other sections of the Windows to Linux journey series (DeveloperWorks, January 1, November 2003 ).

  • Linux Administrator's Security Guide is a Security Guide, which has an excellent section on Linux backup and recovery practices.
  • Introduction to Backing Up and Restoring Data is an overview that is irrelevant to the operating system or system architecture. This article discusses the backup technology and how to plan backup.
  • Linux Administration Made Easy is an older reference, but it is still useful because the general process and technology of Linux are still consistent.
  • The Linux System Administrator's Guide introduces Linux System Management for beginners.

  • Securing and Optimizing Linux-A Hands on Guide(Red Hat Edition) Chapter 1 "backup and restoration" is another good guide, including a script for executingtar.
  • The TAO of Backup is an interesting demonstration of The Backup philosophy, presented in a philosophical form. Although it is related to a commercial product, this information is well written.
  • IBMDeveloperWorksThe "Linux Machine backup" tutorial guides you through the creation and implementation of backup policies.
  • It is easy to store data and other content on a CD: at IBMDeveloperWorksIn the article "burn CD on Linux", learn how to do this.
  • If you are converting from a Windows environment to a Linux environment, read the Linux User Technical FAQ.
  • The Tivoli Storage Manager was named as The best Storage solution for LinuxWorld 2003. Learn more about Tivoli Storage Manager for Linux from the Linux area on the IBM site.
  • The Tivoli product page contains more information about Tivoli, including security and privacy features.
  • "Linux document Plan"Introduction to LinuxChapter 1 discusses file permissions and security.
  • InDeveloperWorksYou can find more references for Linux developers in the Linux area.
About the author
Chris Walden is IBM Developer Relations Technical Consulting (also knownDragonslayersE-commerce architect, which provides education, implementation, and consulting for IBM business partners. He is dedicated to Linux-related work and will publicize the benefits of Linux to people around him as soon as he has the opportunity. In addition to fulfilling the responsibilities of his architect, he is also proficient in various fields of Linux infrastructure servers, including files, printing and other application services in the hybrid platform user environment. Chris has 10 years of experience in the computer industry. From field support to Web application development and consulting, he has been involved in various fields. You can contact Chris via email cmwalden-at-us.ibm.com.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.