Article Title: How to Implement backup in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
A common question for Linux system administrators is: how do I back up my system? For windows systems, it is easy to back up data (you only need to click the mouse in menu mode ). Linux backup is much more troublesome. If you are not familiar with Linux system files and devices, the situation will become worse. This article discusses how to protect data and related device information in Linux.
1. What is backup?
In the simplest way, the process of backing up data is to copy important data to other media (usually movable) to ensure that the data can be restored when the original data is lost. A backup may be a simple cp command, copying a file to another directory, or using a specific program to write data streams into a specific device. In many cases, the data to be backed up is written to the tape drive, but this is not the case in some cases. In a Linux environment or other Unix system, backup can be to copy files to an existing file system, a replaceable file system, a tape drive, and a remote file system, even the tape drive on the remote system. Of course, from the user's perspective, there is no concept of a tape drive or ZIP drive, but just a file.
2. Which backup device should I select?
There are many devices on the market that claim to be "perfect system backup options", including tape drives, portable disk drives, and even mysterious Internet backup systems. For backup operations, the tape drive provides the most trusted storage method. Why is it a tape drive? Of course, the Jaz or Zip drive of Iomega seems to be an interesting backup tool, but they are easy to cause problems when the hard drive crashes due to the file system. For Internet backup, when you cannot access the Internet due to system crash, you cannot recover system data. Likewise, can you trust that your data is stored in another remote system?
Therefore, we chose a tape drive, but how can we access it? As mentioned earlier in the article, in Linux, from the perspective of user status, anything can be seen as a file. Therefore, you can "open" an appropriate tape drive file to write data to the file. Although it sounds too simple, this is the actual situation. In Linux, the/dev directory of the root file system contains all files associated with physical devices. These files are actually operated on the underlying physical devices. The following table describes how device files are associated with physical devices in Linux:
Device Rewinding does not roll back (No-Rewind)
1st SCSI tape drive/dev/st0/dev/nst0
2nd SCSI tape drive/dev/st1/dev/nst1
Nth SCSI tape drive/dev/st [n-1]/dev/nst [n-1]
1st ATAPI tape drive/dev/ht0/dev/nht0
2nd ATAPI tape drive/dev/ht1/dev/nht1
Nth ATAPI tape drive/dev/ht [n-1]/dev/nht [n-1]
1st floppy tape drive/dev/ft0/dev/nft0
As shown in the preceding table, the device name is based on the Logical Number of the device that is located in a layered structure for this device type, rather than its physical ID (SCSI) or IDE channel (ATAPI ). Therefore, even if a SCSI host is assigned ID4 as the SCSI device, if it is the first tape device of the SCSI chain, it will be/dev/st0 instead of/dev/st4, this naming convention is useful for tracking tape devices in the system, and even for tape devices with multiple drive types. Similarly, in the 2.0.X kernel, only a single ATAPI device is supported. In the 2.2 kernel, multiple ATAPI drivers (ht0, ht1,...) can be used ,...).
Now let's take a look at how these files are named. What is the difference between the rollback and non-rollback? To put it simply, the rewind device allows the tape to be automatically rolled back to the start point after the end of the operation, but not after the end of the operation, stop the tape drive at the current position without performing the rollback operation. For most simple backup operations, the back-to-volume device is more suitable, because it automatically rolls back after the backup operation is completed to prepare for taking out the tape. For complex backup operations (such as additional backup, logical search, and operations on high-end backup tools), devices that do not roll back are more suitable.
3. Access from devices in Linux
In Linux, devices access the node files associated with them. These nodes are located in the/dev directory, but do not confuse the concept-a device node is not just a simple file. When a device node is opened for access, it has special properties to notify the kernel of the physical device. Each node file has an associated master number and slave number (major and minor number) and a device type attribute. For example, the following figure shows the device nodes of the SCSI tape drive:
Crw-rw-1 root operator 9, 0 Dec 1/dev/st0
The first "c" indicates that the device is a character device (meaning that the device only processes one character each time during I/O operations). The master number is 9 and the slave number is 0. The master number is like an address that notifies the kernel of the device drive, and the slave number is used to define the function of a specific instance of the device. What if the node file does not exist? Linux provides a command to easily create a device node file-mkmod. The command format is as follows:
Mknod/dev/nodename [c | B] major minor
However, if the system does not have an appropriate device node, you need to check whether the kernel supports this type of device. This can be viewed through the output of the command cat/proc/devices. In my system, the situation is as follows:
Many administrators may encounter problems with the mt command when operating the Back-to-volume device. The mt command is used to operate a "tape" device. For example, run the mt-f/dev/st0 eod command to set the tape to prepare for additional backup, the tape drive/dev/st0 will move forward to the end of the data to prepare new additional backup operations, but because st0 is a back-to-volume device, the tape drive immediately rolls back to the start point after locating the data and closes the tape device (because st0 is a back-to-volume device ). At this time, the backup operation will overwrite the data information in the tape, instead of attaching the new data to the end of the tape data. If you use a non-back-to-volume device, mt will stop the tape at the eod location, and subsequent backup operations will be added to the location after the last backup.
The recommended solution to this problem is to establish a symbolic link for the desired non-revolving device, such as:/dev/tape, if the mt command does not provide the-f parameter, you can use/dev/tape to operate the device. If the system has multiple TAPE devices, you can use the environment variable TAPE =/dev/nst [x] to achieve the same result without using symbolic links. For the preceding two methods, you do not need to use the-f parameter when using the mt command. For example, if mt eod is used, the correct media location is automatically used, you do not need to worry about which/dev device to use.
4. Basic backup methods in Linux
Now we have discussed how to call tape devices, and we know how to determine whether to use a back-to-volume or non-back-to-volume device. But how can we migrate system files from the system to tape devices? This is the function of various backup tools. All Linux releases provide the ancestor tar of all backup tools (of course, dbppt and bppt, a/k/a dump and restor are the backup tools Adam of Unix systems ). The tar command appears in Unix Version 7. The command name is "Tape ARchiver ". This command is designed to easily back up data from the system to tape or restore data from tape.
The basic syntax of the tar command is:
Tar-mode-option [files]
Here, c Indicates creating (backup),-x extracting (restore), or-t content list (list). The options include the following elements: for example,-v indicates detailed output, -f file indicates the target (Creation Mode) or source (extraction or list mode). For more information, see the manual of the system tar command (man tar ).
The c option of this command creates a new backup (c), uses the verbose mode (v), and outputs the entire system backup to/dev/st0 (f ). In this case, the tar operation will open the/dev/st0 file (device) and write the data stream in tar format to the opened file, and close the file after all data is written. Because the Back-to-volume device/dev/st0 is selected here, the file (storage medium) will enable the device driver to roll back the tape after closing the file in tar.
The next step is to verify that the data is correctly written to the tape. Unfortunately, the tar command in Linux only provides a verification method in comparison mode-The tape content is re-read and compared with the original file in bytes. However, this is still much better than not being verified. This is because it is very bad to find bad data on the tape during recovery.
After the recovery is completed and verified, everything is not over, because the data in the system is constantly changing, one way to maintain a constantly changing system backup is to regularly back up the changed data. There are many ways to achieve such backup, but the most convenient is incremental and differential backup.
Both methods depend on the time, the last backup (incremental), or the last full backup. Incremental Backup only backs up the data modified since the last backup, which is also called a regular backup. Differential backup only backs up the files changed since the last full backup. The following table compares the features of several backup solutions:
5. Full backup Incremental Backup differential backup
Space use Most Least Less than Full
Backup speed Slowest Fastest Faster than Full
Recovery speed Fastest Slowest Faster than Incremental
Differential backup may back up the data ignored by Incremental backup, but the recovery speed of differential backup is faster than that of Incremental backup, because it only requires the last full backup and the last differential backup; and Incremental Backup
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.