Guide |
Tape devices should be used only for periodic file archives or to transfer data from one server to another. Typically a tape device is connected to a Unix machine and controlled with MT or MTX. It is strongly recommended that you back up all your data to disk (perhaps in the cloud) and tape devices at the same time. |
In this tutorial you will learn:
- Tape Device Name
- Basic commands for managing tape drives
- Basic Backup and Restore commands
why backup?
A backup plan is necessary for regular backup files, and if you prefer not to back up, the risk of losing important data increases significantly. With backup, you have the ability to recover from a disk failure. Backups can also help you protect against:
- Accidental file deletion
- file or file system corruption
- The server is completely destroyed, including a backup of the same disk caused by a fire or other problem
- Hard disk or SSD crashes
- Virus or ransomware destroys or deletes files
You can use tape archives to back up your entire server and store it offline.
Understanding Tape File markers and block sizes
Each tape device can store multiple backup files. Tape backup files are created through 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) onto a physical tape. There is a "tape file mark" between each tape file. This is used to indicate the end of a tape file on a 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. The first tape archive begins storage (tar #0) from the physical start of the tape. The next step is the tar #1, and so on.
tape device name on Unix
- /dev/rmt/0 or/DEV/RMT/1 or/dev/rmt/[0-127]: A generic tape device name on Unix. The tape is automatically inverted back.
- /dev/rmt/0n: Feature with no rewind, in other words, after the tape is used, stay in the current state and wait for the next command.
- /DEV/RMT/0B: Using the tape interface, which is BSD behavior. 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 density to medium.
- /DEV/RMT/0U: Set the density to high.
- /DEV/RMT/0C: Set 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 a specific SCSI tape device name, which pops up when it is turned off (if available).
Tape Device Name Example
- /DEV/RMT/1CN indicates that Unity 1 is being used, compression density, no rewind.
- /DEV/RMT/0HB indicates that unity 0, high density, BSD behavior is being used.
- Auto-Rewind SCSI tape device name on Linux:/dev/st0
- Non-inverted SCSI tape device name on Linux:/dev/nst0
- Auto-Rewind SCSI tape device on FreeBSD name:/dev/sa0
- Non-inverted SCSI tape device name on FreeBSD:/dev/nsa0
How do I list the installed SCSI tape devices?
Enter the following command:
# # # Linux (more information see MAN) # # #lsscsilsscsi-g### IBM AIX # # #lsdev-cc tapelsdev-cc adsmlscfg-vl rmt*### Solaris Unix # # #cfgad M–ACFGADM-ALLUXADM probeiostat-en### HP-UX Unix # # #ioscan cfioscan-func TAPEIOSCAN-FNC TAPEIOSCAN-KFC Tape
MT Command Example
On Linux and Unix-like systems, the MT command is used to control the operation of a tape drive, such as viewing a state or finding a file on a tape or writing a tape control tag. Most of the following commands need to be performed as root users. The syntax is as follows:
Mt-f/tape/device/name operation
setting up the environment
You can set the TAPE shell variable. This is the path name of the tape drive. The default on FreeBSD (if the variable is not set, NOT null) is/DEV/NSA0. You can override this by passing a variable through the-f parameter of the MT command, as explained below.
# # # Add to your shell config file # # tape=/dev/st1 #Linux tape=/dev/rmt/2 #Unix tape=/dev/nsa3 #FreeBSD export TAPE
1: Show tape/drive status
MT Status # # # Use defaultmt-f/dev/rmt/0 Status # # # unixmt-f/dev/st0 Status # # Linuxmt-f/dev/nsa0 Status # # # Freebsdmt-f/DEV/RMT/1 Status # # Unix Unity 1 That's tape device No. 1
You can use the Shell Loop statement to traverse a system and locate all of its tape drives as follows:
For d in 0 1 2 3 4 5do mt-f "/dev/rmt/${d}" Statusdone
2: Rewind
Mt REWMT rewindmt-f/dev/mt/0 rewindmt-f/dev/st0 Rewind
3: Eject tape
Mt offmt offlinemt ejectmt-f/dev/mt/0 offmt-f/dev/st0 Eject
4: Erase tape (rewind, unload tape in case of support)
Mt erasemt-f/dev/st0 Erase #Linuxmt-F/dev/rmt/0 Erase #Unix
5: Tension Tape Box
If an error occurs while the tape is reading, you re-tighten the tape, clean the tape drive, and try again as follows:
Mt Retensionmt-f/DEV/RMT/1 retension #Unixmt-F/dev/st0 retension #Linux
6: Write the EOF tag at the current position of the tape
Mt Eofmt Weofmt-f/dev/st0 EOF
7: Forward the tape to the specified number of file tokens, that is, skipping the specified EOF mark
The tape is positioned in the first block of the next file, i.e. the tape locates the first block in the next area (see Figure 01):
Mt Fsfmt-f/dev/rmt/0 fsfmt-f/dev/rmt/1 FSF 1 #go 1 forward file/tape (see fig.01)
8: Rewind tape To specify the number of file markers, that is, rewind with a specified EOF marker
The tape is positioned in the first block of the next file, i.e. the tape is positioned after the EOF tag (see figure 01):
Mt bsfmt-f/DEV/RMT/1 bsfmt-f/dev/rmt/1 BSF 1 #go 1 backward file/tape (see fig.01)
Here is a list of tape location commands:
FSF Advance Specifies the number of file tokens. The tape is positioned in the first block of the next file. FSFM Forward Specifies the number of file tokens. The tape is positioned at the last piece of the previous file. BSF back Specifies the number of file tokens. The tape is positioned at the last piece of the previous file. BSFM back Specifies the number of file tokens. The tape is positioned in the first block of the next file. ASF Tape is positioned at the beginning of the specified number of file markers. Positioning is achieved by first rewinding and then moving forward with the specified number of file tokens. FSR Advances the specified number of records. BSR back Specifies the number of records. FSS (SCSI Tapes) forwards the specified setmarks. BSS (SCSI tapes) backs up the specified setmarks.
Basic Backup Commands
Let's take a look at the backup and restore commands.
9: Backup directory (tar format)
Tar Cvf/dev/rmt/0n/etctar cvf/dev/st0/etc
10: Recovery directory (tar format)
Tar xvf/dev/rmt/0n-c/path/to/restoretar xvf/dev/st0-c/tmp
11: List or check the tape contents (tar format)
Mt-f/dev/st0 Rewind; DD if=/dev/st0 of=-### tar format # # #tar TVF {DEVICE} {Directory-filename}tar Tvf/dev/st0tar tvf/dev/st0 Desktoptar Tvf/dev /rmt/0 foo > List.txt
12: Use Dump or ufsdump backup partition
# # Unix Backup C0T0D0S2 Partition # # #ufsdump 0uf/dev/rmt/0 /dev/rdsk/c0t0d0s2### Linux backup/home Partition # # #dump 0UF/DEV/NST0/DEV/S Da5dump 0uf/dev/nst0/home### FreeBSD backup/usr partition # # #dump -0al-b64-f/dev/nsa0/usr
12: Recover partition using Ufsrestore or Restore
# # # UNIX # # #ufsrestore xf/dev/rmt/0### Unix Interactive Recovery # # #ufsrestore if/dev/rmt/0### Linux # # #restore rf/dev/nst0### from the tape media 6th Backup Interactive Recovery # # #restore ISF 6/dev/nst0### FreeBSD Recovery ufsdump Format # #restore-I-f/dev/nsa0
13: Start writing from the beginning of the tape (see figure)
# # # This will overwrite all data on tape # # #mt-F/dev/st1 rewind### backup Home # # #tar cvf/dev/st1/home### offline and unload Tape # # #mt-F/dev/st0 offline
Start recovery from the beginning of the tape:
Mt-f/dev/st0 Rewindtar xvf/dev/st0mt-f/dev/st0 offline
14: Start writing from the last tar (see map)
# # # This preserves previously written data # # #mt-F/dev/st1 eom### backup Home # # #tar cvf/dev/st1/home### Uninstall # # #mt-F/dev/st0 offline
15: Start Writing from tar number 2 (see figure)
# # # is written after tar number 2 (should be 2+1) # # #mt-F/dev/st0 asf 3tar cvf/dev/st0/usr### asf equivalent to FSF # # #mt-F/dev/sf0 rewindmt-f /dev/st0 FSF 2
Recover Tar from tar number 2:
Mt-f/dev/st0 asf 3tar xvf/dev/st0mt-f/dev/st0 offline
about third-party backup tools
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
15 Practical Linux/unix Tape Management commands