LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-07-2012, 03:16 AM   #1
fantasy1215
Member
 
Registered: Oct 2011
Posts: 75

Rep: Reputation: Disabled
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!
 
Old 03-07-2012, 04:08 AM   #2
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Rep: Reputation: 103Reputation: 103
Lightbulb



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.
 
Old 03-07-2012, 05:33 AM   #3
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Quote:
Originally Posted by fantasy1215 View Post
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

Last edited by lithos; 03-07-2012 at 05:36 AM.
 
Old 03-08-2012, 12:06 AM   #4
fantasy1215
Member
 
Registered: Oct 2011
Posts: 75

Original Poster
Rep: Reputation: Disabled
The problem is using ', If I use " instead ', it works!
Thanks you guys!
 
Old 03-08-2012, 01:39 AM   #5
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
That is nice to have it working now.

Regards.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
tar the last periodic backup that is in another path and move the tar to some dir nelovicov Linux - Newbie 6 01-20-2012 09:40 AM
[SOLVED] Full Path Name Juve IT Linux - Newbie 6 12-16-2010 08:22 PM
How to get the full path of a file in C? Basel Programming 3 10-30-2010 10:52 PM
Shell: tr can only be used when given full path (despite being in $PATH) chochem Programming 2 06-27-2008 08:37 AM
Full Path Verbal Kint Linux - General 7 01-30-2008 09:34 PM


All times are GMT -5. The time now is 09:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration