I am using make
and tar
to backup. When executing makefile, tar command shows file changed as we read it
. In this case,
--ignore-failed-read
doesn't help. I am using tar 1.23 in MinGWHow can I stop the tar's warning to stop my backup following the warning?
Edit-2: it might be the reason
As I said above, the bash shell script worked well in my old computer. Comparing with the old computer, the msys
version is different. So is the version of tar command. In the old computer, tar is 1.13.19 and it is 1.23 in the new computer. I copied the old tar command without copying its dependency msys-1.0.dll to the new computer and renamed it tar_old. And I also updated the tar command in the shell script and run the script. Then everything is ok. So, it seemed that the problem is the tar command. I am sure that there is no any file changed when taring. Is it a bug for tar command in new version? I don't know.
Edit-1: add more details
The backup is invoked by a bash shell script. It scans the target directory and builds makefile then invokes make to use tar command for backup. Followed is a typical makefile built by the bash shell script.
#-------------------------------------------- # backup VC #-------------------------------------------- # the program for packing PACK_TOOL=tar # the option for packing tool PACK_OPTION=cjvf # M$: C driver WIN_C_DIR=c: # M$: D driver WIN_D_DIR=d: # M$: where the software is WIN_PRG_DIR=wuyu/tools # WIN_PRG_DIR= # where to save the backup files BAKDIR=/home/Wu.Y/MS_bak_MSYS VC_FRAMEWORK=/home/Wu.Y/MS_bak_MSYS/tools/VC/VC_framework.tar.bz2 VC_2010=/home/Wu.Y/MS_bak_MSYS/tools/VC/VC_2010.tar.bz2 .PHONY: all all: $(VC_FRAMEWORK) $(VC_2010) $(VC_FRAMEWORK): $(WIN_C_DIR)/$(WIN_PRG_DIR)/VC/Framework/* @$(PACK_TOOL) $(PACK_OPTION) "$@" --ignore-failed-read /c/$(WIN_PRG_DIR)/VC/Framework $(VC_2010): $(WIN_C_DIR)/$(WIN_PRG_DIR)/VC/VS2010/* @$(PACK_TOOL) $(PACK_OPTION) "$@" --ignore-failed-read /c/$(WIN_PRG_DIR)/VC/VS2010
As you can see, the tar package is stored in ~/MS_bak_MSYS/tools/VC/VC_2010.tar.bz2. I run the script in ~/qqaa. ~/MS_bak_MSYS
is excluded from tar command. So, the tar file I am creating is not inside a directory I am trying to put into tar file. This is why I felt it strange that the warning came up.
The tar command will never move or delete any of the original directories and files you feed it – it only makes archived copies. You should also note that using a dot (.)
By default it does not compress; however, it does compress the resulting archive with gzip (also by GNU) if you supply -z . The conventional suffix for gzipped files is . gz , so you'll often see tarballs (slang for a tar archive, usually implying it's been compressed) that end in . tar.
The most common uses of the tar command are to create and extract a tar archive. To extract an archive, use the tar -xf command followed by the archive name, and to create a new one use tar -czf followed by the archive name and the files and directories you want to add to the archive.
By default, tar will preserve file permissions and ownership when creating the archive. To extract file permissions and ownership, you will need to run tar as root when extracting, since changing file ownership usually requires superuser privileges. See this question for more information.
I also encounter the tar messages "changed as we read it". For me these message occurred when I was making tar file of Linux file system in bitbake build environment. This error was sporadic.
For me this was not due to creating tar file from the same directory. I am assuming there is actually some file overwritten or changed during tar file creation.
The message is a warning and it still creates the tar file. We can still suppress these warning message by setting option
--warning=no-file-changed
(http://www.gnu.org/software/tar/manual/html_section/warnings.html )
Still the exit code return by the tar is "1" in warning message case: http://www.gnu.org/software/tar/manual/html_section/Synopsis.html
So if we are calling the tar file from some function in scripts, we can handle the exit code something like this:
set +e tar -czf sample.tar.gz dir1 dir2 exitcode=$? if [ "$exitcode" != "1" ] && [ "$exitcode" != "0" ]; then exit $exitcode fi set -e
Although its very late but I recently had the same issue.
Issue is because dir .
is changing as xyz.tar.gz
is created after running the command. There are two solutions:
Solution 1: tar
will not mind if the archive is created in any directory inside .
. There can be reasons why can't create the archive outside the work space. Worked around it by creating a temporary directory for putting the archive as:
mkdir artefacts tar -zcvf artefacts/archive.tar.gz --exclude=./artefacts . echo $? 0
Solution 2: This one I like. create the archive file before running tar:
touch archive.tar.gz tar --exclude=archive.tar.gz -zcvf archive.tar.gz . echo $? 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With