[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Backup shell scripting program

Posted on 2004-10-21
3
Medium Priority
?
226 Views
Last Modified: 2010-05-18
Good afternoon gentlemen...I'm writing a backup shell script on Fedora Linux server. The purpose of the script is back-up weekly files to an internal tape drive. I have everything execpt when the tape is finished at the recording, I need to develop an if statement so that when it reaches the end of the tape it will eject the tape and send a message to the administrator that the tape has been ejected. I have a sample script below, but the if statement is the one I need help with, what do I use to specify the tape is at the end, is it 0. Script below


!#/bin/sh

File_st="/var/log"
tape_drive="/dev/sto"
cd $File_st
find . print | cpio -ovH crc -O /dev/nst0

if ( $tape_drive = ????)
then

eject $tape_drive
mail "tape is finished" > admin@localhost

else

mail "date% this weeks backup is complete" > admin@localhost


any modifications will be welcomed.
0
Comment
Question by:ritru
  • 2
3 Comments
 
LVL 38

Accepted Solution

by:
wesly_chen earned 1000 total points
ID: 12375939
Hi ritru,

  The line should change to
find . print | cpio -ovH crc -O /dev/nst0
===>  find . -name <filename> -print -exec cpio -ovH crc -O {} /dev/st0 \;

   If you just copy whatever under /var/log, then just use "cpio". No need for find command.

   Besides, you can check the status of cpio, if it fail, then you need to check the tape or the backup log.
Not just check whether tape full (if tape were full, then the cpio would error out, and the status will be 1:fail).

Regards,

Wesly
0
 

Author Comment

by:ritru
ID: 12382590
So what you saying is I can do an

if [$tape_drive == -1] then

eject $tape_drive
mail "tape has finished" > admin@localhost

else

cd $File_st
find . print | cpio -ovH crc -O /dev/nst0
mail "date% this weeks backup is complete" > admin@localhost

fi

This would resolve if the tape is full or not...One more question is that the correct command to prompt for the date or am I missing something.... My mail command is correct right?  Anyway thank you for time and patience.

0
 
LVL 38

Expert Comment

by:wesly_chen
ID: 12406183
Well,
the return status code is stored in $status.

So if you do
cpio -ovH crc -O /var/log /dev/st0
and cpio fails for any reason including "tape full".
Then the $status is set to "1" automically.
So it should be:
--------------------------
cpio -ovH crc -O $File_st /dev/st0

if [ $status == 1 ] then
mail "backup failed" > admin@localhost
else
mail "date% this weeks backup is complete" > admin@localhost
fi
----------------------------

Regards,

Wesly
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question