Linux Tape Drive Backup Full introduction

Source: Internet
Author: User
Tags file copy posix rewind knowledge base

First, determine the data backup strategy

You must first determine which files to manipulate during the backup process. In a business environment, this is a very difficult decision and can have a serious impact. If too much data is backed up, the cost of the backup system is too large to cut other expenses. If you do not back up enough data, the important data may be lost.

Backing up the entire system is simple (make sure that you don't back up some of the NFS-mounted directories and special file systems such as/proc/), but there are often too many things to back up. If the data on the entire system disk is lost, it is likely that you will have to reinstall the basic operating system before recovering any data. It is not meaningless to save these system files on a backup tape. Therefore, in order to reduce the cost of the backup system (including hardware, network, system load, and backup time), you should usually only back up important files.

Shared programs: Public programs that can be used in multiple systems. The/usr/local or/opt directory is often shared between multiple systems that contain other operating systems that are not provided with the operating system.

User data: The user home directory that contains all user data and private files.

Application data: In a distributed computing environment, application data is typically shared across multiple systems. For example, a Web server cluster typically needs to share the same content.

System Information: System Information includes account information (user, Group and password), mail alias, host list, etc. Only you know where your data is stored and at least think about it before you build your own backup system. Although I cannot list every piece of data that needs to be backed up, I can provide some guidance, including:

Important system data: Do not forget important system data, such as files in the/etc/directory, and sometimes files in the/var/directory. If these files are automatically generated, you may only need to back up these files on the primary system.

Software added later: includes software provided by any non-native operating system installed in the systems. You may have installed these software in the/opt/or/usr/local/directory, which simplifies the backup process for these software. Alternatively, you might install all of these programs on a centralized file server, which makes the backup process easier. If you have some packages installed on your system, be sure to save the packages that are already installed and include them in the backup process.

application configuration files and data: Consider which services are running on each system. If a system is running the DNS service, ensure that the zone file is included in the backup. If the system is running Web services, it is necessary to back up Web content, and sometimes even to back up access logs, which may or may not be important.

Development resources: If you have a CVS repository, a bug database, a knowledge base, and other development tools that hold important data, you should ensure that the files are included in the backup.

Management tools: Don't forget to include all your system automation scripts and tools during the backup process.

Database: If you save some data in one or more databases, you obviously want to include the data in the backup process, but in addition, make sure that the data is backed up correctly. In many cases, in order to properly back up the contents of a database, you may need to close the database or dump the data. Although some database software can export and back up the data to the appropriate format, some backup software can back up the database while the database is running.

User data: Finally, users in the system are usually very grateful that you included their private files when you backed up. If you have a large file server, this machine is a good place to perform backups and replicate data from other systems as needed.

Another question to consider is what level of time is required for the backup process. If you use a tape backup system and you have only one tape, you have to replace the data on the tape every day. If a person realizes a few days later that they have mistakenly deleted a document, they are too unfortunate. Of course, if all the data can be stored on a tape, the solution is simple-just buy

Multiple tapes. But if there is a lot of data, then the situation is much more complicated.

Ii. Introduction to Storage Tapes

Tape storage is a fairly broad category, including DDS, LTO, DAT, DLT, SDLT, and more. For decades, various tapes have become traditional backup media. Table 1 is a list of tape technologies:

Tape type

Tape capacity

Minimum life

DAT Tape 4 mm DDS

4 GB (120 m DDS-2)

3-4 years

GB (125 m DDS-3)

3-4 years

GB (150 m DDS-4)

3-4 years

8 mm Tape

7 GB (160 m)

2-4 years

Mammoth-2 (AME)

GB

3-4 years

GB

3-4 years

AIT Tape

GB

3-4 years

GB

3-4 years

Gb

3-4 years

DLT

+ GB

10

Table 1 Introduction to tape technology

Note: The technology used by DDS-3 and DDS-4 differs from earlier versions. The latest tape drives only support the largest tapes, but most drives provide read-only backward compatibility.

III. Tape Management Commands

From the user's point of view, any Linux device can be viewed as a file. Therefore, you can "open" the appropriate tape drive file for write operations, and the data to be backed up is written to the file. It sounds too simple, but that's the way it is. UNIX systems treat every device as a file, as with a normal file, so that the file and device operations are as uniform as possible. From the user's point of view, the use of the device is the same as the general file. So the most effective way to manage tapes is to use the relevant commands.

1.tar command

The TAR command is a tool for creating and restoring backup files, and there are several options if you want to use tape instead of using a hard disk to back up data based on certain basic principles. The most commonly used program is tar, and most UNIX classes also contain this program. Here's how to do some simple backups using GNU tar. If you just want to back up a system on tape, that's where it's powerful. You can also use Rsync to copy files from several systems and then use TAR to package the data on tape. The following examples are based on the following 3-point hypothesis:

Backing up the/home/directory. You can specify a different directory or multiple directories simply by modifying them in the appropriate location.

The tape drive is accessed through the device file/DEV/ST0. If there is only one SCSI tape drive on a Linux system, then the correct device file is/dev/st0. If this is not the case, you will need to use the appropriate device files to match the hardware device.

This article uses the TANDBERG data, the latest semi-high LTO Ultrium 2 tape drive with a 5.25-inch tape for a half-height tape drive with a speed of 48MBps and a compression capacity of up to 400GB.

Figure Semi-high LTO Ultrium 2 tape drive

The script is executed as the root user, and the current working directory is the root directory (/).

Use Tar for basic backups

To create a full backup on tape using tar, you can run the following command:

#tar Cvpf/dev/st0home

Option C means that a new file should be created; The option v means that the files should be displayed at the same time that they are added to the file; The option p means that all permissions should be preserved; the option F means that the file should be written to a document (/dev/st0, which actually represents your tape drive).

Create an incremental backup using tar

To create a simple incremental backup, you can use the-n option provided by GNU Tar, which allows you to specify a date and specifies that only files that have been created or modified after that date will be included in the file. Assuming a daily backup, you can use the following command to make an incremental backup:

#tar cpf/dev/st0-n "$ (date-d ' 1dayago ')" Home

The following script can perform all the backups for you:

#!/bin/bash
# Where to place backup log files
Log_dir= "/usr/local/var/backup_logs"
# which directories to include in Backup
Dirs= "Home"
# which output file or tape device to use
dev= "/dev/st0"
today=$ (Date +%a)
CD/
Case $today in
Mon)
# Full Backup
Tar cvpf $DEV $DIRS
Mt-f $DEV Rewind
Mt-f $DEV offline
;;
tue| wed| thu| Fri)
# Partial Backup
Tar cvpf $DEV-n "$ (date-d ' 1 day ago ')" $DIRS
Mt-f $DEV Rewind
Mt-f $DEV offline
;;
*)
# Weekend, do nothing
;;

Assuming that the backup script executes every morning, you can replace the tape every day after the script has finished running. This way, you can always change to tomorrow's tape for backup.

Backup of Tapes

So far, the discussion of tar is actually completely unrelated to the backup media, and Tar uses the tape as a disk-like device (except that when you use the disk, you specify the output file name, not the tape device). There are other challenges that can occur when you want to back up data to a physical tape. First, the backup data may need to span multiple tapes. This can be achieved using the--multi-volume (-m) switch:

#tar Cpf/dev/st0-m Home

If you are backing up data that involves more than one tape, you cannot use the--gzip (-z) switch. If tar detects an error when you reach the end of the tape, you can use the--tape-length (-l) switch to specify the size of the tape (in kilobytes):

#tar cpf/dev/st0-m-l 4000000 Home

In this example, we specify the use of a 4GB tape.

Recovering data from a tar package

Recovering data from a backup package created from a tape using tar is very slow. When recovering data, regardless of whether an incremental backup is used, the first thing to determine is when the previous data is intact. You can then select the appropriate tapes based on this point in time and extract the files from the tape. If you need to see which files are included in the TAR package, you can use the T switch. Note that this requires reading the entire tar package, which can be very slow if the tar package is on tape.

#tar tvf/dev/st0

The entire package can be expanded in the current directory:

#tar xvpf/dev/st0

You can also expand only specific files or directories. In the following example, we can expand only one user's entire home directory:

#tar xvpf/dev/st0 Home/user1

Alternatively, we can just expand one file:

#tar xvpf/dev/st0 Home/user1/file1

Note that even if you expand only one file, you may need to process the entire package. Similarly, on tape drives, this can be very slow.

2.cpio Command

The Cpio command is used to replicate files, special files, or file systems that require multiple tape volumes. Cpio command parameters are too many, here only the relevant parameters.

Copy all the files in the directory to tape. The steps are as follows:

1. Go to the directory that contains the files you want to copy.

2. Insert the writable tape into the tape drive.

3. Copy the file to tape. Use the command:

$ ls | Cpio-oc >/dev/st0

Parameter description: LS provides a list of file names for the Cpio command; cpio-oc specifies that the CPIO command should operate in copy-out mode (-O) and write header information in ASCII character format (-C). These options ensure that systems can be ported to other vendors. >/DEV/STN: Specifies the output file.

All files in the directory are copied to the tape in the specified tape drive, and any existing files on that tape are also overwrite. The screen displays the total number of blocks copied.

Application Examples:

Copy all files in the/export/home/directory to tape:

$ cd/export/home/kryten
$ ls | Cpio-oc >/dev/st0
Blocks
$ CPIO-CIVT </dev/st0
-rw-r--r--1 root Other 0 Jul 14:59, Filea
-rw-r--r--1 root Other 0 Jul 14:59, Fileb
-rw-r--r--1 root Other 0 Jul 14:59, Filec
Drwxr-xr-x 2 Root Other 0 Jul 14:59, letters
Blocks

Recover all files from tape (cpio)

If an archive is created with a relative pathname, the input file is generated as a directory in the current directory when the file is restored. However, if an archive file has been created with an absolute pathname, the file will be recreated in the system using the same absolute path. The steps are as follows:

