[Linux-Biella] tutils per tape DAT SCSI (lungo)
LeOS
linux@bilug.linux.it
Wed, 15 Jan 2003 10:16:55 +0100
LeOS wrote:
>
> COSA C'E' ancora da fare?
>
> il comando di restore
> ovvero
allora
stato fatto tutto quanto :)
il programma legge il tape, piglia il catalog, lo espande nella solita
directory
poi se lo va a parsare riga per riga visualizzando quello ke serve
nel codice di sotto, non avendo qui il DAT, ho remarkato tutte li righe
relative alle operazioni sul tape, ma a naso dovrebbe andare tutto
quanto, btw, potete dare un'occhiata voi stessi al funzionamento,
semplicemente nella home dell'utente che esegue il trestore create a
manina la solita dir "tutils" e dentro ci copiate il catalog di esempio
che avevo postato tempo fa.
questo vi dara' la possibilita' di giocare col programmino :)
buona vita a tutti, compreso lucabert ke mi ha copiato il saluto ma
adesso lo registro e mi faccio pafare le royalties!
PS: ecco uno scrinsciot ;)
============================
Tape "BaBau!" created on
Mon Dec 30 21:18:28 CET 2002
============================
First file:
| File: | Begin: | End: | Date:
| .bash_profile | 2 | 23 | Mon Dec 30 21:23:00 CET 2002
-------------------------------------------------------------
[p]revious file - [n]ext file - [r]estore file - e[x]it
[f]irst file - [l]ast file
-------------------------------------------------------------
Your choice: r
Restoring file: .bash_profile - Beginning Block: 2
Done!
il codice lo trovate qui di seguito:
# --- Create the temp dir in user home ---
if [ -e ~/tutils ] ; then
echo "Skipping Directory creation"
else
mkdir ~/tutils
fi
currentdir=$PWD
# --- Reach End Of Data on Tape ---
#mt-st -f /dev/tape eod
# --- Rewind the Tape to reach the begin of saved Catalog ---
#mt-st -f /dev/tape bsfm 3
# --- Restore the Catalog and view it ---
#cp /dev/tape ~/tutils
#tar xf ~/tutils/tape -C ~/tutils
cd ~/tutils
# --- Check the tape contents: if tape is just formatted, exit ---
lun=$(cat catalog |wc -l)
let lunnoheader=lun-6
if [ $lunnoheader -lt 6 ]; then
echo "The tape is empty..."
exit
fi
# --- funtions used, just to clean this dirty code ---
viewlist ()
{
clear
# --- print first 4 lines: header of the catalog ---
head -n 4 catalog
echo
filename=$(head -n $namepos catalog | tail -n 1)
begin=$(head -n $beginpos catalog | tail -n 1)
end=$(head -n $endpos catalog | tail -n 1)
ondate=$(head -n $datepos catalog | tail -n 1)
if [ $beginpos = 8 ]; then
let lastpos=lun-4
echo "First file:"
else
if [ $beginpos = $lastpos ]; then
echo "Last file:"
else
echo "Between First file and Last file ;)"
fi
fi
echo
begtemp=${begin##"At block "}
let diff=`expr length $begtemp`-1
begblock=`expr substr $begtemp 1 $diff`
endtemp=${end##"At block "}
let diff=`expr length $endtemp`-1
endblock=`expr substr $endtemp 1 $diff`
# --- Format the output ---
echo -n "| File:"
let difflen=`expr length $filename`-5
for ((counter=1 ; counter<=difflen ; counter++))
do
echo -n " "
done
echo -n " | Begin:"
let difflen=`expr length $begblock`-6
for ((counter=1 ; counter<=difflen ; counter++))
do
echo -n " "
done
echo -n " | End:"
let difflen=`expr length $endblock`-4
for ((counter=1 ; counter<=difflen ; counter++))
do
echo -n " "
done
echo -n " | Date:"
echo
echo -n "| "$filename
let difflen=5-`expr length $filename`
for ((counter=1 ; counter<=difflen ; counter++))
do
echo -n " "
done
echo -n " | "$begblock
let difflen=6-`expr length $begblock`
for ((counter=1 ; counter<=difflen ; counter++))
do
echo -n " "
done
echo -n " | "$endblock
let difflen=4-`expr length $endblock`
for ((counter=1 ; counter<=difflen ; counter++))
do
echo -n " "
done
echo " | "$ondate
echo
echo
echo "-------------------------------------------------------------"
echo "[p]revious file - [n]ext file - [r]estore file - e[x]it"
echo "[f]irst file - [l]ast file"
echo "-------------------------------------------------------------"
echo
echo -n "Your choice: "
}
debug ()
{
echo "| NamePOS: "$namepos" | | BeginPOS: "$beginpos" | | Lun:
"$lun" | | LunOK: "$lunok" |"
echo
}
# --- position of the first file name, after the header of the catalog ---
namepos=6
while [ "$action" != x ]
do
# --- in the catalog file lines change for filename, starting and
ending position and date ---
let beginpos=namepos+2
let endpos=namepos+4
let datepos=namepos+5
viewlist
read -n 1 action
echo
echo
if [ $action = p ] ; then
if [ $namepos -gt 6 ] ; then
let namepos=namepos-7
fi
fi
if [ $action = n ] ; then
let lunok=lun-7
if [ $namepos -lt $lunok ] ; then
let namepos=namepos+7
fi
fi
if [ $action = l ] ; then
let namepos=lun-6
fi
if [ $action = f ] ; then
let namepos=6
fi
if [ $action = r ] ; then
echo "Restoring file: $filename - Beginning Block: $begblock"
# --- routine di restore ---
# mt-st -f /dev/tape seek $begblock
# cp /dev/tape .
# tar xf tape
# cd $currentdir
# mkdir restored
# cd restored
# tar zxf ~/tutils/$filename
echo "Done!"
exit
fi
if [ $action = x ] ; then
echo
echo "Nothing done..."
cd $currentdir
exit
fi
if [ $action = q ] ; then
echo
echo "Nothing done..."
cd $currentdir
exit
fi
done
#cd $currentdir
# --- Clean temp dir ---
#rm -Rf ~/tutils