开发者

using tar to compress log directory, what happens when apache tries to write during compression?

I want to run a cron and compress my /var/log directory every hour to a tar file.. so I can backup that file.

What would happen to the log files the exact moment I run the tar command, will I miss those log开发者_高级运维 lines or would the different softwares running and using /var/log wait, or will the tar be corrupt etc?

I have a busy webserver so it writes to the log files many times every second.

I plan on running

tar -zcf /home/user/file_date.tar /var/log


The tar will have an incomplete version of the file, without the new data that was written while it compressed and you'll get the following message:

Truncated write; file may have grown while being archived.

You can test this with the following one liner:

perl -e 'open my $log_fh, ">", "/tmp/dir/log" or die; while (1) { print $log_fh $x++,"\n"; } '

and run

tar cvzf dir.tar.gz /tmp/dir/

from another terminal

I'd suggest renaming the file before tarring, or using logrotate if it fits your needs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