+ Reply to Thread
Results 1 to 3 of 3

Thread: backup script

  1. #1
    Join Date
    Nov 2001
    Location
    Georgetown
    Posts
    12

    backup script

    I am back.
    Well this time, the task is to write a shell script do the backup on to a DLT tape (40G). But the problem is that my the directories are even bigger (this case, 2 DLT tapes are required). So what I do is list all the subdirectories in that directory recursively with their sizes so that the users can chose the total number of GB of files backed up to be less than 40 G.
    I entire script is as follows which is quite long and is not entirely mine,

    # weekly.backup

    # making a log file
    export log="/misc/csl1/temp/Unimanual1999.backup.txt"
    echo '' >> $log
    echo "# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #" >> $log
    echo '' >> $log
    echo "STARTING weekly.backup ... " >> $log
    echo '' >> $log
    date >> $log
    echo '' >> $log
    echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" >> $log

    echo -n "Welcome to the weekly backup. Press 'y' to begin .... : "

    echo "There is too much data on Unimanual1999 to put on to one tape, therefore,"
    echo "you will need two tapes to do the backup "
    echo ''
    echo "You will need to put roughly half of the data on each tape, and you will"
    echo "be asked to list the directories you would like to put on each tape."
    echo ''
    echo "Below is a list of directories within Unimaual1999 and their sizes in kilobytes."
    echo "This may take a moment..."
    echo ''
    du --max-depth=1 /misc/csl1/Unimanual1999 > /misc/csl1/temp/Unimanual1999.backup.txt
    echo ''

    Directories=""
    ShortDirectories=""
    let total=0
    continue="y"
    dircounter=0
    echo '' > /misc/csl1/temp/Unimanual1999.backup.txt
    while [ $continue != "n" ]; do
    echo ''
    more /misc/csl1/temp/Unimanual1999.backup.txt
    echo ''
    echo "Please select a directory that you would like to back up."
    echo "Copy and paste the line containing its size and name."
    echo ''
    echo -n ": "
    read size dir

    dirname=`basename $dir`
    shortdir=$dir

    echo ''

    let temptotal=$total+$size

    echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
    echo ''
    echo "DIRECTORIES:"
    echo ''
    let k=1
    until (($k > $dircounter)); do
    echo "$ShortDirectories[$k]"
    let k=$k+1
    done

    echo $shortdir

    echo ''
    echo "Total = $temptotal"
    let tempremain=40000000-$temptotal

    if (($tempremain < 0)); then
    echo ''
    echo "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
    echo "* *"
    echo " YOU HAVE EXCEEDED the space available by $tempremain. "
    echo "* *"
    echo "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"
    else
    echo "Available = $tempremain"
    fi
    echo ''
    echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
    echo ''
    echo -n "Are you sure that you would like to add $dir? (y/n): "
    read answer
    if [ $answer = "y" ]; then
    echo "$dirname" >> /misc/csl1/temp/Unimanual1999.backup.txt
    Directories=($Directories $dir)
    ShortDirectories=($ShortDirectories $shortdir)
    let total=$temptotal
    let remain=$tempremain
    let dircounter=$dircounter+1
    fi
    echo ''
    echo "You have approximately $remain kilobytes available."
    echo ''
    echo -n "Do you want to add another directory? (y/n): "
    read continue
    done

    echo ''
    echo "Please put in tape 1 for Unimanual1999"
    echo -n "When the "Tape in Use" light on the DLT drive has stopped flashing, press 'Enter'."
    read go

    echo "" >> $log
    echo "Starting Unimanual1999, tape 1" >> $log
    date >> $log

    mt -f /dev/st0 rewind
    tar cf - $ShortDirectories | /usr/bin/rsh chaos "buffer -t -o /dev/st0
    mt -f /dev/st0 rewind

    echo "" >> $log
    echo "$ShortDirectories" >> $log
    echo '' >> $log
    echo "were backed up from Unimanual1999 which currently contains the following:" >> $log

    echo '' >> $log
    echo "Unimanual1999" >> $log
    ls -l /misc/csl1/Unimanual1999 >> $log
    echo '' >> $log

    df /misc/csl1/Unimanual1999 >> $log
    echo ''
    df /misc/csl1/Unimanual1999
    echo ''
    echo "Please compare the \"Total bytes written\" that was returned from the backup with"
    echo "the number in the \"Used column above\". Please make sure that they are the same."
    echo "Please note that the size from the backup is in bytes, and the size listed"
    echo "immediately above is in kilobytes."
    echo ''

    echo "" >> $log
    echo "Finished backing up Unimanual1999, tape 1" >> $log
    date >> $log

    echo "Finished backing up Unimanual1999 tape 1" > /misc/csl1/temp/dont_remove_30.1_backup.txt
    echo "$ShortDirectories" >> /misc/csl1/temp/dont_remove_30.1_backup.txt
    date >> /misc/csl1/temp/dont_remove_30.1_backup.txt

    rm /misc/csl1/temp/morefile.30.txt

    echo '' >> $log
    echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" >> $log

    #--------------------------------------------------------> End of Script

    Upon execution I face the following problems,
    1. The directories are not listed for me to chose from, is there something wrong in this line,
    echo '' > /misc/csl1/temp/Unimanual1999.backup.txt
    more /misc/csl1/temp/Unimanual1999.backup.txt

    2.After I select some directory (since I know them, even though they are not displayed) the messages displayed are,
    Please select a directory that you would like to back up.
    Copy and paste the line containing its size and name.
    :

    (case 1# If I enter nothing, then I get)
    basename: too few arguments
    Try `basename --help' for more information.
    BackupScript: let: temptotal=0+: syntax error: operand expected (error token is "+")

    (case 2# If I enter, then I get)
    Total =
    BackupScript: let: tempremain=40000000-: syntax error: operand expected (error token is "-")
    BackupScript: ((: < 0: syntax error: operand expected (error token is "< 0")
    Available =
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    DIRECTORIES:
    [1]
    Total = 0
    Available = 40000000

    3. Then I get a prompt,
    Are you sure that you would like to add ? (y/n): y
    BackupScript: let: total=: syntax error: operand expected (error token is "=")
    BackupScript: let: remain=: syntax error: operand expected (error token is "=")

    You have approximately kilobytes available.
    Do you want to add another directory? (y/n): n

    4. Finally,
    Please put in tape 1 for Unimanual1999
    When the Tape in Use light on the DLT drive has stopped flashing, press 'Enter'. (I press Enter)
    BackupScript: line 141: unexpected EOF while looking for matching `"'
    BackupScript: line 142: syntax error: unexpected end of file

    I am extremely sorry for giving you such a long footage, but since I am new to this, I would be most helpful if someone can help me debug codes.
    Thanks again in advance,
    ~ Nishant

  2. #2
    Join Date
    Mar 2000
    Location
    Elyria, Ohio - USA
    Posts
    2,075
    It would appear that you have placed an awful lot of responsibility for backups on the users. You might want to look into kbackup. Among other things, it can create compressed archives, which might cutdown your backup requirements to one tape. Take a look here. -mk

    ------------------
    If it ain't broke,
    Fix it till it is.
    If it ain't broke,
    Fix it till it is.

  3. #3
    Join Date
    Feb 2001
    Location
    Sydney, Australia
    Posts
    132
    You could also change "tar cf" to "tar zcf" to enable compression.

    [This message has been edited by Murmandamus (edited 12-03-2001).]

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts