Skip to main content
added 2623 characters in body
Source Link
Someone
  • 303
  • 1
  • 3
  • 15

Some quick bash-script with basic tape operations:

#!/bin/bash

export TAPE="/dev/nst0"
############################################
function anykey {
      read -n 1 -p "Press any key to continue..."
}

while true; do
clear
cat <<EOF
Choose action:

1. Show tape status
2. Show list of files of current block
3. Write new data (append tape)
4. Rewind tape (Set to BOT)
5. Wind tape (Set to EOD)
6. Set head to N blocks before
7. Set head to N blocks after
8. Extract data from current block
9. Erase tape

0. Exit
-----

EOF
read -p "Select action: " ans

case $ans in
    1).
      echo "====="; mt status ; echo "====="; anykey ;;
    2)
      echo "====="; tar tzv; echo "====="
      echo "Rewinding to the beginning of current block..."
      mt bsf 2; mt fsf
      echo "Done"; anykey ;;
    3).
      read -p "Select file or directory: " path
      cd $(dirname $path)
      if [ $? -ne 0 ]; then
          anykey
          continue
      fi..
      echo "Positioning to the end of written data..."
      mt eod; tar czv $(basename $path) -C $(dirname $path)
      echo "Done"; anykey ;;
    4).
      echo "Rewinding tape..."; mt rewind; echo "Done"; anykey ;;
    5).
      echo "Winding tape..."; mt eod; echo "Done"; anykey ;;
    6)
      read -p "Enter number of blocks before to set to: " ans
      mt bsf $(($ans+1)); mt fsf
      echo "Done"; anykey ;;
    7)
      read -p "Enter number of blocks after to set to: " ans
      mt fsf $ans; echo "Done"; anykey ;;
    8)
      read -p "Enter folder where to extract: " path
      cd $path
      if [ $? -ne 0 ]; then
          anykey
          continue
      fi
      read -p "Extract all data from this block? [Y|n]: " ans
      if [ $ans == "n" ]; then
          read -p "Enter file or dir name: " ans
          tar zxpv $ans
      else
          tar zxpv
      fi
      echo "Done"; anykey ;;
    9)
      echo "WARNING! Erasing will destroy ALL data on tape! Continue? [y|n]"; read ans
      if [ $ans == "y" ]; then
          echo "Rewinding tape..."; mt rewind;.
          echo "Erasing tape. This is quite long operation..."; mt erase; echo "Done"
      fi
      anykey ;;
    0) exit 0 ;;
    *) continue ;;
esac
done

Tape drive devices

Some quick bash-script with basic tape operations:

#!/bin/bash

export TAPE="/dev/nst0"
############################################
function anykey {
      read -n 1 -p "Press any key to continue..."
}

while true; do
clear
cat <<EOF
Choose action:

1. Show tape status
2. Show list of files of current block
3. Write new data (append tape)
4. Rewind tape (Set to BOT)
5. Wind tape (Set to EOD)
6. Set head to N blocks before
7. Set head to N blocks after
8. Extract data from current block
9. Erase tape

0. Exit
-----

EOF
read -p "Select action: " ans

case $ans in
    1).
      echo "====="; mt status ; echo "====="; anykey ;;
    2)
      echo "====="; tar tzv; echo "====="
      echo "Rewinding to the beginning of current block..."
      mt bsf 2; mt fsf
      echo "Done"; anykey ;;
    3).
      read -p "Select file or directory: " path
      cd $(dirname $path)
      if [ $? -ne 0 ]; then
          anykey
          continue
      fi..
      echo "Positioning to the end of written data..."
      mt eod; tar czv $(basename $path) -C $(dirname $path)
      echo "Done"; anykey ;;
    4).
      echo "Rewinding tape..."; mt rewind; echo "Done"; anykey ;;
    5).
      echo "Winding tape..."; mt eod; echo "Done"; anykey ;;
    6)
      read -p "Enter number of blocks before to set to: " ans
      mt bsf $(($ans+1)); mt fsf
      echo "Done"; anykey ;;
    7)
      read -p "Enter number of blocks after to set to: " ans
      mt fsf $ans; echo "Done"; anykey ;;
    8)
      read -p "Enter folder where to extract: " path
      cd $path
      if [ $? -ne 0 ]; then
          anykey
          continue
      fi
      read -p "Extract all data from this block? [Y|n]: " ans
      if [ $ans == "n" ]; then
          read -p "Enter file or dir name: " ans
          tar zxpv $ans
      else
          tar zxpv
      fi
      echo "Done"; anykey ;;
    9)
      echo "WARNING! Erasing will destroy ALL data on tape! Continue? [y|n]"; read ans
      if [ $ans == "y" ]; then
          echo "Rewinding tape..."; mt rewind;.
          echo "Erasing tape. This is quite long operation..."; mt erase; echo "Done"
      fi
      anykey ;;
    0) exit 0 ;;
    *) continue ;;
esac
done

Tape drive devices

Source Link
Someone
  • 303
  • 1
  • 3
  • 15

Some notes about tape backup. Maybe somebody finds it useful...

  1. Do not rewind tape after writing - use /dev/nst0 device (in case of linux)
  2. Set shell variable TAPE=/dev/nst0
  3. Set head to the beginnig of tape: mt rewind
  4. Set head to the end of written on tape data blocks: mt eod
  5. Get current tape postion: mt status and see File number and block number values
  6. Set tape head to the beginnig of previous block: mt bsf 2; mt fsf. Do not use to set head to the tape beginning - use rewind
  7. tar czv <dir_or_file> - write <dir_or_file> to tape
  8. tar tzv - get content of current block of data on tape (filelist).
  9. Sometimes errors occurs - use mt retension to reset soft errors

Tape drive devices