0

I'm wanting to copy a file and gzip it in a single command/step

But I want to do numbered backup if the file already exists i.e. "cp --backup=numbered" or similar.

The reason for the single step is that I'm copying a log file (which can be large) to a network filesystem. The filesystem is not nfs and I cannot use scp. I must use regular unix commands. Actually the filesystem is cephfs.

I thought perhaps a zcat logfile > /dest/logfile but what about numbered backup?

This whole problem arose because logrotate only starts gzipping on the 2nd rotate operation not the first. i.e. live (today), yesterday (.1 - not gzipped), day before yesterday (.2 - gzipped). Kindof annoying.

If I gzip before copy I think that might mess with logrotate.

hookenz
  • 14,472
  • 23
  • 88
  • 143

1 Answers1

0

I'm afraid logrotate always runs the postrotate script before the compression. What you probably want to do is to remove normal compression and instead do that manually as part of your postrotate script. This would ensure that the compression takes place prior to copying. See here for an example: http://www.leaseweblabs.com/2013/06/logrotate-and-rsync-mysqldump-backups/

Setomidor
  • 101
  • 1