Jump to content

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.

Link to comment
Share on other sites

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.

Link to comment
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

Link to comment
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...