[SOLVED] Script: Quick format all tapes in library

DocCyblade

New Member
Oct 23, 2022
7
5
3
Another one of my automations scripts I made. I needed a quick way to quick format all the tapes in the library with a certain prefix. I have a IBM 9 tape changer and had some tapes I wanted to re-use but they had data on them from another backup. So this script uses PBS commands proxmox-tape commands to do this.

I am doing an update that will instead of formatting based on label prefix, but will format ALL except an exclusion list, since this script is named format all. I will update this post when its been tested

Feel free to is this, if you do drop a comment so I know its being used.

Latest source
https://gist.github.com/DocCyblade/011c59e02986b09a90eddbc44d3db880

Bash:
#!/bin/bash

# --------------------------------------------------------------------------------
#     Copyright (C) 2022  Kenneth R. Robinson (DocCyblade)
#     https://github.com/doccyblade
# --------------------------------------------------------------------------------
#                                   GNU GPLv3
# --------------------------------------------------------------------------------
#     This program is free software: you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation, either version 3 of the License, or
#     (at your option) any later version.
#
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
#
#     You should have received a copy of the GNU General Public License
#     along with this program.  If not, see <https://www.gnu.org/licenses/>.


# format-all-tapes.sh
APA_VER=v2.1
#
# Change Log
#
# 1.0 - First release  (2022-10-23)
# 2.0 - Use PBS proxmox-tape commands instead of mt/mtx (2022-10-27)
#       This will show a task as well in the webGUI
# 2.1 - Add license
#
# Tested on PBS v2.2-7
#
# Source:
# https://gist.github.com/DocCyblade/011c59e02986b09a90eddbc44d3db880


# TODO Wish List:
# - Add help --help or ?
# - Add CLI prefix overide
# -
#

# Tape drive name in PBS to use
export PROXMOX_TAPE_DRIVE=IBM-LTO6


# Tape Prefix
export TAPE_PFX=SQ


# ---------- Do not change anything below --------------


# License/Copyright Notice
echo " ----------------------------------------------------------------------------"
echo "  Proxmox Backup Format All Tapes Script $APA_VER"
echo "  (`basename $0`) - Licnesed under GNU GPLv3"
echo " ----------------------------------------------------------------------------"
echo " | Copyright (C) 2022  Kenneth R. Robinson (https://github.com/doccyblade)  |"
echo " | This program comes with ABSOLUTELY NO WARRANTY; This is free software,   |"
echo " | and you are welcome to redistribute it under certain conditions          |"
echo " ----------------------------------------------------------------------------"
echo ""
sleep 2

echo ""
echo "======================================"
echo " Erase all tapes in libray script!"
echo "======================================"
echo ""
echo "Getting library status.."
proxmox-tape changer status
echo ""
echo ""

echo "This will format ALL Tapes below and also "
echo "remove them from the media pools!!!!!"
echo "-------------------------------"
echo ""
pmtx status | grep "VolumeTag(" | grep -o "$TAPE_PFX.*" | cut -b 1-8
echo ""
echo "-------------------------------"
echo ""
echo ""
read -r -p "Are You Sure? [Y/n] " input



case $input in
      [yY][eE][sS]|[yY])

      # Grab list
      TLIST=`pmtx status | grep "VolumeTag(" | grep -o "$TAPE_PFX.*" | cut -b 1-8`

      for i in $TLIST
      do
        echo ""
        echo " - - - = = = = [Formatting tape $i] = = = = - - - "
        echo ""

        # Load Tape
        echo "Loading tape $i"
        proxmox-tape load-media $i
        sleep 5
        echo "Waiting for drive to be ready"
        sleep 15
        echo "Tape $i loaded!"
        echo "- - -"
        echo ""

        # Quick format tape
        echo "Quick formatting tape, this will also remove it from media pool!"
        sleep 5
        proxmox-tape format --fast true
        echo "Quick format complete"
        echo "- - -"
        echo ""

        # Rewind and eject tape
        echo "Ejecting tape $i from drive"
        proxmox-tape eject
        sleep 10
        echo "Tape $i was ejected from drive"
        echo "- - -"
        echo ""
       # Done, move to next tape if any
        echo "Tape $i has been quick formatted"
        echo "moving on to next tape if there is one.."
        echo ""
        echo "- - - = = = = [Tape $i complete] = = = = - - -"
        echo ""
      done
      echo ""
      echo " All tapes have been formatted and removed from the media pools"
      echo ""

            ;;
      [nN][oO]|[nN])
            echo "Canceled! Nothing has been done"
            echo ""
            echo ""
            ;;
      *)
            echo "Invalid input..."
            echo "Canceled! Nothing has been done"
            echo ""
            echo ""
            exit 1
            ;;
esac
 
Last edited: