[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trouble with tar



Hi Ray,

  Are you running the script in cron as the same user ? It does sounds like a permissions issue, or problem perhaps with an $ENV variable .

One suggestion , within your script add these lines : 
LOGNAME="/var/log/MGBackup.log" 

Then, on the scripts tar command, just pipe it to tee and apeend, like this : 

tar -pszcvf /MapGuideBackup/$FILE$DATE$EXT /usr/local/mapguideopensource | tee -a $LOGNAME 

(Might also want to run the rm statement like this too...) 

The backticks `` inside your if statement are deprecated, and on the DATE variable,  I'd replace those with $() and see if it makes a different, (you might not be getting all of the files you think you are fed into the tar cmd) 

Let cron run it, and check your log... 

Why on earth are you doing a "sh" within your crontab and from the command line ? (Your script;s first line is bash shell, sh = bourne shell??) Just make the script file executable for the user who's supposed to run it , and run it in crontab like this : 

30 17 * * * /MapGuideBackup/MGBackup.sh

--
#!/usr/bin/rh stop

---- Ray Holtz <ray@rayholtz.com> wrote: 

=============
Hello, I have a script to tar up a directory that works fine when I run 
it as sudo.  When it runs in crontab it quits VERY early, and I only get 
an 8MB tar.gz file, instead of 320MB when I manually run it.

Here is the script:
#!/bin/bash
# This script makes a tar.gz file of the entire
# /usr/local/mapguideopensource directory.
# It then deletes the oldest tar.gz file.

FILE="MapGuideBackup-"
DATE=`/bin/date +%Y%m%d-%H%M`
EXT=".tar.gz"
BACKUPS="7"

if [ `ls -tr /MapGuideBackup/$FILE* | wc -l` -ge $BACKUPS ]
         then
         rm -f `ls -tr /MapGuideBackup/$FILE* | head -n 1`
fi

tar -pszcvf /MapGuideBackup/$FILE$DATE$EXT /usr/local/mapguideopensource

When I run that script with:

sudo sh ./MGBackup.sh

it runs fine and makes a 320MB tar.gz file that I can run
tar tvf filename.tar.gz and it scrolls through all the files.
When crontab runs the script with:

30 17 * * * root sh /MapGuideBackup/MGBackup.sh

it is only 8MB and when I run tar tvf filename.tar.gz on it, it only 
shows 15 lines then exits with:

tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now

Can someone see what I'm doing wrong?  I'm sure it will be very obvious 
to another set of eyes.  I'd like to get this working to provide backups 
of the mapguide application I'm working on for this client.

I have ruled out timing issues.  I've run it at 10am, 5:30pm and 10pm 
and the result is the same.

Thanks,
Ray

-- 
Linux Users Of Northern Illinois - Technical Discussion 
http://luni.org/mailman/listinfo/luni


-
To unsubscribe, send email to majordomo@silug.org with
"unsubscribe silug-discuss" in the body.


-
To unsubscribe, send email to majordomo@silug.org with
"unsubscribe silug-discuss" in the body.