Also talk about data backup under Linux

xiaoxiao2021-03-06  64

The value of the data is not allowed. After the damage is regenerated, it is necessary to spend valuable time and desperate efforts, sometimes it is impossible to re-generate, such as some disposable irreversible test experiment. Since data is an investment, you must protect it and take steps to avoid loss. Otherwise, it will cost high money to save, sometimes you have to match tears - see the "9.11 incident" tragic scene, this kind of discourse is not a dramatic manager - numerous servers are destroyed, there is a vulnerability on backup management The company has to swallow the fruit. On the contrary, there is a good backup measures, and disaster loss can be reduced to the lowest point. Lost data is generally several reasons: hardware failure, software curve, human factors or natural disasters. Although modern hardware is quite reliable, it may still be naturally damaged. The hardware that stores data from a decisive role is a hard disk, which relies on tiny tracks and sectors to save fragile data in the world full of electronic interference signals. At the same time, modern software is still unreliable, not strong enough. Worse, people are more unreliable, they are very casual, sometimes tired, they are easy to make mistakes, even maliciously destroy data for some purposes - is those who attack other people's databases for music. "Invaders ". The irresistible natural may not be evil, but it may also cause damage. Therefore, I hope that the ideal data security is almost impossible, and I am going to prepare, it is going to make a policy. Backup is a method of protecting data investment. There are multiple copies of data, they are not afraid of a certain damage (the required data is only recovered from the backup). The most important strategy required for backup is to select backup media. Generally, floppy discs and tapes are used. The floppy disk is very cheap, it is reliable, not too fast, it is easy to get, but the amount of data is not easy to use. Tape is also very cheap, more reliable, and the storage speed is more fast, it is easy to get. Backup tools have a lot of backup tools to choose. Traditional UNIX Backup Tools are Tar, CPIO, and DUMP. In addition, a large number of third-party packages (including free software and business software) can also be used. Different backup media selection may affect the choice of tools. TAR and CPIO are similar, from backups to the basic equivalents. You can save the file to the tape and remove the file. Almost all backup media can be used because its core device drivers handle the underlying device operation, and the user-level program seems to be almost. There are some UNIX versions of TAR and CPIO backup tools that may have problems with the processing of non-deployed files ((such as processing of files, device files, extremely long path, etc.), but these commands on Linux can process correctly All files. DUMP is different from TAR and CPIo, it reads the file system directly without passing the file system. It is actually for the backup of the backup, and the TAR and CPIO are actually for archive files, although they also compete for backup work. There are many advantages to the direct read file system, which can not consider the time tag of the backup file; for TAR and CPIO, you must first read the file system read-only. And read the file system is more effective, if all things are backed up, its backup The time is relatively short, because it moves the minimum of the head. Its main disadvantages are that each file system species requires a specific backup program. In addition, the DUMP program only recognizes the EXT2 file system. DUMP also supports the backup level directly; for TAR And CPIO, this must be implemented with other tools. TAR backup commands a full backup can be easily implemented with TAR:

# tar -create -file / dev / ftape / usr / srctar: ​​removing leading / from absolute path name in the archive #

The above example uses the GNU version of the TAR and its long selection name. Traditional version of TAR only recognizes a single character option. The GNU version can also handle a roll of tape or a disk that cannot be accommodated, and a long path name; this is not all traditional versions. If your backup, a tape cannot be accommodated, you need to use -Multi-Volume (-M) option: # tar -cmf / dev / fd0h1440 / usr / src tar: removing leading / from absolute path name in the archive prepare volume # 2 for / dev / fd0h1440 and hit return: #

Note that you have to format all floppies before starting backup, or format it with another virtual console or virtual terminal when the TAR command needs a new floppy disk. After backup, you should check if it is intact, use the -compare (-d) option:

# tar -compare -verbose -f / dev / ftape usr / src / usr / src / linux usr / src / linux-1.2.10-incruDes / .... #

Failure backups mean that if you lose the original data, the backup cannot be recovered. Incremental backups can be implemented using the TAR with the -newer (-n) option:

# tar -create -newer '8 Sep 1995' -file / dev / ftape / usr / src -verbose tar: removing leading / from absolute path names in the archive usr / src / usr / src / linux-1.2.10-incruDes / usr / src / linux-1.2.10-incruDes / include / usr / src / linux-1.2.10-includees / include / Linux / usr / src / linux-1.2.10-incruDes / include / Linux / Modules / USR /src/linux-1.2.10-includes/include/asm-generic/ usr / src / linux-1.2.10-incrudes / include / ASM-I386 / USR / SRC / Linux-1.2.10-incrudes / include / ASM -MIPS / USR / SRC / Linux-1.2.10-includees / include / asm-alpha / usr / src / linux-1.2.10-includees / include / ASM-M68K / USR / SRC / Linux-1.2.10-Includes / include / asm-sparc / usr / src / patch-1.2.11.gz #

Unfortunately, the tar command cannot know the change of I node information of a file. For example, the rights of the file is changed, or the file name changes. However, in the list of files available and compare the current file system status and the previously backed up file lists. TAR's Expand TAR -Extract (-x) option expands the file:

# tar -extract -same-permissions -verbose -file / dev / fd0h1440 usr / src / usr / src / linux usr / src / linux-1.2.10-incruDes / usr / src / linux-1.2.10-incruDes / include / usr / src / linux-1.2.10-incruDes / include / Linux / usr / src / linux-1.2.10-incrudes / include / linux / hdreg.h usr / src / linux-1.2.10-incruDes / include / Linux / kernel.h ... #

You can also use the command line to expand only specific files and directories (and the files and subdirectories):

# TAR XPVF / DEV / FD0H1440 USR / SRC / Linux-1.2.10-incrudes / include / Linux / HDREG.H USR / SRC / Linux-1.2.10-Includes / include / Linux / HDREG.H # with -List -t) Option See what file in a backup volume:

# TAR -LIST -FILE / DEV / FD0H1440 USR / SRC / USR / SRC / Linux USR / SRC / Linux-1.2.10-Includes / USR / SRC / Linux-1.2.10-Includes / include / usr / src / linux -1.2.10-includees / include / Linux / USR / SRC / Linux-1.2.10-includees / include / linux / hdreg.h usr / src / linux-1.2.10-incrudes / include / Linux / kernel.h. .. #

Note that tar is to read a backup volume in order, so there is a lot of time to encounter a huge volume. It is not possible to use a random access database technology when using a tape drive or other storage medium.

Compressed backup

Backup takes up a lot of space, it takes a lot of money. To reduce space requirements, backup can be compressed. There are several ways to solve. Some programs have built-in support compression, such as the -gzip (-z) option, through the Pipe (PIPE) command, first compressed data with Gzip compression before writing to the backup medium.

Unfortunately, compressed backups may cause problems. Based on the principle of compression, if a bit error can cause all other compressed data to be unavailable. Some backup programs have built-in error corrections, but there is no way to handle a lot of errors. That is to say, if you use a GNU TAR to compress backup, a separate error referior causes the entire backup loss. Backup must be reliable, such compression is not good.

Another way is to compress each file separately, which also returns to the loss of a file, but does not affect other files. Lost files may have been damaged, so this situation is not much more than the compression difference. AFIO program (a variant of CPIO) can be like this.

Compression requires time, for some types of tape drives, backup program write data is very slow, of course, this can be avoided by output buffering (if the backup program is "smart", can be built into, or can be implemented by other programs ), When it is timely, it is not high efficiency, which is also a problem with backup.

转载请注明原文地址:https://www.9cbs.com/read-83500.html

New Post(0)