nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

backup using tape scripts

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 ...

Register free or login to your existing account and remove all advertisements.


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-26-2009, 10:35 PM
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; 11-27-2009 at 04:58 PM.
Reply With Quote
  #2 (permalink)  
Old 11-27-2009, 04:57 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Posts: 2,452
Thanks: 11
Thanked 189 Times in 139 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

What is a counter? Why you need counter?
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 11-27-2009, 09:29 PM
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

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.
Reply With Quote
Reply

Tags
backup , gnu/tar , tar , zip


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
backup using tape bennyhll Novell Suse / OpenSuse 1 11-27-2009 04:59 PM
Fedora Linux Tape Drive Device Name and Backup Commands madmacher Linux software 1 11-27-2008 11:57 PM
tar tape command example tom Getting started tutorials 0 06-05-2007 10:36 AM
UNIX list a backup tape contents chiku Getting started tutorials 0 04-27-2007 05:46 PM
Openbsd Howto backup data on tape - tutorial raj All about FreeBSD/OpenBSD/NetBSD 1 12-20-2006 02:44 AM


All times are GMT +5.5. The time now is 06:28 PM.


Powered by vBulletin® Version 3.8.4 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2009 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38