Simple operations for Linux tape drives

Source: Internet
Author: User
Tags rewind

Since the development of Linux, Linux has become more and more popular with the development of more than a decade. Many programmers are studying Linux. There are many Linux tape drives, mainly through software such as Amanda and Tar. The following describes the knowledge of Linux tape drives.

Amanda provides the remote centralized backup function, which enables remote centralized storage and backup by setting the client and server respectively. Tar is mainly used to directly write data to the tape for backup in a single-host environment. For single-node backup, you only need to simply use the Tar command for backup and recovery.

Install

The HP DAT24/40 series external SCSI tape drives of current manufacturers all provide automatic back-to-volume functions. Connect it to the external SCSI bus and restart the server. After the reboot, run the dmesg command to view the new drive device/dev/st0.

 
 
  1. blk: queue ef0d7a14, I/O limit 4095Mb (mask 0xffffffff)  
  2. audit subsystem ver 0.1 initialized  
  3. (scsi0:A:3): 10.000MB/s transfers (10.000MHz, offset 15)  
  4. Vendor: HP Model: C1537A Rev: L805  
  5. Type: Sequential-Access ANSI SCSI revision: 02  
  6. blk: queue ef0e4614, I/O limit 4095Mb (mask 0xffffffff)  
  7. Attached scsi tape st0 at scsi0, channel 0, id 3, lun 0 

Tape operation

After attaching a tape, perform the following operations:

Rewind to roll the tape to the starting position

Mt-f/dev/st0 rewind

Erase, erase the content on the tape

Mt-f/dev/st0 erase

Note: The erasure operation is very slow and has damage to the tape. It is recommended that you do not execute it. When the data is full, you can continue to write data and overwrite the original data without performing the erasure operation. The new tape can be used immediately after it is encapsulated and does not need to be erased.

Out-of-band, roll the tape to the initial position and then pop up from the tape drive

Mt-f/dev/st0 offline

Data Operations

The basic operations are as follows:

1. Operate tar tvf/dev/st0 in the column directory

If there are no files on the tape, the column directory will report an error. This error does not affect the use of the tape.

 
 
  1. [root@dev131 /root]# tar tvf /dev/st0  
  2. tar: /dev/st0: Cannot read: Input/output error  
  3. tar: At beginning of tape, quitting now  
  4. tar: Error is not recoverable: exiting now  
  5. [root@dev131 /root]# 

2. Write Data to tar cvf/dev/st0 <file name to be written>

There are two ways to write data: Writing files directly without packaging and writing files after packaging and compression. Both have their own advantages and disadvantages. The method of writing files directly without packaging seems to be inefficient and complicated, but it can improve the data survival rate. Tape is a linear storage device that writes all data in close sequence. When a tape is damaged, the tapes in other locations can still be read, and all files can be read. If you use the compressed and compressed packaging method, only one file is stored on the tape. When a fault occurs in any part of the tape and the file cannot be read, the compressed file lacks some details. Even a bit error will cause the compressed file to report a CRC error and cannot be decompressed. Therefore, if you store a large amount of data, we recommend that you write it directly. If you want to access a small file, you 'd better package it and add a time mark to the file name.

For example, to write/root/test1.tar.gz to a tape and overwrite the tape content:

Tar cvf/dev/st0 test1.tar.gz

The transmission speed of the tape drive is relatively slow. For file backup that is not very large, wait a few seconds to complete the writing. Use the cvf parameter to overwrite the existing files on the belt.

Then list the files on the tape:

 
 
  1. [root@dev131 /root]# tar tvf /dev/st0  
  2. -rw-r--r-- root/root 320 2006-12-01 09:29:02  
  3. test1.tar.gz  
  4. [root@dev131 /root]# 

The data is successfully written.

Note: This command can only be written when the tape is brand new. During the second execution, the original data on the tape will be overwritten. In addition, if you use the tar command for backup, the size of the backup file must be smaller than the size of a single disk tape, that is, a file cannot span two disks. In this case, you cannot use the tar command to back up data. You need to use another backup program.

