Saturday, March 21, 2009

Tar Skip Certain Files Such as Log Files

I was moving to a different web hosting Linux dedicated server, and I needed to move all my files over. I first tried to copy via "scp" all the website folders and files, but ran into a problem where scp was not copying symbolic links but instead was following the links and copying the same files repeatedly. I figured that I better use tar to create a tarball of my directories and files. I ran it with gzip compression and it really slowed down my server. No biggie but what I really wanted was to have tar skip huge files such as "access_log" and "error_log" created by apache. After doing some research here are the steps I went about doing this:

1)run "screen" (screen allows you to open up a connected instance of your shell, and in case you get disconnected by your ssh client, the command you ran after running screen still keeps running, and you can "re-attach" to the screen later).

2)make a text file called tar_skip_files.txt, and add file names line-by-line that you want tar to skip; wildcards are allowed. In this case my file looked like this:

[root@myserver]# cat tar_skip_files.txt
access_log
error_log

3)Run tar with the "eXclude" switch. The "z" invokes gzip compression. Here is an example:

tar cvfz websites.tgz /home/websites -X tar_skip_files.txt

Then scp the tarball over to your new server and you're in business!

0 comments: