Tape devices should be used on a regular basis only for archiving files or for transferring data from one server to another. Usually, tape devices are all hooked up to Unix boxes, and controlled with mt or mtx. You must backup all data to both disks (may be in cloud) and tape device. In this tutorial you will learn about:
- Tape device names
- Basic commands to manage tape drive
- Basic backup and restore commands
### Why backup? ###
A backup plant is important:
- Ability to recover from disk failure
- Accidental file deletion
- File or file system corruption
- Complete server destruction, including destruction of on-site backups due to fire or other problems.
You can use tape based archives to backup the whole server and move tapes off-site.
### Understanding tape file marks and block size ###
Each tape device can store multiple tape backup files. Tape backup files are created using cpio, tar, dd, and so on. However, tape device can be opened, written data to, and closed by various program. You can store several backups (tapes) on physical tape. Between each tape file is a "tape file mark". This is used to indicate where one tape file ends and another begins on physical tape. You need to use mt command to positions the tape (winds forward and rewinds and marks).
#### How data is stored on a tape ####
![Fig.02: How data is stored on a tape](http://s0.cyberciti.org/uploads/cms/2015/10/how-data-is-stored-on-a-tape.jpg)
Fig.02: How data is stored on a tape
All data is stored subsequently in sequential tape archive format using tar. The first tape archive will start on the physical beginning of the tape (tar #0). The next will be tar #1 and so on.
### Tape device names on Unix ###
1. /dev/rmt/0 or /dev/rmt/1 or /dev/rmt/[0-127] : Regular tape device name on Unix. The tape is rewound.
1. /dev/rmt/0n : This is know as no rewind i.e. after using tape, leaves the tape in current status for next command.
1. /dev/rmt/0b : Use magtape interface i.e. BSD behavior. More-readable by a variety of OS's such as AIX, Windows, Linux, FreeBSD, and more.
1. /dev/rmt/0l : Set density to low.
1. /dev/rmt/0m : Set density to medium.
1. /dev/rmt/0u : Set density to high.
1. /dev/rmt/0c : Set density to compressed.
1. /dev/st[0-9] : Linux specific SCSI tape device name.
1. /dev/sa[0-9] : FreeBSD specific SCSI tape device name.
1. /dev/esa0 : FreeBSD specific SCSI tape device name that eject on close (if capable).
#### Tape device name examples ####
- The /dev/rmt/1cn indicate that I'm using unity 1, compressed density and no rewind.
- The /dev/rmt/0hb indicate that I'm using unity 0, high density and BSD behavior.
- The auto rewind SCSI tape device name on Linux : /dev/st0
- The non-rewind SCSI tape device name on Linux : /dev/nst0
- The auto rewind SCSI tape device name on FreeBSD: /dev/sa0
- The non-rewind SCSI tape device name on FreeBSD: /dev/nsa0
#### How do I list installed scsi tape devices? ####
![Fig.03: Installed tape devices on Linux server](http://s0.cyberciti.org/uploads/cms/2015/10/linux-find-tape-devices-command.jpg)
Fig.03: Installed tape devices on Linux server
### mt command examples ###
In Linux and Unix-like system, mt command is used to control operations of the tape drive, such as finding status or seeking through files on a tape or writing tape control marks to the tape. You must most of the following command as root user. The syntax is:
mt -f /tape/device/name operation
#### Setting up environment ####
You can set TAPE shell variable. This is the pathname of the tape drive. The default (if the variable is unset, but not if it is null) is /dev/nsa0 on FreeBSD. It may be overridden with the -f option passed to the mt command as explained below.
asf The tape is positioned at the beginning of the count file. Positioning is done by first rewinding the tape and then spacing forward over count filemarks.
### How do I verify backup tapes created using tar? ###
It is important that you do regular full system restorations and service testing, it's the only way to know for sure that the entire system is working correctly. See our [tutorial on verifying tar command tape backups][1] for more information.
### Sample shell script ###
#!/bin/bash
# A UNIX / Linux shell script to backup dirs to tape device like /dev/st0 (linux)
# This script make both full and incremental backups.
# You need at two sets of five tapes. Label each tape as Mon, Tue, Wed, Thu and Fri.
# You can run script at midnight or early morning each day using cronjons.
# The operator or sys admin can replace the tape every day after the script has done.
# Script must run as root or configure permission via sudo.
Both Linux and Unix-like system provides many third-party utilities which you can use to schedule the creation of backups including tape backups such as:
- Amanda
- Bacula
- rsync
- duplicity
- rsnapshot
See also
- Man pages - [mt(1)][2], [mtx(1)][3], [tar(1)][4], [dump(8)][5], [restore(8)][6]