LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux > Linux - General
User Name
Password
Linux - General This 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

Tags used in this thread
Popular LQ Tags , , , , ,

Reply
 
Thread Tools
Old 10-26-2009, 01:37 PM   #1
speedhunt3r
LQ Newbie
 
Registered: Apr 2009
Posts: 13
Thanked: 0
Unhappy tar backup Bash script help


[Log in to get rid of this advertisement]
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...
linuxubuntu speedhunt3r is offline  
Tag This Post , , , , ,
Reply With Quote
Old 10-26-2009, 01:52 PM   #2
Tux-Slack
Member
 
Registered: Nov 2006
Location: Slovenia
Distribution: Slackware 12
Posts: 490
Thanked: 10
Try:
Code:
DATE=`date +%Y%m%d`
OUTPUT=/home/oj/Desktop/backup_$DATE.tar.gz
windows_xp_2003 Tux-Slack is offline     Reply With Quote
Old 10-27-2009, 02:01 AM   #3
speedhunt3r
LQ Newbie
 
Registered: Apr 2009
Posts: 13
Thanked: 0

Original Poster
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
linuxubuntu speedhunt3r is offline     Reply With Quote
Old 10-27-2009, 02:59 AM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 5.4
Posts: 7,411
Thanked: 324
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.
windows_xp_2003 chrism01 is offline     Reply With Quote
Old 10-27-2009, 04:08 AM   #5
speedhunt3r
LQ Newbie
 
Registered: Apr 2009
Posts: 13
Thanked: 0

Original Poster
I was missing the -print0
linuxubuntu speedhunt3r is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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 Off
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 12:11 AM.

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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration