tar excluding some files
I am working on a backup script and have to use tar with --exclude option somewhere in the script.
scenario: I need create a single tar ball with contents of two directories test1 and test2. In directory test1, all .jpg files needs to be excluded, but all the contents of another directory test2 (including .jpg files) has to be taken while tarring. A command like following excludes .jpg files in both test1 and test2 directories, but I need to exclude .jpg files only from /home/test2. tar -hcvzf testing.tar.gz /home/test1 --exclude *.jpg /home/test2 It would be great if someone could give some ideas. Thanks, Shan |
Hi,
Untested: tar -hcvzf testing.tar.gz /home/test1 /home/test2 --exclude /home/test2/*.jpg Hope this helps. |
Hi druuna,
That works! never thought of giving full path :). Thanks many |
You're welcome :)
Could you mark this as solved (see thread tools). |
Hi again druuna,
I need one more help here. >> tar -hcvzf testing.tar.gz /home/test1 /home/test2 --exclude /home/test2/*.jpg Command excludes all jpg files in the location /home/test2/, but I need all jpg files in sub directories under /home/test2/ to be excluded as well. how can I go about this? Thanks |
Hi,
Have a look at the -X (or --exclude-from=file) option (GNU Tar : 6.4 Excluding Some Files) All exclusions should be in a file (could be filled by using find, might need some editing). Hope this helps. |
Thanks druuna,
yes I used --exclude-from option to exclude the jpg files recursively and got around this. I'll close the thread. Regards, |
You're welcome :)
|
All times are GMT -5. The time now is 02:33 AM. |