Tar: How to ignore the archive itself

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.


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.


b=backup.tar.gz; tar --exclude=$b -zcf $b .


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.