3

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 !

3 Answers 3

3

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

4
  • This is a nice idea, but you could end up with an insanely long arguments list. Which would then cause problems with the shell. Nov 9, 2011 at 23:31
  • What kind of problems/limitations ?
    – Bastien974
    Nov 17, 2011 at 19:41
  • 2
    ARG_MAX -- see here : snippets.dzone.com/posts/show/2803 Nov 17, 2011 at 20:09
  • This was perfect for me. I tried putting wild cards in the -T file list, and found out that didn't work. This solution worked like a charm! I don't know what the file limit would be though, so I'm checking out the link above this comment. (Edit: The above link is no longer available (snippets....))
    – RufusVS
    Nov 15, 2019 at 2:13
2

Have you try using --wildcards ?

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

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

1
  • 1
    I tried and looks like --wildcards only works for extraction, doesn't work with -cf
    – Bastien974
    Nov 7, 2011 at 14:25
1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .