[translating]20151130 Useful Linux and Unix Tape Managements Commands For Sysadmins

This commit is contained in:
alim0x 2016-01-09 22:43:51 +08:00
parent 29e2a62670
commit ec97b60533

View File

@ -1,3 +1,5 @@
alim0x translating
15 Useful Linux and Unix Tape Managements Commands For Sysadmins 15 Useful Linux and Unix Tape Managements Commands For Sysadmins
================================================================================ ================================================================================
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 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:
@ -62,24 +64,24 @@ Type the following commands:
## Linux (read man pages for more info) ## ## Linux (read man pages for more info) ##
lsscsi lsscsi
lsscsi -g lsscsi -g
## IBM AIX ## ## IBM AIX ##
lsdev -Cc tape lsdev -Cc tape
lsdev -Cc adsm lsdev -Cc adsm
lscfg -vl rmt* lscfg -vl rmt*
## Solaris Unix ## ## Solaris Unix ##
cfgadm a cfgadm a
cfgadm -al cfgadm -al
luxadm probe luxadm probe
iostat -En iostat -En
## HP-UX Unix ## ## HP-UX Unix ##
ioscan Cf ioscan Cf
ioscan -funC tape ioscan -funC tape
ioscan -fnC tape ioscan -fnC tape
ioscan -kfC tape ioscan -kfC tape
Sample outputs from my Linux server: Sample outputs from my Linux server:
@ -105,26 +107,26 @@ You can set TAPE shell variable. This is the pathname of the tape drive. The def
### 1: Display status of the tape/drive ### ### 1: Display status of the tape/drive ###
mt status #Use default mt status #Use default
mt -f /dev/rmt/0 status #Unix mt -f /dev/rmt/0 status #Unix
mt -f /dev/st0 status #Linux mt -f /dev/st0 status #Linux
mt -f /dev/nsa0 status #FreeBSD mt -f /dev/nsa0 status #FreeBSD
mt -f /dev/rmt/1 status #Unix unity 1 i.e. tape device no. 1 mt -f /dev/rmt/1 status #Unix unity 1 i.e. tape device no. 1
You can use shell loop as follows to poll a system and locate all of its tape drives: You can use shell loop as follows to poll a system and locate all of its tape drives:
for d in 0 1 2 3 4 5 for d in 0 1 2 3 4 5
do do
mt -f "/dev/rmt/${d}" status mt -f "/dev/rmt/${d}" status
done done
### 2: Rewinds the tape ### ### 2: Rewinds the tape ###
mt rew mt rew
mt rewind mt rewind
mt -f /dev/mt/0 rewind mt -f /dev/mt/0 rewind
mt -f /dev/st0 rewind mt -f /dev/st0 rewind
### 3: Eject the tape ### ### 3: Eject the tape ###
mt off mt off
@ -132,27 +134,27 @@ You can use shell loop as follows to poll a system and locate all of its tape dr
mt eject mt eject
mt -f /dev/mt/0 off mt -f /dev/mt/0 off
mt -f /dev/st0 eject mt -f /dev/st0 eject
### 4: Erase the tape (rewind the tape and, if applicable, unload the tape) ### ### 4: Erase the tape (rewind the tape and, if applicable, unload the tape) ###
mt erase mt erase
mt -f /dev/st0 erase #Linux mt -f /dev/st0 erase #Linux
mt -f /dev/rmt/0 erase #Unix mt -f /dev/rmt/0 erase #Unix
### 5: Retensioning a magnetic tape cartridge ### ### 5: Retensioning a magnetic tape cartridge ###
If errors occur when a tape is being read, you can retension the tape, clean the tape drive, and then try again as follows: If errors occur when a tape is being read, you can retension the tape, clean the tape drive, and then try again as follows:
mt retension mt retension
mt -f /dev/rmt/1 retension #Unix mt -f /dev/rmt/1 retension #Unix
mt -f /dev/st0 retension #Linux mt -f /dev/st0 retension #Linux
### 6: Writes n EOF marks in the current position of tape ### ### 6: Writes n EOF marks in the current position of tape ###
mt eof mt eof
mt weof mt weof
mt -f /dev/st0 eof mt -f /dev/st0 eof
### 7: Forward space count files i.e. jumps n EOF marks ### ### 7: Forward space count files i.e. jumps n EOF marks ###
The tape is positioned on the first block of the next file i.e. tape will position on first block of the field (see fig.01): The tape is positioned on the first block of the next file i.e. tape will position on first block of the field (see fig.01):
@ -160,7 +162,7 @@ The tape is positioned on the first block of the next file i.e. tape will positi
mt fsf mt fsf
mt -f /dev/rmt/0 fsf mt -f /dev/rmt/0 fsf
mt -f /dev/rmt/1 fsf 1 #go 1 forward file/tape (see fig.01) mt -f /dev/rmt/1 fsf 1 #go 1 forward file/tape (see fig.01)
### 8: Backward space count files i.e. rewinds n EOF marks ### ### 8: Backward space count files i.e. rewinds n EOF marks ###
The tape is positioned on the first block of the next file i.e. tape positions after EOF mark (see fig.01): The tape is positioned on the first block of the next file i.e. tape positions after EOF mark (see fig.01):
@ -168,27 +170,27 @@ The tape is positioned on the first block of the next file i.e. tape positions a
mt bsf mt bsf
mt -f /dev/rmt/1 bsf mt -f /dev/rmt/1 bsf
mt -f /dev/rmt/1 bsf 1 #go 1 backward file/tape (see fig.01) mt -f /dev/rmt/1 bsf 1 #go 1 backward file/tape (see fig.01)
Here is a list of the tape position commands: Here is a list of the tape position commands:
fsf Forward space count files. The tape is positioned on the first block of the next file. fsf Forward space count files. The tape is positioned on the first block of the next file.
fsfm Forward space count files. The tape is positioned on the last block of the previous file. fsfm Forward space count files. The tape is positioned on the last block of the previous file.
bsf Backward space count files. The tape is positioned on the last block of the previous file. bsf Backward space count files. The tape is positioned on the last block of the previous file.
bsfm Backward space count files. The tape is positioned on the first block of the next file. bsfm Backward space count files. The tape is positioned on the first block of the next file.
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. 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.
fsr Forward space count records. fsr Forward space count records.
bsr Backward space count records. bsr Backward space count records.
fss (SCSI tapes) Forward space count setmarks. fss (SCSI tapes) Forward space count setmarks.
bss (SCSI tapes) Backward space count setmarks. bss (SCSI tapes) Backward space count setmarks.
### Basic backup commands ### ### Basic backup commands ###
Let us see commands to backup and restore files Let us see commands to backup and restore files
@ -197,31 +199,31 @@ Let us see commands to backup and restore files
tar cvf /dev/rmt/0n /etc tar cvf /dev/rmt/0n /etc
tar cvf /dev/st0 /etc tar cvf /dev/st0 /etc
### 10: To restore directory (tar format) ### ### 10: To restore directory (tar format) ###
tar xvf /dev/rmt/0n -C /path/to/restore tar xvf /dev/rmt/0n -C /path/to/restore
tar xvf /dev/st0 -C /tmp tar xvf /dev/st0 -C /tmp
### 11: List or check tape contents (tar format) ### ### 11: List or check tape contents (tar format) ###
mt -f /dev/st0 rewind; dd if=/dev/st0 of=- mt -f /dev/st0 rewind; dd if=/dev/st0 of=-
## tar format ## ## tar format ##
tar tvf {DEVICE} {Directory-FileName} tar tvf {DEVICE} {Directory-FileName}
tar tvf /dev/st0 tar tvf /dev/st0
tar tvf /dev/st0 desktop tar tvf /dev/st0 desktop
tar tvf /dev/rmt/0 foo > list.txt tar tvf /dev/rmt/0 foo > list.txt
### 12: Backup partition with dump or ufsdump ### ### 12: Backup partition with dump or ufsdump ###
## Unix backup c0t0d0s2 partition ## ## Unix backup c0t0d0s2 partition ##
ufsdump 0uf /dev/rmt/0 /dev/rdsk/c0t0d0s2 ufsdump 0uf /dev/rmt/0 /dev/rdsk/c0t0d0s2
## Linux backup /home partition ## ## Linux backup /home partition ##
dump 0uf /dev/nst0 /dev/sda5 dump 0uf /dev/nst0 /dev/sda5
dump 0uf /dev/nst0 /home dump 0uf /dev/nst0 /home
## FreeBSD backup /usr partition ## ## FreeBSD backup /usr partition ##
dump -0aL -b64 -f /dev/nsa0 /usr dump -0aL -b64 -f /dev/nsa0 /usr
@ -231,12 +233,12 @@ Let us see commands to backup and restore files
ufsrestore xf /dev/rmt/0 ufsrestore xf /dev/rmt/0
## Unix interactive restore ## ## Unix interactive restore ##
ufsrestore if /dev/rmt/0 ufsrestore if /dev/rmt/0
## Linux ## ## Linux ##
restore rf /dev/nst0 restore rf /dev/nst0
## Restore interactive from the 6th backup on the tape media ## ## Restore interactive from the 6th backup on the tape media ##
restore isf 6 /dev/nst0 restore isf 6 /dev/nst0
## FreeBSD restore ufsdump format ## ## FreeBSD restore ufsdump format ##
restore -i -f /dev/nsa0 restore -i -f /dev/nsa0
@ -244,10 +246,10 @@ Let us see commands to backup and restore files
## This will overwrite all data on tape ## ## This will overwrite all data on tape ##
mt -f /dev/st1 rewind mt -f /dev/st1 rewind
### Backup home ## ### Backup home ##
tar cvf /dev/st1 /home tar cvf /dev/st1 /home
## Offline and unload tape ## ## Offline and unload tape ##
mt -f /dev/st0 offline mt -f /dev/st0 offline
@ -256,28 +258,28 @@ To restore from the beginning of the tape:
mt -f /dev/st0 rewind mt -f /dev/st0 rewind
tar xvf /dev/st0 tar xvf /dev/st0
mt -f /dev/st0 offline mt -f /dev/st0 offline
### 14: Start writing after the last tar (see fig.02) ### ### 14: Start writing after the last tar (see fig.02) ###
## This will kee all data written so far ## ## This will kee all data written so far ##
mt -f /dev/st1 eom mt -f /dev/st1 eom
### Backup home ## ### Backup home ##
tar cvf /dev/st1 /home tar cvf /dev/st1 /home
## Unload ## ## Unload ##
mt -f /dev/st0 offline mt -f /dev/st0 offline
### 15: Start writing after tar number 2 (see fig.02) ### ### 15: Start writing after tar number 2 (see fig.02) ###
## To wrtite after tar number 2 (should be 2+1) ## To wrtite after tar number 2 (should be 2+1)
mt -f /dev/st0 asf 3 mt -f /dev/st0 asf 3
tar cvf /dev/st0 /usr tar cvf /dev/st0 /usr
## asf equivalent command done using fsf ## ## asf equivalent command done using fsf ##
mt -f /dev/sf0 rewind mt -f /dev/sf0 rewind
mt -f /dev/st0 fsf 2 mt -f /dev/st0 fsf 2
To restore tar from tar number 2: To restore tar from tar number 2:
mt -f /dev/st0 asf 3 mt -f /dev/st0 asf 3
@ -308,28 +310,28 @@ It is important that you do regular full system restorations and service testing
# Last updated on : Feb-2007 - Added support for excluding files / dirs. # Last updated on : Feb-2007 - Added support for excluding files / dirs.
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
LOGBASE=/root/backup/log LOGBASE=/root/backup/log
# Backup dirs; do not prefix / # Backup dirs; do not prefix /
BACKUP_ROOT_DIR="home sales" BACKUP_ROOT_DIR="home sales"
# Get todays day like Mon, Tue and so on # Get todays day like Mon, Tue and so on
NOW=$(date +"%a") NOW=$(date +"%a")
# Tape devie name # Tape devie name
TAPE="/dev/st0" TAPE="/dev/st0"
# Exclude file # Exclude file
TAR_ARGS="" TAR_ARGS=""
EXCLUDE_CONF=/root/.backup.exclude.conf EXCLUDE_CONF=/root/.backup.exclude.conf
# Backup Log file # Backup Log file
LOGFIILE=$LOGBASE/$NOW.backup.log LOGFIILE=$LOGBASE/$NOW.backup.log
# Path to binaries # Path to binaries
TAR=/bin/tar TAR=/bin/tar
MT=/bin/mt MT=/bin/mt
MKDIR=/bin/mkdir MKDIR=/bin/mkdir
# ------------------------------------------------------------------------ # ------------------------------------------------------------------------
# Excluding files when using tar # Excluding files when using tar
# Create a file called $EXCLUDE_CONF using a text editor # Create a file called $EXCLUDE_CONF using a text editor
@ -338,7 +340,7 @@ It is important that you do regular full system restorations and service testing
# home/vivek/*.cpp~ # home/vivek/*.cpp~
# ------------------------------------------------------------------------ # ------------------------------------------------------------------------
[ -f $EXCLUDE_CONF ] && TAR_ARGS="-X $EXCLUDE_CONF" [ -f $EXCLUDE_CONF ] && TAR_ARGS="-X $EXCLUDE_CONF"
#### Custom functions ##### #### Custom functions #####
# Make a full backup # Make a full backup
full_backup(){ full_backup(){
@ -349,7 +351,7 @@ It is important that you do regular full system restorations and service testing
$MT -f $TAPE offline $MT -f $TAPE offline
cd $old cd $old
} }
# Make a partial backup # Make a partial backup
partial_backup(){ partial_backup(){
local old=$(pwd) local old=$(pwd)
@ -359,7 +361,7 @@ It is important that you do regular full system restorations and service testing
$MT -f $TAPE offline $MT -f $TAPE offline
cd $old cd $old
} }
# Make sure all dirs exits # Make sure all dirs exits
verify_backup_dirs(){ verify_backup_dirs(){
local s=0 local s=0
@ -374,15 +376,15 @@ It is important that you do regular full system restorations and service testing
# if not; just die # if not; just die
[ $s -eq 1 ] && exit 1 [ $s -eq 1 ] && exit 1
} }
#### Main logic #### #### Main logic ####
# Make sure log dir exits # Make sure log dir exits
[ ! -d $LOGBASE ] && $MKDIR -p $LOGBASE [ ! -d $LOGBASE ] && $MKDIR -p $LOGBASE
# Verify dirs # Verify dirs
verify_backup_dirs verify_backup_dirs
# Okay let us start backup procedure # Okay let us start backup procedure
# If it is Monday make a full backup; # If it is Monday make a full backup;
# For Tue to Fri make a partial backup # For Tue to Fri make a partial backup
@ -392,7 +394,7 @@ It is important that you do regular full system restorations and service testing
Tue|Wed|Thu|Fri) partial_backup;; Tue|Wed|Thu|Fri) partial_backup;;
*) ;; *) ;;
esac > $LOGFIILE 2>&1 esac > $LOGFIILE 2>&1
### A note about third party backup utilities ### ### A note about third party backup utilities ###
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: 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:
@ -422,4 +424,4 @@ via: http://www.cyberciti.biz/hardware/unix-linux-basic-tape-management-commands
[3]:http://www.manpager.com/linux/man1/mtx.1.html [3]:http://www.manpager.com/linux/man1/mtx.1.html
[4]:http://www.manpager.com/linux/man1/tar.1.html [4]:http://www.manpager.com/linux/man1/tar.1.html
[5]:http://www.manpager.com/linux/man8/dump.8.html [5]:http://www.manpager.com/linux/man8/dump.8.html
[6]:http://www.manpager.com/linux/man8/restore.8.html [6]:http://www.manpager.com/linux/man8/restore.8.html