Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a backup script that has this syntax "tar -czvf backup.tar.gz -T filelist" In this filelist, I'm listing folder to backup, but I also need to backup every file that has a given extension like "*.jpeg"

The file name are changing everyday, that's why I need to use a wildcard but it's not accepted in a file list.

Is there a workaround to make this work ?

Thanks !

share|improve this question

Have you try using --wildcards ?

 tar -xf foo.tar -v --wildcards '*.c'

http://www.gnu.org/s/tar/manual/html_section/wildcards.html

share|improve this answer
1  
I tried and looks like --wildcards only works for extraction, doesn't work with -cf – Bastien974 Nov 7 '11 at 14:25
up vote 1 down vote accepted

The easiest solution I found is : tar -czvf backup.tar.gz $(cat filelist)

share|improve this answer
    
This is a nice idea, but you could end up with an insanely long arguments list. Which would then cause problems with the shell. – Tom O'Connor Nov 9 '11 at 23:31
    
What kind of problems/limitations ? – Bastien974 Nov 17 '11 at 19:41
2  
ARG_MAX -- see here : snippets.dzone.com/posts/show/2803 – Tom O'Connor Nov 17 '11 at 20:09

Create a filelist.template that contains the static folders to always backup and then copy it to filelist each time and add in all the .jpeg files. Something like:

cp filelist.template filelist
ls *.jpeg >> filelist
tar -czvf backup.tar.gz -T filelist

you could also use a find command instead of ls if you need *.jpeg from a variety of locations.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.