HomePage :: TechnicalProjects :: LinuxTapeBackupScript

Linux Tape Backup Script

NOTE: All of the information on this page was written by Scott Manzella

Simple Backup Script Using tar

 #!/bin/bash
 # Tape Backup Procedure
 #
 /usr/bin/mt -f /dev/st0 load
 /bin/sleep 5
 /usr/bin/mt -f /dev/st0 retension
 /bin/sleep 5
 /bin/tar -cvf /dev/st0 /etc /home /root /srv /bin /usr
 /bin/sleep 5
 /usr/bin/mt -f /dev/st0 offline
 exit

Notes

This particular script was specifically designed to run on SuSE. With exception to the mt load option, this script should work on a SuSE installation with either a DDS or Travan drive.

The load option does not work in the SuSE implementation of mt. However, the mt load option does work under Red Hat. This option is useful for some tape drives that are slow to recognize media, especially the DDS (2,3,4) drives. It wakes the tape drive and makes it ready for further tape operations.

A sleep command after each tape operation can prevent the tape from returning a tape not ready response to the next command. The sleep command gives the tape drive a few seconds to catch up and make itself ready for the next command.

The mt retension option is only necessary for Travan drives. DDS tapes do not need to be retensioned. Travan tapes should be retensioned before each use.

The data that is to be backed up is tarred to tape. (This is what tar (tape archive) was originally designed for). the -cvf option is used:

c - create archive

v - verbose mode, lots of pretty files scrolling down the screen

f - specifies the output file which is a tape drive — in our example (/dev/st0)

Be aware that if your tape drive is a SCSI unit, /dev/st0 works automatically. Some Travan drives are IDE. In the event that an IDE drive is used, SCSI emulation must be employed to allow the mt and tar commands to work properly with the tape drive. Check with your OS documentation for the best way to emulate SCSI on an IDE device.

The mt offline command ejects the tape from the drive. DDS tapes are physically ejected by the drive. Travan tapes are simply made ready to be removed by the user.

One option that can be placed after the mt load command is the mt erase command. This command will quickly erase a tape. Erasing a tape is useful for avoiding a read only error returned by some tapes after they are used with various commercial backup applications.

Also, be aware that in order to use this script on a Red Hat box, it is necessary to provide the correct paths for the mt command. On a Red Hat box, mt is located in /bin/mt, not /usr/bin/mt as it is on a Suse box.