PIPE find results to tar not behaving as expected.
Ok, I feel like a newbie on this question but;
I am trying to pipe a find command to 'tar -cvf' to create a tar archive. I have tried all the techniques that I can find or think of and this is what's happening.
I have a data directory that I would like to backup files that are older than 365days using tar and then delete the files from the data directory. There are some directories in the path that I want to exclude from the backup. And yes, I know there is other methods of doing this; but right now I am very curious as to why the below method is not working.
The results that I am getting.
# This works as expected: Tar archive only contains files&folders older than 365days.
find /path-example/ -mtime +365 | xargs tar -cvf /backup-dir/example.tar
# This command creates a tar archive with EVERYTHING in /path-example/
# seems to ignore my options.
find /path-example/ -name "*DIR_TO_EXCLUDE*" -prune -o -mtime +365 | xargs tar -cvf /backup-dir/example.tar
# I have also tried to exclude with tar,
find /path-example/ -mtime +365 | xargs -iXXX tar -cvf /backup-dir/example.tar XXX --exlcude="*DIR_TO_EXCLUDE/*"
# and it's still backing up everything in /path-example/
# however the find command returns what I expect to stdout when I run just the find command
find /path-example/ -name "*DIR_TO_EXCLUDE*" -prune -o -mtime +365
Is this a bug? or is this expected results and I am just missing something?
either way it's sure bugging the heck out of me :)
I am using:
CentOS release 5.4 (Final)
2.6.18-164.6.1.el5 #1 SMP Tue Nov 3 16:18:27 EST 2009 i686 i686 i386 GNU/Linux
Check out the -path option and combine with -prune. Also remember, as I recently found out, that you also need to include a -print option once you have it all in place.
If you still get stuck, come back and I will give an example.
In addition to what grail suggested, I would consider the --no-recursion option of tar. The find command will print out the directories and their content separately, so that the tar command will archive the directory descending into it recursively AND the files. Since a tar archive is a stream of files, they will actually be stored twice (or more) even if upon extraction they will be overwritten and placed into the same location.
Maybe this is what you're looking for:
remove leading directory information
I was at it for hours... my issue? I called it, well many things... /logs, /logs/, logs/ ./logs, ./logs/, /home/logs, /home/logs/.
colucix's --no-recursion is necessary to allow the right hand side to function properly.
Similarly, -wholename "/home/logs", and grail's -path "/home/logs" work as well... Note: not "/home/logs/" or even "./logs"
|All times are GMT -5. The time now is 08:54 AM.|