LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 10-26-2009, 01:37 PM   #1
speedhunt3r
LQ Newbie
 
Registered: Apr 2009
Posts: 13

Rep: Reputation: 0
Unhappy 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...
 
Old 10-26-2009, 01:52 PM   #2
Tux-Slack
Member
 
Registered: Nov 2006
Location: Slovenia
Distribution: Slackware 13.37
Posts: 511

Rep: Reputation: 36
Try:
Code:
DATE=`date +%Y%m%d`
OUTPUT=/home/oj/Desktop/backup_$DATE.tar.gz
 
Old 10-27-2009, 02:01 AM   #3
speedhunt3r
LQ Newbie
 
Registered: Apr 2009
Posts: 13

Original Poster
Rep: Reputation: 0
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?

Last edited by speedhunt3r; 10-27-2009 at 02:46 AM. Reason: error clarification
 
Old 10-27-2009, 02:59 AM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,311

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
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.
 
Old 10-27-2009, 04:08 AM   #5
speedhunt3r
LQ Newbie
 
Registered: Apr 2009
Posts: 13

Original Poster
Rep: Reputation: 0
I was missing the -print0
 
  


Reply

Tags
backup, bash, if, tar


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
script that shows progress in a tar backup kaplan71 Linux - Software 1 03-17-2009 04:44 PM
Bash backup script failing using tar and --newer option saldkj Programming 3 03-12-2005 01:03 PM
Incremental backup script - Tar problem joshheald Linux - Software 1 09-28-2004 11:02 AM
Basic backup script using Tar GraemeK Linux - General 1 09-17-2004 06:19 AM
Backup script to tar untoldone Programming 2 05-20-2004 04:03 PM


All times are GMT -5. The time now is 07:05 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration