LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   tar.bz2 exception to --exclude? (https://www.linuxquestions.org/questions/linux-general-1/tar-bz2-exception-to-exclude-873653/)

whycali 04-07-2011 03:56 PM

tar.bz2 exception to --exclude?
 
I'm writing a script to backup a joomla site. I'd like to exclude every file EXCEPT the index.html file in the /cache /tmp and /administrator/cache directories, but can't figure out how to do it. Here's my command line:

Code:

tar -cjf test.tar.bz2 joomla_16 joomla_16/cache/index.html joomla_16/cache/index.html joomla_16/administrator/cache/index.html --exclude "cache/*" --exclude "_*" --exclude "administrator/cache/*" --exclude "tmp/*"
This creates the archive, excludes the three directories but does not include the index.html files.

Thanks!

Mike

Snark1994 04-07-2011 04:28 PM

Well, a simple way would be to add the line

Code:

tar -Ajf test.tar.bz2 /cache/index.html /tmp/index.html /administrator/cache/tmp/index.html

whycali 04-07-2011 04:52 PM

That makes sense, but I got this error when I tried it:

Code:

tar: Cannot concatenate compressed archives
Try `tar --help' or `tar --usage' for more information.


Snark1994 04-08-2011 01:32 PM

Ah, okay, what you can do is this (just tried it, so it definitely works... at least on my PC):

Code:

tar -cf test.tar joomla_16 joomla_16/cache/index.html joomla_16/cache/index.html joomla_16/administrator/cache/index.html --exclude "cache/*" --exclude "_*" --exclude "administrator/cache/*" --exclude "tmp/*"
tar -Af test.tar /cache/index.html /tmp/index.html /administrator/cache/tmp/index.html
bzip2 test.tar

This separates the two stages - one creates the test.tar file, the next appends the files you want added to it, and then you compress the completed archive :)

whycali 04-08-2011 06:23 PM

Wonderful, thanks for all your help. I'll give it a shot, but wanted to thank you first.

Mike

Snark1994 04-09-2011 04:25 AM

If the problem's been solved, it's considered polite to mark the thread as 'SOLVED' (there's a link at the top of the page) :)

And posting a thank post like you did / clicking the reputation buttons is definitely good kudos, so well done for that :P

whycali 04-11-2011 01:39 PM

All appears to work correctly, but it's not. When I try to open the tar.bz2 file I get this error:
Code:

tar: Skipping to next header
tar: Exiting with failure status due to previous errors

This happens on the tar -Af phase when we're adding the index.html files. What could be causing this?

Snark1994 04-12-2011 11:02 AM

*headslap*

So sorry. -A is appending tar files to an archive, but -r is appending files to the end of an archive. So -A would add two .tar files together, but -r would put the next file into the archive.

whycali 04-12-2011 11:10 AM

[SOLVED] tar.bz2 exception to --exclude?
 
TYVM! That worked like a charm.... rep+++


All times are GMT -5. The time now is 06:31 AM.