How to Implement backup in Linux (1)

Source: Internet
Author: User
Tags rewind

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/nst02nd SCSI tape drive /dev/st1 /dev/nst1nth SCSI tape drive /dev/st[n-1] /dev/nst[n-1]1st ATAPI tape drive /dev/ht0 /dev/nht02nd ATAPI tape drive /dev/ht1 /dev/nht1nth 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-rw- 1 root operator 9, 0 Dec 1 04:10 /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:
Character Devices1 mem 10 misc2 pty 14 sound3 ttyp 21 sg4 ttyS 29 fb5 cua 37 ht7 vcs 128 ptm9 st 136 ptsBlock Devices1 ramdisk2 fd3 ide09 md22 ide1
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.


Related Article

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.