当前位置: 首页 > 工具软件 > Tape > 使用案例 >

LINUX下查看tape library信息

穆正青
2023-12-01
一、LINUX下查看tape library信息
pwd
/sys/class/scsi_tape/nst0/stats	

[root@linux stats]# ls -l
total 0
-r--r--r-- 1 root root 4096 Jan 21 09:51 in_flight
-r--r--r-- 1 root root 4096 Jan 21 09:51 io_ns
-r--r--r-- 1 root root 4096 Jan 21 09:51 other_cnt
-r--r--r-- 1 root root 4096 Jan 21 09:51 read_byte_cnt
-r--r--r-- 1 root root 4096 Jan 21 09:51 read_cnt
-r--r--r-- 1 root root 4096 Jan 21 09:51 read_ns
-r--r--r-- 1 root root 4096 Jan 21 09:51 resid_cnt
-r--r--r-- 1 root root 4096 Jan 21 09:51 write_byte_cnt
-r--r--r-- 1 root root 4096 Jan 21 09:51 write_cnt
-r--r--r-- 1 root root 4096 Jan 21 09:51 write_ns

[root@linux stats]# tapestat -z 1
Linux 3.10.0-514.el7.x86_64 (CV-X86BACKUP) 	01/21/2020 	_x86_64_	(56 CPU)

Tape:    r/s     w/s   kB_read/s   kB_wrtn/s %Rd %Wr %Oa    Rs/s    Ot/s
st0        0       0          35           0   0   0   0       0       0
st1        0       0          26           0   0   0   0       0       0

[root@linux stats]# lsscsi -g
[0:0:0:0]    storage HP       P840ar           6.60  -          /dev/sg0 
[0:1:0:0]    disk    HP       LOGICAL VOLUME   6.60  /dev/sda   /dev/sg1 
[0:1:0:1]    disk    HP       LOGICAL VOLUME   6.60  /dev/sdb   /dev/sg2 
[1:0:0:0]    tape    IBM      ULT3580-TD5      BBNF  /dev/st0   /dev/sg3 
[1:0:0:1]    tape    IBM      ULT3580-TD5      BBNF  /dev/st1   /dev/sg4 
[1:0:2:0]    tape    IBM      ULT3580-TD5      D2A0  /dev/st2   /dev/sg5 
[1:0:2:1]    mediumx IBM      03584L32         C260  /dev/sch0  /dev/sg6 
[1:0:3:0]    tape    IBM      ULT3580-TD5      D2A0  /dev/st3   /dev/sg7 
[1:0:4:0]    tape    IBM      ULT3580-TD5      D2A0  /dev/st4   /dev/sg8 
[1:0:5:0]    tape    IBM      ULT3580-TD5      D2A0  /dev/st5   /dev/sg9 
[1:0:6:0]    tape    IBM      ULT3580-TD5      D2A0  /dev/st6   /dev/sg10
[1:0:9:0]    tape    IBM      ULT3580-TD5      D2A0  /dev/st7   /dev/sg11


[root@CV-X86BACKUP stats]# tapeinfo -f /dev/sg10
Product Type: Tape Drive
Vendor ID: 'IBM     '
Product ID: 'ULT3580-TD5     '
Revision: 'D2A0'
Attached Changer API: No
SerialNumber: '00078ADB90'
MinBlock: 1
MaxBlock: 8388608
SCSI ID: 6
SCSI LUN: 0
Ready: no

--可以得到当前磁带的使用量,磁带的总量减去使用量就是剩余量了啊
tar tvf /dev/rmt0 | awk ' { total+=total } END { print total/1024/1024 } 


--安装mt命令
yum install -y mt-st
二、异地备份中使用driver
异地备份中可以使用的磁带机
for i in `seq 1 11`;
do 
tapeinfo -f /dev/sg$i  | grep "SerialNumber"; 
echo sg$i;
done

SerialNumber: '00078A2B8E'  /dev/st4   /dev/sg8   <---即st2/st4可以用在异地备份里
SerialNumber: '00078A2B99'  /dev/st2   /dev/sg5
三、mt命令使用手则
mt命令使用手则
The mt command provides several features that can query and control the tape drives including:

Rewind tape drive:
    # mt -f /dev/st0 rewind

Backup directory /etc with tar command (with z compression):
    # tar -czf /dev/st0 /etc

Display list of all files on tape:
    # tar -tzf /dev/st0

Restore /etc directory:
    # cd /
    # mt -f /dev/st0 rewind
    # tar -xzf /dev/st0 etc

Unload the tape:
    # mt -f /dev/st0  offline

status information about the tape :
    # mt -f /dev/st0   status

Erase the tape:
    # mt -f /dev/st0 erase

Go to end of data:
    # mt -f /dev/nst0 eod

Goto previous record:
    # mt -f /dev/nst0  bsfm 1

Forward record:
    # mt -f /dev/nst0  fsf 1

