views:

19

answers:

1

Hi!

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
+1  A: 

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.

miedwar