#!/bin/sh # Usage: autoimport.sh # Key points # Mixed libraries will require that the VTL contain the vcartridges of the desired cartridge type # The vcartridge is created if not present in the VTL, using the volume type associated with the first drive #set -x if [ $# -lt 3 ]; then echo "ERROR: Invalid number of arguments $#" echo "Usage: autoimport.sh " exit 1 fi export PATH="/quadstorvtl/bin:/quadstorvtl/quadstor/scctl:$PATH" maxjobs=2 force=1 while getopts "v:g:i:s:f:m:f:" opt; do case $opt in v) vtl="$OPTARG" ;; g) pool="$OPTARG" ;; i) libid="$OPTARG" ;; s) skipfile="$OPTARG" ;; f) includefile="$OPTARG" ;; m) maxjobs="$OPTARG" ;; f) force="$OPTARG" ;; esac done echo "VTL: $vtl Pool: $pool LibID: $libid MaxJobs: $maxjobs" if [ "$skipfile" != "" ]; then skiplist=`cat $skipfile` fi enabled=`ptconfig -l | grep "^${libid}" | grep -q Enabled` if [ "$?" != 0 ]; then #Enable the library echo "Enable library with LibID $libid" ptconfig -e 1 -i $libid fi #Rescan the library first echo "Rescan library with LibID $libid" ptconfig -r -i $libid echo "Sleeping 30 seconds..." sleep 30 vcartlist=`vcconfig -l -v $vtl | awk '{print $2}' | sed -n '1!p'` if [ "$includefile" != "" ]; then pcartlist=`cat $includefile` else pcartlist=`ptconfig -l -i $libid -b` fi j=0 checklist="" checkcount=0 wait_for_pending_jobs() { while [ $checkcount -ge $maxjobs ]; do tmplist="" for checkcart in $checklist; do check=`impexp -l | grep Imp | grep "In Progress" | grep $checkcart | wc -l` if [ "$check" -eq "1" ]; then if [ "$tmplist" = "" ]; then tmplist="$checkcart" else echo "$tmplist" | grep -q $checkcart if [ "$?" != "0" ]; then tmplist="$tmplist $checkcart" fi fi else comp=`impexp -l | grep Imp | grep "Completed" | grep $checkcart | wc -l` if [ "$comp" = "0" ]; then echo "Warn: Import for $checkcart did not complete successfully" else echo "Vaulting $checkcart" vcconfig -m -v $vtl -p $checkcart --vault let checkcount=checkcount-1 fi fi if [ "$checkcount" != "0" ]; then sleep 30 fi done checklist=$tmplist done } for pcart in $pcartlist; do found=0 skippcart=0 if [ "$skiplist" != "" ]; then for skip in $skiplist; do if [ "$vcart" = "$pcart" ]; then skippcart=1 break fi done fi if [ $skippcart -eq 1 ]; then continue fi for vcart in $vcartlist; do if [ "$vcart" = "$pcart" ]; then if [ "$force" = "1" ]; then echo "For label $pcart found vcartridge. Deleting vcartridge" vcconfig -x -v $vtl -p $vcart -x sleep 30 else echo "For label $pcart found vcartridge. Skipping creation" found=1 break fi fi done create="" if [ $found -eq 0 ]; then create=" -n" fi for i in `impexp -l | grep $pcart | cut -f 1 -d' '`;do echo "Deleting previous jobid $i for $pcart" impexp -r -j $i done while [ 1 ]; do impexp -v $vtl -p $pcart -g $pool -i $libid -e 0 -c 1 $create if [ "$?" = 1 ]; then echo "Received busy status for $pcart. Retrying after 2 minutes.." sleep 120 continue else echo "Started import for $pcart" if [ "$checklist" = "" ]; then checklist="$pcart" else checklist="$checklist $pcart" fi let checkcount=checkcount+1 break fi done let j=j+1 while [ $j -ge $maxjobs ]; do j=`impexp -l | awk '{print 2}' | grep Imp | grep "In Progress" | wc -l` if [ $j -ge $maxjobs ]; then echo "Waiting for running jobs to complete. Running jobs $j Max jobs $maxjobs" sleep 60 fi done wait_for_pending_jobs done maxjobs=0 wait_for_pending_jobs