1. Go to the directory where you want to place the file.

2. Insert the tape into the tape drive.

3. Extract all files from the tape. The command is as follows:

$ CPIO-ICVD </dev/st0

3. Tar and Cpio command comparison

In some cases, especially for single-user systems, complex backup procedures are not required, and the simple tape commands such as tar and CPIC can periodically save important data to tape. Tar and Cpio can also back up local and remote file systems that are loaded via NFS. Table 2 is the comparison and pros and cons of the tar and Cpio commands

Command

Function

Advantages

Disadvantages

Is it possible to recognize

No files

System boundaries

Whether to support

Hold multiple volumes

Backup

Tar

Used to copy files and directory subtrees to a single tape.

L can be used in most UNIX operating systems

L Easy access to public domain versions

File system boundaries are not recognized;

The length of the full path name cannot exceed

255 characters;

cannot be used to create multiple tape volumes;

Whether

Whether

Cpio

Used to replicate files, special files, or file systems that require multiple tape volumes. Or, use when you want to copy a file from a running system to a running system.

L can more efficiently package data to tape than using the TAR command

L Skip all error points on the tape when recovering

L provides options for writing files in different header formats (such as TAR, Ustar, CRC, ODC, bar) for portability between different system types

L Create multiple tape volumes

The syntax of the command is more complex than the tar command.

Whether

Is

Table 2 Advantages and disadvantages of the tar and Cpio commands

1. MT command

The MT command is used to control the tape drive. You can use the status option of the MT command to obtain information about the status of the tape drive. The MT command reports information about all the tape drives that are described in configuration file/kernel/drv/st.conf.

MT Command format: MT [-F Device] command [Count],

Mt-f/dev/st0 Status View hardware information for the tape drive.

Mt-f/dev/st0 Erase the tape in the tape drive for data deletion actions.

Mt-f/dev/st0 Rewind The tape for the back-band action.

Mt-f/dev/st0 offline Tape is brought back and exited by the tape drive.

Mt–f/dev/st0 unload to eject the tape from the tape drive.

Mt-f/dev/st0 compression off turns off the hardware compression feature.

Pax command

For POSIX-compliant systems, the PAX command provides better portability than tar or cpio. You can use the PAX command when copying files that require multiple tape volumes, special files or file systems, or if you want to copy files into or out of a POSIX-compliant system.

1. Copy all files from one directory to tape

Use the following procedure to copy all files in the current directory to tape with the pax command.

(1) Change to the directory containing the file you want to copy.

(2) Insert a writable tape into the tape drive.

(3) Enter pax-w-F >/dev/st0 and enter. The-W option writes the contents of the current directory to the tape. The-f option identifies the tape drive. Command the last stronghold (.) Indicates the current directory. The pax command lists the copied files at the time of the copy.

(4) Enter pax-l-F </dev/st0 and enter. The-l option lists the files on the tape to confirm that the completed files have been copied.

(5) Remove the tape from the tape drive and specify the file name on the tape label.

The following example copies all files to the tape on drive 0.

%pax-w-F >/dev/st0

2. Recover all files on tape

Use the following steps to copy all the files on the tape to the current directory with the PAX command.

(1) Change to the directory where you want to copy the file.

(2) Insert a writable tape into the tape drive.

(3) Enter Pax-r-F </dev/st0 and enter. The-r option reads the contents of the tape to the current directory. The-f option identifies the tape drive. End of command period (.) Indicates the current working directory. The pax command does not list copy files when copying.

(4) Input ls-l and enter.

The ls-l command lists the files in the current directory and their permissions to verify the completion of the file copy.

(5) Take the tape from the tape drive and write down the file name on the tape label.

The following example shows a copy of all files from a tape in drive 0.

% Pax-r-f/dev/rmt/0
% Ls-l

See the PAX Handbook for more information.

Four, do the tape drive and storage media maintenance

Tape drives and tapes are good tools for server backup, but tape also has some downsides:

Tapes are very sensitive to heat and electromagnetic fields and are prone to error if handled improperly. Electromagnetic fields are generated by a variety of common devices around the computer, including UPS power supplies, peripherals that contain power supplies, monitors, and speakers.

In addition, the mere reading of tapes can also affect data.

Tape is a continuous storage device. In order to access a specified file on a tape, the tape must be scrolled to the correct point. This is often problematic for older tape drives. The current high-end drive is able to access any point within a few seconds.

For the above defects, the following measures should be taken:

1. Periodically clean and inspect the tape drive to ensure proper operation. Store the tape in a dust-free, safe position away from the magnetic device.

2. You should create a log and maintain it, which tracks the media (tape volumes) and the location of each backup file that stores each job (backup).

3. Pay attention to physical security. In the location where backup tapes are saved, general physical security should be considered: tapes must be protected from theft, vandalism, and possible environmental damage.

4. Properly save the tape. Some media have special requirements that must be taken into account. Tape reels for cassette cartridges, for example, are placed vertically (perpendicular to the ground, like a car's tires), and the China is in contact with the drive (thus gravity pulls the tape off the tape shaft).

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.