LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   tar full path exclusive problem (https://www.linuxquestions.org/questions/linux-newbie-8/tar-full-path-exclusive-problem-933162/)

fantasy1215 03-07-2012 03:16 AM

tar full path exclusive problem
 
I use a bash script to tar backup my directory files. But I want the log directory to be excluded.
In my script:
CODE1
Code:

cbc_bindir="${HOME}/cbcbin";
tar -zcvf cbcbin.tar.gz  ${cbc_bindir}/* ${HOME}/.bashrc ${HOME}/.bash_profile  --exclude '${cbc_bindir}/log/*' --exclude '${cbc_bindir}/log'

But tar still include the log directory and all the log files to the tar bar.

If I change the code to:
CODE2
Code:

cbc_bindir="${HOME}/cbcbin";
cd ${cbc_bindir};
tar -zcvf cbcbin.tar.gz  ./* ${HOME}/.bashrc ${HOME}/.bash_profile  --exclude './log'

Can exclude the log directory and all the log files.

I wonder why CODE1 didn't work? I really want work like the way CODE1 does!

jv2112 03-07-2012 04:08 AM

:twocents:

Try moving the exlcude option before the source directories. I know when I use rsync the order is important or the exclusion does not happen.

Like this:
Code:


tar -zcvf cbcbin.tar.gz  --exclude './log' ./* ${HOME}/.bashrc ${HOME}/.bash_profile

Hope this helps.

lithos 03-07-2012 05:33 AM

Quote:

Originally Posted by fantasy1215 (Post 4620617)
I use a bash script to tar backup my directory files. But I want the log directory to be excluded.
In my script:
CODE1
Code:

cbc_bindir="${HOME}/cbcbin";
tar -zcvf cbcbin.tar.gz  ${cbc_bindir}/* ${HOME}/.bashrc ${HOME}/.bash_profile  --exclude '${cbc_bindir}/log/*' --exclude '${cbc_bindir}/log'

But tar still include the log directory and all the log files to the tar bar.

...

I wonder why CODE1 didn't work? I really want work like the way CODE1 does!


Hi,

could you try it with double quotes " instead of single '
... "${cbc_bindir}/log/*"


This is the difference at first quick test:
Code:

echo ""${cbc_bindir}/log/*""
/log/*

echo "'${cbc_bindir}/log/*'"
'/log/*'

good luck

fantasy1215 03-08-2012 12:06 AM

The problem is using ', If I use " instead ', it works!
Thanks you guys!

lithos 03-08-2012 01:39 AM

That is nice to have it working now.

Regards.


All times are GMT -5. The time now is 07:30 AM.