Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the practical Linux/Unix tape management commands

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about what practical Linux/Unix tape management commands are about. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Why back up?

A backup plan is necessary for backing up files on a regular basis, and if you prefer not to back up, the risk of losing important data is greatly increased. With backup, you have the ability to recover from disk failures. Backups can also help you resist:

Unexpected file deletion

File or file system corruption

The server is completely destroyed, including the destruction of the same disk backup due to fire or other problems

Hard drive or SSD crashes

Virus or blackmail software destroys or deletes files

You can use tape archives to back up the entire server and store it offline.

Understand tape file tags and block sizes

Each tape device can store multiple backup files. Tape backup files are created by commands such as cpio,tar,dd. At the same time, tape devices can be opened, written, and closed by a variety of programs. You can store several backups (tape files) on a physical tape. There is a "tape file tag" between each tape file. This is used to indicate the end of a tape file on one physical tape and the beginning of another file. You need to use the mt command to locate the tape (fast forward, rewind and mark).

How the data on the tape is stored

All data is stored continuously in a continuous tape storage format using tar. * A tape archive is stored from the physical beginning of the tape (tar # 0). Next up is tar # 1, and so on.

Tape device name on Unix

/ dev/rmt/0 or / dev/rmt/1 or / dev/rmt/ [0-127]: regular tape device name on Unix. The tape is automatically rewound.

/ dev/rmt/0n: characterized by no rewind, in other words, after the tape is used, it stays in the current state and waits for the next command.

/ dev/rmt/0b: use the tape interface, which is the behavior of BSD. The behavior of various types of operating systems such as AIX,Windows,Linux,FreeBSD is more readable.

/ dev/rmt/0l: set the density to low.

/ dev/rmt/0m: set the density to medium.

/ dev/rmt/0u: set the density to high.

/ dev/rmt/0c: sets the density to compression.

/ dev/st [0-9]: Linux specific SCSI tape device name.

/ dev/sa [0-9]: FreeBSD specific SCSI tape device name.

/ dev/esa0: FreeBSD specific SCSI tape device name that pops up on shutdown (if possible).

Example of tape device name

/ dev/rmt/1cn indicates that unity 1 is being used, compression density, no reversal.

/ dev/rmt/0hb indicates that unity 0, high density, BSD behavior is being used.

Automatic rewind of SCSI tape device name on Linux: / dev/st0

No rewind SCSI tape device name on Linux: / dev/nst0

Automatic rewind of SCSI tape device name on FreeBSD: / dev/sa0

No rewind SCSI tape device name on FreeBSD: / dev/nsa0

How do I list installed scsi tape devices?

Enter the following command:

# Linux (see man for more information) # lsscsi lsscsi-g # IBM AIX # lsdev-Cc tape lsdev-Cc adsm lscfg-vl rmt* # Solaris Unix # cfgadm-a cfgadm-al luxadm probe iostat-En # HP-UX Unix # ioscan Cf ioscan-funC tape ioscan-fnC tape ioscan-kfC tape

Example of mt command

On Linux and Unix-like systems, the mt command is used to control the operation of the tape drive, such as checking status or finding files on tape or writing tape control tags. Most of the following commands need to be executed as root users. The syntax is as follows:

Mt-f / tape/device/name operation

Set up the environment

You can set the TAPE shell variable. This is the pathname of the tape drive. The default on FreeBSD (if the variable is not set instead of null) is / dev/nsa0. It can be overridden by passing variables in the-f argument of the mt command, as explained below.

# add to your shell profile # TAPE=/dev/st1 # Linux TAPE=/dev/rmt/2 # Unix TAPE=/dev/nsa3 # FreeBSD export TAPE

1: show tape / drive status

Mt status # Use default mt-f / dev/rmt/0 status # Unix mt-f / dev/st0 status # Linux mt-f / dev/nsa0 status # FreeBSD mt-f / dev/rmt/1 status # Unix unity 1 is tape device no. 1

You can use the shell loop statement to traverse a system and locate all its tape drives as follows:

For d in 0 1 2 3 4 5 do mt-f "/ dev/rmt/$ {d}" status done

2: rewind

Mt rew mt rewind mt-f / dev/mt/0 rewind mt-f / dev/st0 rewind

3: eject the tape

Mt off mt offline mt eject mt-f / dev/mt/0 off mt-f / dev/st0 eject

4: erase the tape (rewind, unload the tape if supported)

Mt erase mt-f / dev/st0 erase # Linux mt-f / dev/rmt/0 erase # Unix

5: tighten the tape cartridge

If there is an error while reading the tape, you retighten the tape, clean the tape drive, and try again like this:

Mt retension mt-f / dev/rmt/1 retension # Unix mt-f / dev/st0 retension # Linux

6: write the EOF tag at the current location of the tape

Mt eof mt weof mt-f / dev/st0 eof

7: forward the tape to the specified number of file tags, that is, skip the specified EOF tag

The tape is positioned in the * blocks of the next file, that is, the tape will be located in the blocks of the next area (see figure 01):

Mt fsf mt-f / dev/rmt/0 fsf mt-f / dev/rmt/1 fsf 1 # go 1 forward file/tape (see fig.01)

8: rewind the tape by the specified number of file tags, that is, rewind the tape to specify an EOF tag

The tape is positioned in the * * blocks of the next file, that is, the tape is positioned after the EOF tag (see figure 01):

Mt bsf mt-f / dev/rmt/1 bsf mt-f / dev/rmt/1 bsf 1 # go 1 backward file/tape (see fig.01)

Here is a list of tape positioning commands:

The number of file tags specified by the fsf forward. The tape is positioned in the * block of the next file. The number of file tags specified by the fsfm forward. The tape is positioned in the * * block of the previous file. Bsf reverses the specified number of file tags. The tape is positioned in the * * block of the previous file. Bsfm reverses the specified number of file tags. The tape is positioned in the * block of the next file. The asf tape is positioned at the beginning of the specified number of file tags. Positioning is achieved by rewinding and then advancing the specified number of file tags. Fsr advances the specified number of records. Bsr reverses the specified number of records. Fss (SCSI tapes) advances the specified setmarks. Bss (SCSI tapes) reverses the specified setmarks.

Basic backup command

Let's take a look at the backup and restore commands.

9: backup directory (tar format)

Tar cvf / dev/rmt/0n / etc tar cvf / dev/st0 / etc

10: restore directory (tar format)

Tar xvf / dev/rmt/0n-C / path/to/restore tar xvf / dev/st0-C / tmp

11: list or check the contents of the tape (tar format)

Mt-f / dev/st0 rewind; dd if=/dev/st0 of=- # tar format # tar tvf {DEVICE} {Directory-FileName} tar tvf / dev/st0 tar tvf / dev/st0 desktop tar tvf / dev/rmt/0 foo > list.txt

12: back up the partition using dump or ufsdump

# Unix backup c0t0d0s2 partition # ufsdump 0uf / dev/rmt/0 / dev/rdsk/c0t0d0s2 # Linux backup / home partition # dump 0uf / dev/nst0 / dev/sda5 dump 0uf / dev/nst0 / home # FreeBSD backup / usr partition # dump-0aL-b64-f / dev/nsa0 / usr

13: restore a partition using ufsrestore or restore

# Unix # ufsrestore xf / dev/rmt/0 # Unix Interactive recovery # ufsrestore if / dev/rmt/0 # Linux # restore rf / dev/nst0 # Interactive recovery from the sixth backup on the tape media # restore isf 6 / dev/nst0 # # FreeBSD recovery ufsdump format # restore-I-f / dev/nsa0

14: write from the beginning of the tape (see figure 02)

# this will overwrite all data on the tape # mt-f / dev/st1 rewind # backup home # tar cvf / dev/st1 / home # offline and uninstall the tape # mt-f / dev/st0 offline

Restore from the beginning of the tape:

Mt-f / dev/st0 rewind tar xvf / dev/st0 mt-f / dev/st0 offline

15: start writing after * a tar (see figure 02)

# this retains the previously written data # mt-f / dev/st1 eom # backup home # tar cvf / dev/st1 / home # Uninstall # mt-f / dev/st0 offline

16: start writing after tar number 2 (see figure 02)

# write after tar number 2 (should be 2x1) # mt-f / dev/st0 asf 3 tar cvf / dev/st0 / usr # asf is equivalent to fsf # mt-f / dev/sf0 rewind mt-f / dev/st0 fsf 2

Restore tar from tar number 2:

Mt-f / dev/st0 asf 3 tar xvf / dev/st0 mt-f / dev/st0 offline

About third-party backup tools

Both Linux and Unix-like systems provide a number of third-party tools that can be used to schedule backups, including tape backups, such as:

Amanda

Bacula

Rsync

Duplicity

Rsnapshot

Thank you for reading! This is the end of this article on "what are the practical Linux/Unix tape management commands?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report