There's subj tape drive (LTO-2 tapes, SCSI connection) connected to Debian 8. And I can't understand if it can make "session" writes? And, if yes, how correctly it has to be done?

I mean, that I need to write somedir1 on tape once, then, after time, write somedir2 on same tape and tape device have to "append" somedir2 to already written data on tape. Something like multisessions writes on CD/DVD.

'Cause now I can't find a way to create any "sessions".

How I am writing:

mt -f /dev/st0 eod - setting tape to the end of data

tar -czf /dev/st0 /somedir1 - writing somedir1

mt -f /dev/st0 eod - setting tape to the end of data again (cause tape device rewinds tape)

tar -czf /dev/st0 /somedir2 - writing somedir2

mt -f /dev/st0 rewind - rewinding tape.

Then, when reading data with tar -tzf /dev/st0 it only lists somedir2, but not somedir1.

2 Answers 2


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

Some quick bash-script with basic tape operations:


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

while true; do
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

read -p "Select action: " ans

case $ans in
      echo "====="; mt status ; echo "====="; anykey ;;
      echo "====="; tar tzv; echo "====="
      echo "Rewinding to the beginning of current block..."
      mt bsf 2; mt fsf
      echo "Done"; anykey ;;
      read -p "Select file or directory: " path
      cd $(dirname $path)
      if [ $? -ne 0 ]; then
      echo "Positioning to the end of written data..."
      mt eod; tar czv $(basename $path) -C $(dirname $path)
      echo "Done"; anykey ;;
      echo "Rewinding tape..."; mt rewind; echo "Done"; anykey ;;
      echo "Winding tape..."; mt eod; echo "Done"; anykey ;;
      read -p "Enter number of blocks before to set to: " ans
      mt bsf $(($ans+1)); mt fsf
      echo "Done"; anykey ;;
      read -p "Enter number of blocks after to set to: " ans
      mt fsf $ans; echo "Done"; anykey ;;
      read -p "Enter folder where to extract: " path
      cd $path
      if [ $? -ne 0 ]; then
      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
          tar zxpv
      echo "Done"; anykey ;;
      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"
      anykey ;;
    0) exit 0 ;;
    *) continue ;;

Tape drive devices


You need to use /dev/nst0; /dev/st0 rewinds when the device is closed, /dev/nst0 doesn't. With your current workflow, you're always writing to the beginning of the tape...

You might also want to look into tape markers (see the mt documentation).

  • Thanks a lot. I'll try using /dev/nst0
    – Someone
    Nov 11, 2016 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.