0

I want to add gzip file verification to my backup script.

My backup script creates logs for stdout and stderr like this:

scp -i $BCKIDENTITYFILE $BCKLOG "$BCKREMOTEUSER"@"$BCKHOST":$BCKREMOTEDIR 2>> $BCKERRLOG 1>> $BCKLOG

When I tested this:

# this prints OK to error.log, nothing to output.log
gzip -v -t existingfile.sql.gz 2>> error.log 1>> output.log 

# prints missing file message to error.log, nothing to output.log
gzip -v -t notexistingfile.sql.gz 2>> error.log 1>> output.log 

What I'm doing wrong?

1
  • @don_crissti Yup. It looks like it acts like mysqldump. Thanks for pointing to explanation.
    – Kamil
    Commented Jan 11, 2023 at 23:36

1 Answer 1

0

It looks like the issue is that you are redirecting the standard error 2>> (2>>) and standard output (1>>) streams to separate log files, but gzip is writing both status information and error messages to the standard error stream.

When you run the command gzip -v -t existingfile.sql.gz, the -v option causes gzip to print additional information about the compressed file, such as the name of the file, its original and compressed sizes, and the compression ratio. This information is written to the standard error stream, which is being redirected to the error.log file in your script.

When the file doesn't exist, the message "gzip: notexistingfile.sql.gz: No such file or directory" is also sent to standard error stream which is redirected to error.log

To fix this, you can redirect the standard error and standard output streams to the same file, so that the status information and error messages are both written to the output.log file:

gzip -v -t existingfile.sql.gz &>> output.log This will redirect both standard error and standard output to the file output.log, so you can see the outcome of the gzip verification in one file.

Alternatively, you could also redirect standard error to standard output, then redirect standard output to the output.log file like this:

gzip -v -t existingfile.sql.gz 2>

0

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