I'm trying to create a backup script. I've managed to get this script working fine on a CentOS 6.7 machine and am now trying to get it working properly on Debian 7.
I am running into a problem I can't seem to solve with Google or any of the information found on this site. I'll try to explain my situation before getting into the problem.
On CentOS, I use the following command to find files that have been changed in the past 24 hours in $SOURCEDIR and use xargs to put only these files into $ARCHIVE. If no files are found a message pops up.
find $SOURCEDIR -mtime -1 -print | xargs -r tar rcvf $ARCHIVE || { echo "No files have been changed in the past 24 hours. Exiting script ..." ; exit 1; } I am aware that using tar rcvf can invoke the following error message:
You may not specify more than one '-Acdtrux' or '--test-label' option
This however, does not seem to happen on the CentOS machine. It does on the Debian machine, thus I've removed the r command from the tar command. The reason I've added this in the first place is because I want to avoid the archive being overwritten if find would return more than 100 results.
Now onto the actual problem. Whenever I run
find $SOURCEDIR -mtime -1 -print I get a list of the files that have been changed in $SOURCEDIR in the past 24 hours, as expected. However, whenever I run the complete command including the pipe symbol and the xargs command like this:
find $SOURCEDIR -mtime -1 -print | xargs -r tar cvf $ARCHIVE || { echo "No files have been changed in the past 24 hours. Exiting script ..." ; exit 1; } I actually see the find command print all files from $SOURCEDIR before I end up with an archive including all the files from $SOURCEDIR, and I do not understand why. Any help would be greatly appreciated.
find $SOURCEDIR -mtime -1 -printalso include.as one of the output?.included in the output of thefindcommand. The output includes the name of the$SOURCEDIRand all the files that have been changed in the past 24 hours.$SOURCEDIRdoesn't show up on CentOS? you just need to remove that before piping totar..$SOURCEDIRis the first result. I've edited the original post to include the fact that I get to see all files listed byfindwhen I run the full command.-type fargument if you only want it to print pathnames of files. Otherwise, it'll print directory pathnames, too.