Backup in the Linux environment
Original author: Tim Jones original source: http: //www.linux-mag.com/cgi-bin/printer.pl issue = 1999-07 & article = guru?
Translation: ideal at linuxaid
One problem with Linux system administrators is: How to back up my system? For Windows systems, backup is very simple (just need to click the mouse in the menu mode). LINUX backup is more trouble, if you are not familiar with Linux system files and devices, the situation will become worse. This article discusses the method of protecting data and related equipment information in the Linux environment.
What is backup? The process of the easiest way to back up data is to copy important data to other media (usually movable) to ensure that data can be restored in the case of raw data loss. One backup may be a simple CP command, copy a file into another directory, or use a specific program to write data to a complex process in a particular device. Many cases are written to the tape drive in the case, but some cases are not like this. In the Linux environment, or other UNIX systems, backups can be copied to existing file systems, alternative file systems, tape drives, remote file systems, and even tape drives on remote systems. Of course, from the perspective of the user, there is no concept of the tape drive or the ZIP drive, but only the file.
Which backup device should you choose?
There are many devices that claim to be "perfect system backup", including tape drives, portable disk drives, and even mysterious Internet backup systems. For backup operations, the tape drive provides the most credible storage. Why is it a tape drive? Of course, Iomega's JAZ or ZIP drive looks interested backup tools, but they are easy to cause problems due to the cause of the file system in the case of the hard drive crash. For Internet backups, when you cannot access the Internet because of the system crashes, the system cannot be recovered. Similarly, can you really trust your data to store the remote system of others?
Therefore, we chose the tape drive, but how to access the tape drive? As mentioned earlier in the article, in the Linux system, anything can be seen as a file in the perspective of the user status. Therefore, it is possible to "open" the appropriate tape drive file to perform a write operation, and the data to be backed up is written to the file. Although this is too simple, the actual situation is like this. Linux Environment The / dev directory of the root file system contains all files associated with the physical device. When these files are operated, it is actually a physical device in operation. The following table describes how the device files are associated with physical devices in the Linux environment:
Dewinding Non-returning (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
This is as seen in the above table, the device name is based on the logical number of devices located for the type of device type, rather than its physical ID (SCSI) or IDE channel (ATAPI). Therefore, even if an SCSI disk machine is assigned to the ID4 of the SCSI device, if it is the first tape device of the SCSI chain, it will be / dev / ST0, not / dev / ST4, this naming convention is conducive to Track tape devices in your system, even tape devices with multiple drive types. Similarly, in the 2.0.x kernel, only a single ATAPI device, 2.2 version of the core can use multiple ATAPI drivers (HT0, HT1, ...). Now let's take a look at how these files are named, and where is the difference between the rebound and the roll? Simply put, the rollback device allows the tape to return to the beginning of the start, without the return device, and the tape drive is left at the time without the back operation. For most simple backup operations, the backup device is more suitable because it is automatically returned after the backup operation is completed to prepare the tape. For those complex backup operations (such as additional backup, logical search, and those high-end backup tools), no backup devices are more suitable for some.
Device Access in the Linux environment In the Linux environment, device access is through and associated with the device node files. These nodes are located in the / dev directory, but don't confuse concepts - a device node is more than just a simple file. When a device node is opened for access, it has a special attribute to notify which physical device is of the kernel operation. Each node file has an associated master number and a Major and minor number and device type properties, for example, the device node for the SCSI tape drive is as follows: 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 only one character each time), the main number is 9, from 0. The home code is like an address to notify the kernel which device driver used, and the origin is used to define a particular instance of the device. 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 there is no suitable device node in the system, it is necessary to detect whether the kernel supports this. Type type of equipment. This can be observed by the output of command cat / proc / devices, in my system, the situation is as follows: Character Devices 1 MEM 10 Misc 2 Pty 14 Sound 3 TTYP 21 SG 4 TTYS 29 FB 5 CUA 37 HT 7 VCS 128 PTM 9 ST 136 PTS Block Devices 1 Ramdisk 2 FD 3 IDE0 9 MD 22 IDE1
Many administrators encounter questions about MT commands when operating backup devices. The MT command implements a "tape" device. For example, the command MT -F / DEV / ST0 eod command sets the tape to prepare for new additional backups, and the tape drive / dev / ST0 will advance to the data to prepare a new additional backup operation, but because ST0 is a backup device. The tape drive will immediately return to the beginning and turn off the tape device after positioning to the data. (Because ST0 is a back device). At this time, if the backup operation, the data information in the tape is overridden, not the new data is attached to the end of the tape data. If you use a non-return device, MT will leave the tape in the EOD position, and subsequent backup operations will be added to the place after the last backup end.
The recommended solution for this problem is to establish a symbolic link for the non-rotating device you want to use, such as: / dev / tape, the MT command can use / dev / tape to operate the device using / dev / tape when the -f parameter is provided. If the system has multiple tape devices, you can use the environment variable TAPE = / DEV / NST [x] to achieve the same result. For the above two methods, do not need to use the -f parameter when using the MT command, for example: MT EOD, automatically use the correct media location without care where to use which / DEV device. Now we have discussed how to call tape devices, and we already know how to decide to use back or non-roll-up devices. But how do I achieve the system's file from the system to the tape device? This is the function of various backup tools. All Linux publishing provides ancestors of all backup tools: TAR (of course, DBPPT and BPPT, A / K / A DUMP AND RESTOR are the Adam of the Unix system backup tool). The TAR command appears in UNIX Version 7. The name of this command comes from "Tape Archiver". This command is designed to make data from the system to the tape or recover data from the system from the system.
The basic syntax of the TAR command is:
Tar -Mode -Option [files]
Here C represents the BACKUP, XX extraction (RESTORE) or the -t content list (list), including the following elements: such as -V represents the detailed output, -f file represents the purpose (creating mode) or source (extraction or list Mode), more detailed information, please see the manual of the system TAR command (Man Tar).
Use TAR to do the simplest backup as follows:
TAR-CVF / DEV / ST0
Simple tar command output: Lost Found / VAR / VAR / ADM / VAR / ADM / LST / VAR / ADM / LST / LOG / VAR / ADM / LST / LOG / DEBUGVAR / ADM / LST / LOG / HISTORYVAR / ADM / LST / log / cmd.trace var / adm / lst / log / install.success var / adm / lstall / log / postin.failed var / adm / lst / log / install.failed var / admin / lstall / n ADM / LST / ANALYSE / BOOT.IMG VAR / ADM / LST / ANALYS / BOOT.MSG VAR / ADM / LST / AnalySE / BOOT.INFO VAR / ADM / LST / ANALYSE / BOOT.DIAG VAR / ADM / LST / AnalySE / Boot.Params Var / ADM / LST / DATABASE / VAR / Spool / [...]
The C option representation of this command represents a new backup (C) and uses the detailed 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) to write the data stream to the open file in the TAR data format, and close the file after all the data is written. Because we have selected the return device / dev / ST0, the file (storage medium) will drive the device back to the tape after TAR shutdown.
The next step will be that verification data is written correctly into the tape. Unfortunately, the TAR command in the Linux environment only provides a comparative mode verification means - tape content is reread, and compares the original file by one byte. However, this is still much better than no verification. Because there is a bad thing in the tape in the recovery.
After the end of the recovery and is verified, everything is not ending, because the data in the system is constantly changing, a method of retaining a backup of a changing system is to continuously perform a regular data to back up. There are many ways to implement such a backup, but most convenient is incremental and differential backup. The backup methods of these two methods are dependent on time, or based on the previous backup (increment), or based on the previous full backup. Incremental backups only back up data modified since the last backup, sometimes referred to as a regular backup; and differential backups only back up files that have changed over the last complete backup. The following table is the characteristics of several backup solutions:
Full Backup Incremental Backup Differential Backup Space Using Mostleastless Than Full Backup Speed Slowstfastestfaster Than Full Recovery Speed FastestSlowestFaster Than Incremental
The figure below shows the comparison of incremental backups and differential backups for a week, the first picture is incremental backup:
It can be seen that the differential backup may back up the data ignored to the incremental backup, but the differential backup recovery speed is fast than the increment, as it only needs the last full backup and the most differential backup; and incremental backup needs from A complete backup of each incremental backup.
For the user's writing method, you need to use the -n or --newer option of the tar command, followed by a time, the time should be the usual calendar format (for example: 03/199 = March 12th, 1999).
TAR-CVF / DEV / ST0 --NEWER 03/12/1999 /
This command will be the file in the backup system in March 12th, 1999 and its future.
I will provide a simple script file to automate the automation model that simultaneously implements complete and differential backups. Before using this script, pay attention to check the environment variable defined by the script to meet your needs.
#! / bin / sh
#
###################################################################
#
# TAR Backup Script to Cover Daily and weekly Backups on one tape.
# Generic UNIX Version - Edit Variables As Required
#
# For this to work, it must be started on a monDay!
#
# Copyright (c) 1999, Tim Jones
# Permission granted for use / modification
#
# Tim Jones / Linux Magazine Provide this Shell Script with no warranty
# (IMPLIED or OTHERWISE)
#
############################################################################
DOW = `Date % W`
Date = `Date % D`
Day = `Date % a`
Device = "My Rewind Tape" # REWINDING TAPE DRIVE
Ndevice = "my no_rewind tape" # non-reveving tape drive
Rewind = "MT -F $ Device Rewind"
EOD = "MT -F $ NDEVICE EOD"
FSF = "MT -F $ NDEVICE FSF"
Mailist = "root" # list of users to receive backup noticeif [$ dow = "6"]
THEN
# This is saturday, so append and write the whole system!
$ Eod
Echo $ DATE> /TMP/.lastfull
TAR-CVF $ nDevice /> /TMP/Backup.txt
$ REWIND
$ Fsf 5
TAR-DVF $ nDevice >> /tmp/backup.txt
$ REWIND
Cp /TMP/.lastfull /etc/.lastfull
Else
# this is not saturday
Case $ dow in
0)
# it's sunday - nothing to do
EXIT 0
;
1)
# Monday, Let the Tape Rewind for the Difference Verification
Echo $ DATE> /TMP/.lastinc
TAR-CVVF $ Device --Newer `Cat / etc / .lastfull` /> /tmp/backup.txt
Cp /TMP/.lastinc /etc/.lastinc
;
*)
# OtR DAYS, MUST REWIND MANUALLY AND INSPECT, -I
$ Eod
Echo $ DATE> /TMP/.lastinc
TAR-CVF $ NDEVICE - Newer `Cat / etc / .lastinc` /> / tmp / backup
$ REWIND
$ Fsf `expr $ dow - 1`
echo "*********** Verifying $ {day} 's backup" >> /TMP/backup.txt
TAR --DVF $ nDevice >> /tmp/backup.txt
Cp /TMP/.lastinc /etc/.lastinc
$ REWIND
ESAC
Fi
Mail $ MAILLIST
RM -F /TMP/Backup.txt
# END of Script
Reference
For more information on DUMP, TAR and GZIPs that are included in various Linux releases, please refer to the following resources:
http://rsync.samba.org/ - rsync
http://www.amanda.org/ - Amanda
ftp://ftp.zn-gmbh.com/pub/linux/ - AfBackup
http://www.cs.wisc.edu/~jmelski/burt/ - Burt
http://www.estinc.com/features.html - bru
http://www.estinc.com/qsdr.html - QuickStart
http://www.unitrends.com/bp.html - Backup Professional
http://www.unitrends.com/ctar.html - CTAR
http://www.unitrends.com/ctarnet.html - CTAR: Net
http://www.unitrends.com/pcpara.html - PC Parachute
http://www.arkeia.com/ - arkeia
http://www.legato.com/Products/html/legato_networker.html - Legato Networker ftp://ftp.legato.com/pub/Unsupported/Linux_Client/ - Unsupported Legato Networker Linux client softwarehttp: //www.merlinsoftech. COM / Nonflash / Merlinhome.htm - Perfect Backup