View Single Post
  #1 (permalink)  
Old 26-11-2009, 09:35 PM
bennyhll bennyhll is offline
Junior Member
User
 
Join Date: Nov 2009
OS: openSuSE
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
bennyhll is on a distinguished road
Default backup using tape scripts

hi
i need to make some scripts:
1) a script that will add an zip archive each week to a tape.
2) a script that will tell when there is no room on the tape to put archives
3) a script that will search/extract a specific archive from that tape, when requested.

can you help me, please ? i'm quite a newbie on scripting. I tried 2 times for script no 1), but none of it seems to work right because when i try to extract, nothing is where it sould be or cannot be extracted. These are my scripts:

counter - is a file in my scripts directory where i store the backup track number on tape
mailul - is a file in my scripts directory where i store mail body to be sent

TRY no 1:

Code:
#!/bin/sh
#-- Declarare variabile----------------------------
data=`date +%d-%m-%Y`;
cale=/BACKUP;
src=/home/journaling/Maildir/cur
t=`cat counter`;
num_file=$data-$t

#-- Arhivare ------------------------------------
/usr/bin/zip -r -P password /BACKUP/$num_file.zip $src
count=0

#-- First time backup ----------------------------
if [ $t -eq 1 ]; then
            echo " S-a creat arhiva $num_file.zip " >> $cale/mailul;
            echo " Initializez primul backup pe banda " >>$cale/mailul;
            mt -f /dev/st0 tell;
            nice -19 dd if=$cale/$num_file.zip of=/dev/nst0;
            mt -f /dev/st0 weof 1;
            >counter;
            echo "1" >> counter;
            echo " In data `date +%d-%m-%y` ,ora `date +%T` backup created " >> $cale/mailul
#-- Next time backup ----------------------------
else
            mt -f /dev/nst0 eod;
            nice -19 dd if=$cale/$num_file.zip of=/dev/nst0;
            echo " In data `date +%d-%m-%y` ,ora `date +%T` backup $t created on tape " >> $cale/mailul
            (( t += 1 ));
            mt -f /dev/st0 weof $t;
            >counter;
            echo "$t" >> counter;
fi

#-- Send mail, create log -----------------------------------
cat $cale/mailul| mail mymail@mydomain -s "Journaling BACKUP"
cp $cale/mailul $cale/log-$num_file

#-- empty mail body ----------------------------------------
>mailul

TRY no. 2:


Code:
 #!/bin/sh
#-- Declarare variabile ------------------------------------------------
data=`date +%d-%m-%Y`;
cale=/BACKUP;
t=`cat counter`;

#-- Lock sa nu se suprapuna backup-urile ------------------------------
if [ -f /tmp/backup.lock ]; then
    echo "locked!"
    exit;
fi
date>/tmp/disk_to_tape.lock

#-- Arhivare-----------------------------------------------------
/usr/bin/zip -r -P password /BACKUP/$data.zip /home/costin
count=0

#-- Primul backup de pe banda -----------------------------------
if [ $t -eq 0 ]; then
        for f in $data;
            do  echo " S-a creat arhiva $data.zip " >> $cale/mailul;
                echo " Banda este goala, initializez primul backup " >>$cale/mailul;
                nice -19 tar cf /dev/nst0 /BACKUP/$data.zip;
                mt -f /dev/st0 weof 1;
                >counter;
                echo 1 >> counter;
            done
            if [ $count -eq 1 ]; then
echo " In data `date +%d-%m-%y` ,ora `date +%T` s-a realizat backup-ul si a fost mutat pe tape drive " >> $cale/mailul
            else
                >mailul;
                echo " Verifica banda, nu s-a efectuat backup-ul ! " >> $cale/mailul;
                echo " `date +%d-%m-%y` " >> $cale/mailul;
                echo " `date +%T` " >> $cale/mailul;
            fi

#-- Backup-uri adaugate pe banda ------------------------------------
else
        for f in $data;
            do echo $count >> $cale/mailul;
                echo "Adaug backup-ul $t pe banda existenta" >> $cale/mailul
                mt -f /dev/nst0 eom;
                nice -19 tar cf /dev/nst0 /BACKUP/$data.zip;
                (( t += 1 ));
                mt -f /dev/st0 weof $t;
                (( count += 1));
                >counter;
                echo "$t" >> counter;
            done
            if [ $count -eq 1 ]; then
echo " In data `date +%d-%m-%y` ,ora `date +%T` s-a realizat backup-ul si a fost mutat pe tape drive " >> $cale/mailul
            else
                >mailul;
                echo " Verifica banda, nu s-a efectuat backup-ul ! " >> $cale/mailul;
                echo " `date +%d-%m-%y` " >> $cale/mailul;
                echo " `date +%T` " >> $cale/mailul;
            fi
fi

#-- Remove lock, send mail, create log ----------------------------
rm -f /tmp/disk_to_tape.lock
cat $cale/mailul| mail mymail@mydomain -s "Journaling BACKUP"
cp $cale/mailul $cale/log-$data

#-- golire fisier de mail pentru urmatoarea operatie ---------------
>mailul

Last edited by nixcraft; 27-11-2009 at 03:58 PM.
Reply With Quote