MandrivaUsers.org : multiple --exclude in tar - MandrivaUsers.org

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

multiple --exclude in tar

#1 User is offline   Vdubjunkie 

  • frequent
  • Group: Members
  • Posts: 177
  • Joined: 10-January 03

Posted 11 October 2003 - 11:45 AM

Hello all,
First off, let me say that aru would be proud. I've finally bitten the bullet and taken to the (for me) arduous task of learning to script using bash.
btw, in searching I did not find my answer, but I did find this:
http://www.mandrakeusers.org/viewtopic.php...xclude+multiple
...and, wow is about all I can say.
On to my problem. I decided to write up a cool script that I could put a CRON job in for to backup my /home folder minus a few things which take up too much space and are unnecessary.
My problem is that the only thing I have found to work is the following:
tar --exclude=<first> --exclude=<second> -cjf backupfile.bz2 /home/*
In my script I have something like:
EXCLD='first second third'
and use the $EXCLD in the final line of "code" to execute a tar command. Now, I've tried single quoting, double single quoting, full quoting, separating with semi and full colons and backslashes, everything I can think of to my list of files/directories to exclude so that I can have one --exclude statement, and I just cannot figure out how to make it work.
I do believe that I got this idea to work once before by redirecting it to another file using the -X or --exclude-from= and just listing one item per line in that text file, but I'd sort of like to avoid that too if possible. If that is the option, please tell me so I can bite the bullet and move on... :roll:

...oh yeah.. man this is freaking fun. any of you CLI junkies out there putting off scripting should do like me, bite the bullet and learn it.
0

#2 Guest_anon_*

  • Group: Guests

Posted 11 October 2003 - 12:45 PM

Can't help you with bash, im not that good at it :( If you can't get a good answer for your problem, you could always run rsync through cron to get the job done.
Example:
 rsync auz --existing

Which would archive,update,compress(zip) only the existing files in your backup folder. Not as clever as writing your own script, but it works.
0

#3 User is offline   aru 

  • Mandriva Guru
  • Group: Members
  • Posts: 2,150
  • Joined: 04-December 02

Posted 11 October 2003 - 01:59 PM

Quote

Hello all,
    First off, let me say that aru would be proud.  I've finally bitten the bullet and taken to the (for me) arduous task of learning to script using bash.

:lol:/> yes, I'm proud of you :lol:/>

Quote

My problem is that the only thing I have found to work is the following:
tar --exclude=<first> --exclude=<second> -cjf backupfile.bz2 /home/*
In my script I have something like:
EXCLD='first second third'
and use the $EXCLD in the final line of "code" to execute a tar command. 
[...]
 
I do believe that I got this idea to work once before by redirecting it to another file using the -X or --exclude-from= and just listing one item per line in that text file, but I'd sort of like to avoid that too if possible.  If that is the option, please tell me so I can bite the bullet and move on...


You'll need to use the "--exclude-from" flag, but you don't need to use a file to store the filenames, you can 'emulate' that file, something like:

EXCLD='first second third'

tar -X <(for i in ${EXCLD}; do echo $i; done) -cjf backupfile.bz2 /home/*


The <(stuff) creates a 'virtual file' at /dev/fd/62 containing the output of stuff
The text you've read above is supposed to be in english;
oops! btw, the code in this post -if any- is released under the GNU GPL v2 or later, that means among other things that it hasn't any warranty.


- The Unix philosophy in one lesson: KEEP IT SIMPLE, STUPID! -- ES. Raymond. "TAOUP"

You might want to take a look to our Musb FAQs and to "THE" FAQs... and remember "/usr/bin/man" is your best friend, use it!

:wq
0

#4 User is offline   Vdubjunkie 

  • frequent
  • Group: Members
  • Posts: 177
  • Joined: 10-January 03

Posted 18 October 2003 - 04:06 AM

I knew aru would come through for me.
Man I've been having fun. All of a sudden making sense of, and following the process of scripts makes a lot more sense!
:P/>
Anyway, I was searching for that post where you showed me how to find a bunch of files meeting criteria, then move it all. After doing that I'm back to bash.edu for some more edumacation :twisted:/>

Thanks once again man. I only hope one day the code will flow in my head the way it does in yours.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users