Jump to content
  • Announcements

    • spinynorman

      Mandriva Official Documentation

      Official documentation for extant versions of Mandriva can be found at doc.mandriva.com.   Documentation for the latest release may take some time to appear there. You can install all the manuals from the main repository if you have Mandriva installed - files are prefixed mandriva-doc.
    • paul

      Forum software upgrade   10/29/17

      So you may have noticed the forum software has upgraded !!!
      A few things that have changed. We no longer have community blogs (was never really used) We no longer have a portal page.
      We can discuss this, and decide whether it is needed (It costs money) See this thread: Here
Sign in to follow this  
Vdubjunkie

multiple --exclude in tar

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Guest anon

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.

Share this post


Link to post
Share on other sites
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:

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×