3. Continue writing data to tar rvf/dev/st0 <file name to be written>

Tape storage is linear, and all data is written in sequence. To avoid overwriting the content on the front, you must use the rvf parameter to write the Content During writing.

Tar rvf/dev/st0 test2.tar.gz

Run rvf again to write other files:

Tar rvf/dev/st0 test3.tar.gz

After writing, check the files on the tape:

 
 
  1. [root@dev131 /root]# tar tvf /dev/st0  
  2. -rw-r--r-- root/root 320 2006-12-01 09:29:02  
  3. test1.tar.gz  
  4. -rw-r--r-- root/root 320 2006-12-01 09:44:19  
  5. test2.tar.gz  
  6. -rw-r--r-- root/root 320 2006-12-01 09:30:14  
  7. test3.tar.gz  
  8. [root@dev131 /root]# 

As you can see, the newly written and original files are stored on the tape.

The linear Storage Feature of tape enables two identical files to be written to the tape. For example, the file size of the test3 file changes and is written to the tape again:

Tar rvf/dev/st0 test3.tar.gz

View the file list. The following files are displayed on the tape:

 
 
  1. [root@dev131 /root]# tar tvf /dev/st0  
  2. -rw-r--r-- root/root 320 2006-12-01 09:29:02  
  3. test1.tar.gz  
  4. -rw-r--r-- root/root 320 2006-12-01 09:30:14  
  5. test2.tar.gz  
  6. -rw-r--r-- root/root 320 2006-12-01 09:44:19  
  7. test3.tar.gz  
  8. -rw-r--r-- root/root 67085 2006-12-01 09:44:19  
  9. test3.tar.gz  
  10. [root@dev131 /root]# 

We can see that there are two files written to the tape with the same name. The size and time of the two backups of this file can be the same or different.

Note: If the same file is written multiple times on the tape, it will be troublesome to recover. You need to first roll the tape to the location where the file is stored, then, read the files stored in the current location of the tape. The operation is complicated and the speed is also slow. Therefore, it is not recommended to write files with the same file name on a tape. Before backup, it is best to add a time mark to the name of the backup file to facilitate Backup Search. For example, if the file name to be backed up is test-20061-0-0930.tar.gzand test-20061201-0945.tar.gz, it is written to a tape. In this way, the backup and recovery operations can be performed more conveniently and quickly.

4. Read data tar xvf/dev/st0 <file name to be read>

Before reading data, first view the content on the tape and obtain the file name to be restored. For example, view the following result:

 
 
  1. [root@dev131 /root]# tar tvf /dev/st0  
  2. -rw-r--r-- root/root 320 2006-12-01 09:29:02  
  3. test1.tar.gz  
  4. -rw-r--r-- root/root 320 2006-12-01 09:30:14  
  5. test2.tar.gz  
  6. -rw-r--r-- root/root 320 2006-12-01 09:44:19  
  7. test3.tar.gz  
  8. [root@dev131 /root]# 

Restore the test3.tar.gz file and run the following command:

Tar xvf/dev/st0 test3.tar.gz

After reading data.

 
 
  1. [root@dev131 ~]# tar xvf /dev/st0 test3.tar.gz  
  2. test3.tar.gz  
  3. [root@dev131 ~]# 

Then you can find the file read from the tape in the current path:

 
 
  1. [root@dev131 ~]# ls -l test3.tar.gz  
  2. -rw-r--r-- 1 root root 320 Dec 1 11:12  
  3. test3.tar.gz  
  4. [root@dev131 ~]# 

So far, the recovery operation has been completed.

Using the tar command described above, you can use the tvf/cvf/rvf/xvf parameter to read and write tapes. You can use a pre-written copy data script, with the operating commands of the on-disk drive, and place it in/etc/crontab to implement automatic backup. I hope you can learn about Linux tape drives through this article.

  1. Configuration notes: configure the DNS server in Linux
  2. How to display Chinese Characters in RedHat Linux 5
  3. How to disable SELinux in Redhat Enterprise Linux
  4. Install the KDE package in Linux
  5. Redhat Linux Remote Desktop configuration

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.