Excluding a list of files from tar with spaces in filenames
Shlomi Fish
shlomif at iglu.org.il
Fri Feb 5 13:44:29 IST 2010
On Thursday 04 Feb 2010 21:48:46 Baruch Siach wrote:
> Hi Dotan,
>
> On Thu, Feb 04, 2010 at 09:12:54PM +0200, Dotan Cohen wrote:
> > I hope there is a bash guru out there today. I need to script a backup
> > plan which has a list of directories that should not be backed up.
> > Some of these directories have spaces in their filenames. The
> > following script works so long as there are no directories with spaces
> > in DONT_COPY, however, I cannot figure out what to do to get it to
> > work _with_ spaces in filenames:
> >
> > #!/bin/bash
> >
> > DONT_COPY="
> > .adobe/
> > File with Spaces
> > .bin/google-earth
> > Yet Another Annoying Filename
> > "
> >
> > DONT_COPY_LIST=""
> > for pattern in $DONT_COPY ; do DONT_COPY_LIST="$DONT_COPY_LIST
> > --exclude=$pattern "; done
> > tar -zcvf - * $DONT_COPY_LIST
> >
> >
> > Any ideas? Thanks!
>
> How about:
>
> rm -f /tmp/excludes
> for pattern in $DONT_COPY ; do echo ${DONT_COPY} >> /tmp/excludes; done
This loop is wrong. You're looping over $DONT_COPY and echoing it entirely
times and again. Also may be you want «echo "$pattern"» instead of
«echo ${pattern}».
> tar -X /tmp/excludes -zcvf - *
>
Between the last two lines, one can maliciously temper with /tmp/excludes.
Please use more secure names.
Regards,
Shlomi Fish
> Note that this won't archive files with spaces in their file names.
>
> baruch
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
Interview with Ben Collins-Sussman - http://shlom.in/sussman
Deletionists delete Wikipedia articles that they consider lame.
Chuck Norris deletes deletionists whom he considers lame.
Please reply to list if it's a mailing list post - http://shlom.in/reply .
More information about the Linux-il
mailing list