Linux / UNIX Tech Support Forum
This is a discussion on backup using tape scripts within the Shell scripting forums, part of the Development/Scripting category; hi i need to make some scripts: 1) a script that will add an zip archive each week to a ...
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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; 11-27-2009 at 03:58 PM. |
| Sponsored Links | ||
|
|
|
||||
|
What is a counter? Why you need counter?
__________________
Vivek Gite Linux Evangelist |
|
|||
|
because, as i understood, if i want to recover a specific file, i have to go to the specific track were it was recorded.
Let's say: i have - file1.zip recorded at track 1 - file2.zip recorded to track 2 - file3.zip recorded at track 3. I want to restore only file2.zip. then i have to do a mt -f /dev/nst0 fsf 2 (go to track 2) and after that perform the restore with whatever i used (tar or dd, etc). So this is why i need the counter: to hold in a file the track number where i stored the file on the tape for future restore tasks. |
![]() |
| Tags |
| backup , gnu/tar , tar , zip |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| backup using tape | bennyhll | Novell Suse / OpenSuse | 1 | 11-27-2009 03:59 PM |
| Fedora Linux Tape Drive Device Name and Backup Commands | madmacher | Linux software | 1 | 11-27-2008 10:57 PM |
| tar tape command example | tom | Getting started tutorials | 0 | 06-05-2007 09:36 AM |
| UNIX list a backup tape contents | chiku | Getting started tutorials | 0 | 04-27-2007 04:46 PM |
| Openbsd Howto backup data on tape - tutorial | raj | All about FreeBSD/OpenBSD/NetBSD | 1 | 12-20-2006 01:44 AM |