LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   tar backup Bash script help (http://www.linuxquestions.org/questions/linux-general-1/tar-backup-bash-script-help-764584/)

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.

Code:

#!/bin/bash

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

BUDIR=/home/oj/Documents/

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

fi

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

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

fi

if [ $? == 0 ]; then

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

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


fi

The error I get is

Code:

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

Try:
Code:

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


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

Quote:

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 08:45 AM.