I wrote a backup script on my Debian 8 system which uses tar command with "--exclude-from" to exclude some files/dir.
This works great, but today I would like to exclude some files sharing the same path pattern, like /home/www-data/sites/<some_string>log.txt
or directories like /home/www-data/sites/<one_or_two_directories>/vendor
.
I tried to append /home/www-data/sites/*log.txt
into the file, but tar fails and outputs on stderr the following errors:
tar: /home/www-data/sites/*log.txt: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
Did I miss something when trying to use *
or **
?
I then read that in Unix, programs usually do not interpret wildcards themselves which means that *
isn't expanded neither **
by tar.
As far as I know, my last resort here is to expand the list using bash and append it into the exclusion file (if it's not already there) prior to the tar
call. Is there a cleaner way?
EDIT
Here is the script snippet ..
# ...
broot=$(dirname "${PWD}")
i="${PWD}/list.include"
x="${PWD}/list.exclude"
o="$broot/archive.tgz"
tar -zpcf $o -T $i -X $x
# ...
Here is the exclusion file ..
/etc/php5/fpm
/etc/nginx
/etc/mysql
/home/me/websites/*log.txt
/home/me/websites/**/vendor
The goal is to exclude all log files located inside "websites" directory and all "vendor" directories that could be found within any sub-directories of "websites".
**
?