Re: backup script directory errors fixed, now it can't find the eof



On 2008-08-29, JRough wrote:
I started over with a clean version of the redhat linux backup
script. I found out from "which" that I have tar in /bin/tar. I
don't have any more directory problems. I just put the script in the
root directory and it backs up /home.
I run the script and it finds a premature end of file on line 53?
The :command not founde 21,30,31 are just blank lines. Also on line
18,19, 20 it can't find the date command. If I type in one of the
commands for example date +%a on the command line I get the correct
result. Why is it not finding all these commands? Is it the syntax
error? What could be the syntax error?

Because the date command was not found, the variables $DOW, $DOM
and $DM are empty, and you forgot to quote those variables when you
used them in your tests.

---errors--
backup_new.txt: line 18: date: command not found
backup_new.txt: line 19: date: command not found
backup_new.txt: line 20: date: command not found
: command not founde 21:
: command not founde 30:
: command not founde 31:
backup_new.txt: line 53: syntax error near unexpected token `fi'

---script---
#!/bin/sh
# full and incremental backup script
# created 07 February 2000
# Based on a script by Daniel O'Callaghan <danny@xxxxxxxxxxx>
# and modified by Gerhard Mourani <gmourani@xxxxxxxxxxxx>

#Change the 5 variables below to fit your computer/backup

COMPUTER=sf6h31 # name of this
computer
DIRECTORIES="/home" # directoris to backup
BACKUPDIR=/backups # where to store the
backups
TIMEDIR=/backups/last-full # where to store time of
full backup
TAR=/bin/tar # name and
locaction of tar

#You should not have to change anything below here

PATH=/usr/local/bin:/usr/bin:/bin

It shouldn't matter in this script, but:

export PATH

DOW=`date +%a` # Day of the week e.g. Mon
DOM=`date +%d` # Date of the Month e.g. 27
DM=`date +%d%b` # Date and Month e.g. 27Sep

If the date changes between one invocation of date and the next,
you will have inconsistent dates. Use a singlke call to date
(which is also faster):

eval "$(date +'DOW=%a DOM=%d DM=%d%b' )"

However, I would recommend that you use the ISO date format:

eval "$(date +'DOW=%a DOM=%d DM=%d%b DATE=%Y-%m-%d' )"

# On the 1st of the month a permanet full backup is made
# Every Sunday a full backup is made - overwriting last Sundays backup
# The rest of the time an incremental backup is made. Each incremental
# backup overwrites last weeks incremental backup of the same name.
#
# if NEWER = "", then tar backs up all files in the directories
# otherwise it backs up files newer than the NEWER date. NEWER
# gets it date from the file written every Sunday.


# Monthly full backup
if [ $DOM = "01" ]; then

You have that backwards; in the shell, the variable needs quoting,
not the literal string:

if [ "$DOM" = 01 ]; then

NEWER=""
$TAR $NEWER -cf $BACKUPDIR/$COMPUTER-$DM.tar $DIRECTORIES
fi

# Weekly full backup
if [ $DOW = "Sun" ]; then
NEWER=""
NOW=`date +%d-%b`

# Update full backup date
echo $NOW > $TIMEDIR/$COMPUTER-full-date
$TAR $NEWER -cf $BACKUPDIR/$COMPUTER-$DOW.tar $DIRECTORIES

# Make incremental backup - overwrite last weeks
else

# Get date of last full backup
NEWER="--newer `cat $TIMEDIR/$COMPUTER-full-date`"
$TAR $NEWER -cf $BACKUPDIR/$COMPUTER-$DOW.tar $DIRECTORIES
fi


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
.



Relevant Pages

  • Re: file backup in windows
    ... I want my script to identigy the user ... logged in and go to the resp outlook folder or should be able to read ... operating system to try a few sample commands at the command line. ...
    (comp.lang.python)
  • Re: Need some small help on shell script - delete old files
    ... the grep are then sent to xargs to issue the rm command. ... gzip of $FILENAME at the end is not necessary as far as I can tell ...  Could this possibly be from this script? ... Also not sure why the qzip did not run on last night's backup. ...
    (comp.unix.shell)
  • Re: remote server backup script
    ... > Just type away at the command line. ... Make a backup of whatever you want ... > command line, in a script. ... >>the server ssh key on the clients machine). ...
    (comp.os.linux.misc)
  • Re: Need some small help on shell script - delete old files
    ... the grep are then sent to xargs to issue the rm command. ... gzip of $FILENAME at the end is not necessary as far as I can tell ... I am running the script and have noticed that the file names have been ... here is a list of the files in the backup directory: ...
    (comp.unix.shell)
  • Re: how get the script to run the first time and create the files it is looking for, or other error
    ... "# name and location of tar". ... This is a very sloppy and weak script. ... it's not the backup method that counts, ... # The rest of the time an incremental backup is made. ...
    (comp.unix.shell)