0

Im having trouble getting output into my log file in my script. Backup runs successfully but the logfile is empty. WHen I run the script I get "Warning: Using a password on the command line interface can be insecure." so at least that should be in a log file. (I am using a .key file)

mysqldump  -u root -p$Pass   --all-databases | gzip > fulldbdmp-$(date +%m%d%Y).dump.gz 2> file.log

3 Answers 3

2

I agree with this answer, but it seems, that it is needed to add another parameter (-v) to enable verbose output, like mysqldump -v -u root -p$Pass --all-databases 2>file.log | gzip > fulldbdmp-$(date +%m%d%Y).dump.gz.

Sign up to request clarification or add additional context in comments.

2 Comments

Inspired by this answer and official docs
Great..cant believe I did not realize it.. Thank you. Spasibo - Vitalik
1

Thats because, only error from your gzip execution goes into file. To get what you want, use -

mysqldump -u root -p$Pass --all-databases 2>file.log | gzip > fulldbdmp-$(date +%m%d%Y).dump.gz

1 Comment

Yep, that all makes sense. Thank you
1

The fact that you can see the error message on your terminal means it's not going into the log file.

As others have mentioned, you are redirecting stderr from the gzip element of the pipeline, not the mysqldump element.

If you think about your pipline as a series of elements, it may become clear what's going on:

  • mysqldump -u root -p$Pass --all-databases
  • gzip > fulldbdmp-$(date +%m%d%Y).dump.gz 2> file.log

You were probably after this:

  • mysqldump -u root -p$Pass --all-databases 2> file.log
  • gzip > fulldbdmp-$(date +%m%d%Y).dump.gz

Which becomes:

mysqldump -u root -p$Pass --all-databases 2> file.log \ |
  gzip > fulldbdmp-$(date +%m%d%Y).dump.gz

Side note: I would strongly encourage you not to ignore the following warning. It is there for a reason. see 6.1.2.1 End-User Guidelines for Password Security

Warning: Using a password on the command line interface can be insecure

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.