LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   tar excluding some files (https://www.linuxquestions.org/questions/linux-newbie-8/tar-excluding-some-files-813496/)

infraquest 06-11-2010 02:03 AM

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

druuna 06-11-2010 02:35 AM

Hi,

Untested:

tar -hcvzf testing.tar.gz /home/test1 /home/test2 --exclude /home/test2/*.jpg

Hope this helps.

infraquest 06-11-2010 04:25 AM

Hi druuna,

That works! never thought of giving full path :).
Thanks many

druuna 06-11-2010 04:26 AM

You're welcome :)

Could you mark this as solved (see thread tools).

infraquest 06-11-2010 05:33 AM

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

druuna 06-11-2010 06:01 AM

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.

infraquest 06-11-2010 06:22 AM

Thanks druuna,
yes I used --exclude-from option to exclude the jpg files recursively and got around this.
I'll close the thread.

Regards,

druuna 06-11-2010 06:35 AM

You're welcome :)


All times are GMT -5. The time now is 02:33 AM.