Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I was planning to do a quick backup of my website. So I tried to run the following command in my webroot:

tar cvfz backup.tar.gz .

That seemed to be working nicely for a while. Until I discovered it had started to backup backup.tar.gz...

Is there an easy way that I can get it to ignore the file I am archiving to?

Note: I would of course have put the archive file in the directory above it if I could. But I only have access to my home directory.

share|improve this question
    
What about access to /tmp? That's always been world writable on every machine I've ever touched. –  Doug Harris Dec 20 '09 at 20:43
    
That could be. But that is also readable by everyone, isn't it? –  Svish Dec 21 '09 at 17:04
add comment

2 Answers

up vote 1 down vote accepted

Try

tar cvfz backup.tar.gz *

This way shell extends the *, vs the tar reading current directory. The difference is that the produced archive does not contain root folder.

If you also need to include hidden files (.files) you can try

tar cvfz backup.tar.gz * .??*

This includes .files and prevents inclusion of parent directories.

share|improve this answer
    
Interesting. What does .??* do exactly? –  Svish Dec 20 '09 at 13:25
    
? is a 'any character' when the * is 'any character sequence'. Shell does not normally include .files with *, so .?? is simply any file beginning with a dot and having two or more characters after the dot, thus preventing inclusion of . and .. –  Ahe Dec 20 '09 at 13:35
    
.??* of course has a problem, it does not include .a and so on, but it is faster to write than .[^.]* and files with a dot and one character are rare. –  Ahe Dec 20 '09 at 13:39
    
Ahaa. Good stuff. Seems to be working nicely :) –  Svish Dec 20 '09 at 14:01
add comment

I'm sure there's a nicer way, but I always just do it from the a different directory.

tar cvfz backup.tar.gz /path/to/www

This link looks like it has the information you might want.

share|improve this answer
    
Yeah, but I can't do that since that directory is the only one I have access to. Added note about that to my question :) –  Svish Dec 20 '09 at 13:17
    
the --exclude= option looks viable, as well. –  mrduclaw Dec 20 '09 at 13:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.