3

I've been using cstream for a while for many things, for example to reduce the impact that mysqldump has on drives. However, I have always done so by calling the binary directly from a script or cronjob.

I've got one situation now in which it would be great if I could use cstream from logrotate, but after some trials, I can't get it working.

You can use cstream in two different ways:

  • as a "cat" binary

    cstream foo | gzip

  • as a pipe from another process

    mysqldump foo | cstream > dump.sql

More precisely, I would like to call cstream from the compresscmd option.

Right now I just use this in logrotate config files.

compresscmd /bin/gzip
compressoptions -9

but like I said, I would like to use something like

compresscmd cstream foo | gzip

Is that possible? Can I use variables/macros from within logrotate config files so that I can pass the info of the file to compress to cstream?

Also, I tried to use compresscmd with a shell script to print the arguments that the script receives, but I only saw one argument with value=-9

So, actually I don't know how gzip picks up that info. Is it from some bash env value only available from logrotate?

I've had a look at logrotate's documentation, but I can't see any answer to my doubts.

Can anyone throw some light on this?

1 Answer 1

1

Looks like logrotate is piping to the compresscmd, so you'll need to write a script which can handle the pipe. I'm sure perl / python could provide a more elegant solution, but here is what I was able to cobble together in bash:

with

compresscmd /root/mycompress.bash

mycompress.bash:

   #!/bin/bash

   ## set the field separator to NULL
   IFS=''

   ## read the pipe into an array
   ARRAY=()
   while read LINE
   do
       ARRAY+=($LINE)
   done

   ## echo the array and pipe to desired commands
   for item in ${ARRAY[*]}
   do
       echo $item
   done | cstream | gzip -9

update:

Upon reflection, the use of an array for temporary storage is unnecessary, so the above code can be reduced to:

    #!/bin/bash

    ## set the field separator to NULL
    IFS=''

    while read LINE
    do
            echo $LINE
    done | cstream

upon further reflection, because cstream handles pipes just fine on its own, mycompress.bash can be reduced to:

    #!/bin/bash

    cstream | gzip

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .