From owner-freebsd-questions@FreeBSD.ORG Sat Aug 3 23:11:30 2013 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id C5046542 for ; Sat, 3 Aug 2013 23:11:30 +0000 (UTC) (envelope-from freebsd-doc@fjl.co.uk) Received: from bs1.fjl.org.uk (bs1.fjl.org.uk [84.45.41.196]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 54B202126 for ; Sat, 3 Aug 2013 23:11:29 +0000 (UTC) Received: from [192.168.1.35] (mux.fjl.org.uk [62.3.120.246]) (authenticated bits=0) by bs1.fjl.org.uk (8.14.4/8.14.4) with ESMTP id r73NBK5s032176 (version=TLSv1/SSLv3 cipher=DHE-DSS-CAMELLIA256-SHA bits=256 verify=NO) for ; Sun, 4 Aug 2013 00:11:21 +0100 (BST) (envelope-from freebsd-doc@fjl.co.uk) Message-ID: <51FD8E19.90403@fjl.co.uk> Date: Sun, 04 Aug 2013 00:11:21 +0100 From: Frank Leonhardt User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: freebsd-questions@freebsd.org Subject: Archiving a log file Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.14 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 Aug 2013 23:11:30 -0000 The answer isn't (AFAIK) newsyslog As a one-off, I need to archive an old log file - say httpd-access.log - while its still open. I don't want this to happen automatically and I don't want to set up newsyslog or anything like that. And I really don't want to mess about with signals to whatever is writing to the file, even assuming the writer could respond to them. I can't just rename the file as it's open for writing, and there would also be a good chance that something will be added to the file while it's being compressed. What I actually do is: cp httpd-access.log httpd-access.log-03-Aug-13 && :> httpd-access.log && bzip2 httpd-access.log-03-Aug-13 Data might be lost here as something may be added between the cp being completed and the file being truncated. It's not the end of the world if this happens, but is there a better way? I could always shut down Apache for the duration, but I don't want to do that either, so in this case I'm happy to take the risk (it's not like I'm likely to miss anything that important). I don't know if this can be relied on as a POSIX thing, but the cp command simply(!) issues read() and write() calls until read() fails to get any more bytes, so if data is being appended to the file after cp is started it'll still be copied. Therefore the window where stuff could be written after the copy but before the truncation is shortened, but extant. So what's the magic utility I don't know about? Thanks, Frank.