Restore /home from tape in case of data loss or hard disk failure:
    # tar -xlpMzvf /dev/st0 /home

More commands can be found on the mt man page:
   # man mt
五、备份脚本示例
#!/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.
# Last updated on : Feb-2020 - Added log file support.
# Last updated on : Feb-2020 - Added support for excluding files / dirs.
# -------------------------------------------------------------------------
LOGBASE=/relaydat/tar_scripts/logs
 
# Backup root dirs; do not prefix /
BACKUP_ROOT_DIR="/relaydat"

# Backup dirs; do not prefix /
BACKUP_DIR="MonthDump"
#BACKUP_DIR="test"
 
# Get todays day like Mon, Tue and so on
NOW=$(date +"%Y%m%d%H%M%S")
NOW_MONTH=$(date +"%Y%m")
 
# Tape devie name
TAPE="/dev/IBMtape2n"
 
# Exclude file
#TAR_ARGS=""
#EXCLUDE_CONF=/relaydat/tar_scripts/.backup.exclude.conf

# Lock file for last month
LOCK_FILE_NAME=/relaydat/tar_scripts/logs/tar_sucessess_$NOW_MONTH.loc
 
# Backup Log file
LOGFIILE=$LOGBASE/$NOW.backup.log
 
# Path to binaries
TAR=/usr/bin/tar
MT=/usr/bin/mt
MKDIR=/usr/bin/mkdir
 
# ------------------------------------------------------------------------
# Excluding files when using tar
# Create a file called $EXCLUDE_CONF using a text editor
# Add files matching patterns such as follows (regex allowed):
# home/vivek/iso
# home/vivek/*.cpp~
# ------------------------------------------------------------------------
[ -f $EXCLUDE_CONF ] && TAR_ARGS="-X $EXCLUDE_CONF"
 
#### Custom functions #####
# Make a full backup
full_backup(){
	local old=$(pwd)
	cd $BACKUP_ROOT_DIR
	echo "`date +"%Y%m%d%H%m%S"`:tar is starting"
	ls -l $BACKUP_ROOT_DIR/$BACKUP_DIR
	$MT -f $TAPE eod
	$TAR -cvf $TAPE $BACKUP_DIR || error_exit "Tar operation is error! Please check logfile"
	touch $LOGBASE/tar_sucessess_$NOW_MONTH.loc
#	$MT -f $TAPE offline
	cd $old
	echo  "`date +"%Y%m%d%H%m%S"`:tar is end!"
}
 
# Make a  partial backup
#partial_backup(){
#	local old=$(pwd)
#	cd /
#	$TAR $TAR_ARGS -cvpf $TAPE -N "$(date -d '1 day ago')" $BACKUP_ROOT_DIR
#	$MT -f $TAPE rewind
#	$MT -f $TAPE offline
#	cd $old
#}
 
# Make sure all dirs exits
verify_backup_dirs(){
	local s=0
	for d in $BACKUP_ROOT_DIR
	do
		if [ ! -d /$d ];
		then
			echo "Error : /$d directory does not exits!"
			s=1
		fi
	done
	# if not; just die
	[ $s -eq 1 ] && exit 1
}

check_tape(){
read -p "Have you prepared and checked tapes ?(yes or no): " name
if [[ $name = 'yes' ]]  || [[ $name = 'YES' ]]; then
        continue
else
        echo "Plase retry after check tapes "
        exit 1
fi
}

# Move and backup old directory ,created new backup directory
mv_backup_dir(){
if [ -f $LOCK_FILE_NAME ] && [ ! -z $BACKUP_DIR ] ;  then
		cd /$BACKUP_ROOT_DIR
		#echo "$BACKUP_ROOT_DIR/$BACKUP_DIR.bak"
		rm -rf $BACKUP_ROOT_DIR/$BACKUP_DIR.bak
		if [ -d $BACKUP_DIR ]; then
			mv $BACKUP_DIR $BACKUP_DIR.bak
			mkdir $BACKUP_DIR
		else 
			mkdir $BACKUP_DIR
		fi
	echo "`date +"%Y%m%d%H%m%S"`:Archived file have been backuped and source directory have been move!"
else
        echo "Please backup $NOW_MONTH archived data! "
        exit 1
fi
}


error_exit()
{
	echo "$1" 1>&2
	exit 1
}
 
#### Main logic ####
 
# Check the available state of the tape 
#check_tape 
#echo "tape is avialbe" 

# Make sure log dir exits
[ ! -d $LOGBASE ] && $MKDIR -p $LOGBASE
 
# Verify dirs
verify_backup_dirs 
 
# Okay let us start backup procedure
# If it is Monday make a full backup;
# For Tue to Fri make a partial backup
# Weekend no backups
full_backup >> $LOGFIILE 2>&1
#full_backup  

#move and backup old archived directory
mv_backup_dir >> $LOGFIILE 2>&1
#mv_backup_dir
 类似资料: