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?
Back to Top
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. Hardware driverProgramThe modern method 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.
Back to Top
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 usedCron
Command to automate. This command controls the scheduled events in Linux.
Tar
Tar
Is a classic Unix Command that has been transplanted to Linux.Tar
YesTApeArThe abbreviation of chive (Tape archiving), originally designed to pack files on tape. If you have downloaded LinuxSource codeYou may have encountered a tar file. This is a file-based command, which essentially stacks files consecutively and at the beginning and end.
UseTar
You 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 ).Tar
Is irrelevant to the file system. It can be used on ext2, ext3, JFS, Reiser, and other file systems.
UseTar
It 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, useTar-z
Command.
To useTar
Back up the entire file system except the/proc directory to the SCSI tape device:
Tar-CPF/dev/st0/-- exclude =/proc
Tar-cvpzf/Media/sda7/backup. tgz -- exclude =/proc -- exclude =/lost + found -- exclude =/mnt -- exclude =/sys -- exclude =/Media/ |
In the preceding example,-C
The switch indicates that the archive file is being created.-P
The switch indicates that we want to retain the file license permission, which is critical for good backup.-F
Switch 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 ). WhenTar
It 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-M
Switch (not shown in this example) for multi-volume backup.
Tar-CPF/dev/st0/-- exclude =/proc -- exclude =/dev -- exclude =/lost + found -- exclude =/mnt -- exclude =/sys -- exclude =/Media
Tar cvpzf/run/Media/gbyukg/36323cedd12b8040/backup. tgz -- exclude =/proc -- exclude =/lost + found -- exclude =/mnt -- exclude =/sys -- exclude =/run/media -- exclude =/dev -- exclude =/Media -- exclude =/home/gbyukg/
Just in case
Do not forget that Linux is case sensitive. For example,Tar
The 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,-T
And-T
Execute 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
)Tar
Command:
Here-F
The switch also points to the archive file,-P
The switch indicates that we want to restore the archive permission.-X
Indicates that files are extracted from the archive.-C/
Indicates that we want to start the restoration from.Tar
It is usually restored to the directory where the command is run.-C
Switch so that our current directory is no longer related.
The other twoTar
Command is-T
And-D
Switch.-T
To list the content of an archive object.-D
Switch 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-T
Switch 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 twoFind
Command 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. PNG
All objects. The second is to search for the/tmp directory tree. ISO
All objects. After the list is created,Tar
Create 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-X
Switch replaced-C
Switch. 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.
Back to Top
Dump and restore
Dump
Can execute similarTar
. However,Dump
Tends 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 ."
CooperationDump
The program isRestore
Which is used to restore a file from a dump image.
Restore
Command 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.
Dump
AndRestore
Can be run on the network, so you can back up or restore through a remote device.Dump
AndRestore
Use 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
.
Back to Top
Use dump for backup
UseDump
It 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.
Dump
An 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. UseTar
It 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.Dump
It 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,Dump
Multiple volumes are automatically tracked.
Skip File
Mark will beDump
Skip files and directories. The command to achieve this isChattr
It changes the extended attributes of the ext2 and ext3 file systems.
Chattr + D <FILENAME>
The above command adds a tag to the file to makeDump
This file is skipped during Backup.
Back to Top
Use Restore for restoration
Restore to useDump
Saved information, which can be usedRestore
Command. ImageTar
Same,Dump
Can list (-T
) The content of the archive file, and compare it with the current file (-C
). UseDump
You 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 designDump
The 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-R
Command 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.
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-X
Switch to extract them. For example, to extract only the/etc directory from our tape backup, run the following command:
Interactive restoration (-I)
Restore
Another feature provided is the interactive mode. Run the following command:
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.
Back to Top
Dump and tar
Dump
AndTar
There are a group of advocates. Both have their own advantages and disadvantages. If you are running any file system except ext2 or ext3Dump
Is not available to you. However, if this is not the case, you only need the least script to run it.Dump
AndDump
It also has an interactive mode that can be used to help restore.
I prefer to useTar
Because I like to write scripts to get additional control levels. In addition, there is a multi-platform tool for operating the. tar file.
Back to Top
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.Cpio
AndDd
To perform the backup.Cpio
Is anotherTar
Similar packaging utility, but not widely used.Dd
Is 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,Dd
It is not file-based, so you can only use it to restore data to the same hard drive partition.
Back to Top
Commercial backup Products
There are many commercial backup products available for Linux. Commercial products generally provide convenient interfaces and reporting systems.Dump
AndTar
You 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
Back to Top
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 usedTar
AndDump/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
-
- For more information, see the original article on the developerworks global site.
-
- 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 executing
Tar
.
-
- 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 IBMDeveloperworksArticle"Burn CD on Linux" to 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@us.ibm.com.