-   Linux - General (
-   -   tar backup Bash script help (

speedhunt3r 10-26-2009 12:37 PM

tar backup Bash script help
Guys I need help finding out why my backup script is not working as it should. The problem exists in the second if statement, and the second problem is in the differential backup line itself.



OUTPUT=/home/oj/Desktop/backup_$(date +%Y%m%d).tar.gz


LOGFILE=/home/oj/Desktop/backup_$(date +%Y%m%d).log

exec > $LOGFILE 2>&1

echo "Starting backup of $BUDIR to file $OUTPUT"

if [ `date +%w` -eq 4 ] ; then
tar -cvzpf $OUTPUT $BUDIR


if [ `date +%w` -gt 0 ] && [ `date +%w` -lt 4 ]; then

test -f $OUTPUT && find $BUDIR -type f -newer $OUTPUT | tar --null -czvf $OUTPUT -T-


if [ $? == 0 ]; then

mail -s "Backup successful for $OUTPUT" oj < $LOGFILE

mail -s "Backup failed for $OUTPUT" oj < $LOGFILE


The error I get is


Starting backup of /home/oj/Documents/ to file /home/oj/Desktop/backup_20091027.tar.gz
tar: Removing leading `/' from member names
tar: /home/oj/Documents/backup\n: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors

If I hash out the first if statement along with the tar line and the second if statement, in other words, just let the differential backup run, I get the same error as above.

Whats the problem? I'm new at this...

Tux-Slack 10-26-2009 12:52 PM


DATE=`date +%Y%m%d`

speedhunt3r 10-27-2009 01:01 AM

That didn't help much, It stopped labelling the log file correctly.

Something's wrong with the syntax of the differential backup line, can someone please advise me?

chrism01 10-27-2009 01:59 AM


tar: /home/oj/Documents/backup\n: Cannot stat: No such file or directory
This line implies a dir name ending in a newline char (\n) ; not good.

speedhunt3r 10-27-2009 03:08 AM

I was missing the -print0

All times are GMT -5. The time now is 01:26 PM.