Solved

Backup shell scripting program

Posted on 2004-10-21
219 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
Question by:ritru
    3 Comments
     
    LVL 38

    Accepted Solution

    by:
    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
    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
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Course: JavaScript Coding - Massive 12-Part Bundle

    Regardless of your programming skill level, you'll go from basics to advanced concepts in a vast array of JavaScript subjects including Sammy.js, Agility.js, Ember.js, Node.js, jQuery, AJAX, Extjs, AngularJS, Knockout.js, and JSON.

    Suggested Solutions

    Title # Comments Views Activity
    Centos Boot Error 42 105
    understanding an rpm spec file 5 45
    whats a headless user in linux 3 84
    Identify Linux loader 67 143
    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 demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    877 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now