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 !

Bastien974
  • 1,896
  • 12
  • 44
  • 62

3 Answers3

3

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

Bastien974
  • 1,896
  • 12
  • 44
  • 62
  • 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 09 '11 at 23:31
  • What kind of problems/limitations ? – Bastien974 Nov 17 '11 at 19:41
  • 2
    ARG_MAX -- see here : http://snippets.dzone.com/posts/show/2803 – Tom O'Connor Nov 17 '11 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 '19 at 02: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

ehogue
  • 243
  • 2
  • 8
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.

Colt
  • 2,029
  • 6
  • 21
  • 27
Foy
  • 11
  • 1