LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 03-25-2008, 03:44 PM   #1
3rods
Member
 
Registered: Mar 2008
Posts: 70

Rep: Reputation: 16
Question Backup Script Using tar - Error "file changed as we read it"


I was working on a script that would mount a shared folder from my XP box, tar the contents of the share and then unmount the share. If there are any errors, it should email me (I know this isn't handled properly yet, but it sorta works).

Tar keeps exiting with a 1 because of a "tar: file changed as we read it" error. Tar still completes the archive and it looks correct (haven't MD5'd it yet), but it screws my script up.

Am I doing something wrong or is CIFS screwing me up or what? I don't want to ignore errors from tar in my script, but I don't want false positive emails either.



The script below is very rough.


Code:
#/bin/bash

PROGNAME=$(basename $0)

function error_handle
{
        if [ "$?" = "0" ]; then

        echo $?

        else

        echo "${PROGNAME}: ${1:-"Unknown Error $LINENO "}" > /storage2/picture_backups/errorlog.txt

        /usr/sbin/sendemail -f XXXXXXXX@comcast.net -t backups@XXXXXX.com -u Backup Script Error `date +%Y_%m_%d_%H_%M` 
-s smtp.XXXXXXX.net -o message-file=/storage2/picture_backups/errorlog.txt

        exit 1


        fi
}

mount -t cifs -o username=USERNAME,password=PASSWORD,ro //192.168.1.131/Pictures/PICTURES /storage2/temp > /dev/null & EPID=$!

wait $EPID

error_handle

tar -czvf /storage2/picture_backups/backup-`date +%Y_%m_%d_%H_%M`.tar.gz /storage2/temp/ >/dev/null & EPID=$!

wait $EPID

error_handle

umount /storage2/temp

error_handle
Any help would be, well, helpful.

Thanks.
 
Old 03-26-2008, 09:47 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

The 'error' tar is giving you tells you that a file that is being tarred is changed. You are probably tarring files that are still open/written to. Depending on what is written to these file(s) you could see this as an error, most often it should be seen as informational (next backup the 'missed' data will be tarred).

BTW: It should be #!/bin/bash, not #/bin/bash.

Hope this helps.
 
Old 03-27-2008, 02:24 AM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,269

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
You should be doing a numerical comparison ie not

if [ "$?" = "0" ]; then

but

if [[ $? -eq 0 ]]
then

http://www.tldp.org/LDP/abs/html/comparison-ops.html

Last edited by chrism01; 03-27-2008 at 07:43 PM.
 
Old 03-27-2008, 01:43 PM   #4
3rods
Member
 
Registered: Mar 2008
Posts: 70

Original Poster
Rep: Reputation: 16
This is only my second shell script, so thanks for the help.

I still don't understand why/how the files are being changed. No person (or process) should be accessing the picture folder on the XP share. Is there a way to have tar suppress non-fatal messages so the script logic can proceed as planned?
 
Old 03-08-2014, 02:42 AM   #5
Ellyll
LQ Newbie
 
Registered: Jul 2004
Location: Wales
Distribution: Debian
Posts: 5

Rep: Reputation: 0
I know it's an old thread, but in case it's still useful to someone, you can also use --ignore-failed-read with tar if you get the "file was changed as we read it" problem.
 
Old 03-08-2014, 03:45 AM   #6
Ellyll
LQ Newbie
 
Registered: Jul 2004
Location: Wales
Distribution: Debian
Posts: 5

Rep: Reputation: 0
My mistake, it doesn't actually solve the problem I guess it means it only doesn't give an error for files it cant actually open for reading.
 
Old 03-08-2014, 05:18 AM   #7
Ellyll
LQ Newbie
 
Registered: Jul 2004
Location: Wales
Distribution: Debian
Posts: 5

Rep: Reputation: 0
It seems --ignore-failed-read worked for old versions of tar but the behaviour changed. Doesn't look like there's much you can do until you're on tar 1.27, in which case you might be able to do something with --warning=file-changed (sadly I only have 1.26 on my Debian 7 system so I've not tried it).
 
  


Reply


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
tar "Error exit delayed from previous errors" using "-C /" ToK Linux - Software 2 03-19-2008 06:49 AM
Backup Script error "line 31: syntax error: unexpected end of file" eswanepoel General 7 12-07-2007 09:28 AM
gdb error "Failed to read a valid object file image from memory." Fejimush Programming 0 03-11-2007 01:40 PM
perplexing "read-only file system" error Chomper Linux - General 1 11-16-2005 07:56 PM
tar command : error: file changed as we read it sneezesnoeze Linux - General 2 04-05-2004 06:56 PM


All times are GMT -5. The time now is 10:46 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
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration