Tuesday, October 11, 2011

Exclude Directories or Files with Tar

I often do backups of my public_html but since I don't need folders like phpMyAdmin and logs, I found an easy way to do that in order to reduce backup size.The command to do this is:
tar -zcvf backup.tar.gz public_html/ --exclude "public_html/phpMyAdmin" --exclude "public_html/logs"


I am outside the public_html directory while doing this.For a more general case, it would be:
tar -zcvf filename.tar.gz directory_to_backup --exclude "directory_to_exclude"


This way, I save time and space.Hope this will be useful.
Remember that individual files can be too excluded by replacing directory with filename.

0 comments:

Post a Comment