Masking stdout but not errors on XtraBackup

433 views
Skip to first unread message

Cherian

unread,
Mar 26, 2012, 5:07:34 AM3/26/12
to Percona Discussion
Hi all,
When I run xtrabackup as
(sudo /usr/bin/innobackupex --user=user --password=pass /tmp/
mysqlbackup/ --parallel=5 --stream=tar | gzip > /tmp/mysitqlbackup/
backup.tar.gz) 1>/dev/null

InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase
Oy
and Percona Inc 2009-2012. All Rights Reserved.

This software is published under
the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.

The standard output is shown despite redirecting it.

When I redirect 2>/dev/null the errors as well as well standart output
is masked
innobackupex: Error: mysql child process has died: ERROR 1045 (28000):
Access denied for user 'root'@'localhost' (using password: YES)
I need to run innobackupex as a cron, with me notified only for
genuine errors like the password failure or space issues etc.
How can I do this?
I know I can grep for completed: OK, but I wanted a standard way to do
this and think the redirection logic that innobackupex uses right now
is not optimal
Can someone help?

-Cherisn

David Juntgen

unread,
Mar 26, 2012, 9:28:16 AM3/26/12
to percona-d...@googlegroups.com
Hi,

1) --parallel only works when copying files, not when streaming.  See: http://www.percona.com/doc/percona-xtrabackup/xtrabackup_bin/xbk_option_reference.html

2) when you run your script in cron, is it exactly like you show?  why isn't the stderr redirect within the parentheses?  Can you reply with your contjob / script? 


--Dave


--
You received this message because you are subscribed to the Google Groups "Percona Discussion" group.
To post to this group, send email to percona-d...@googlegroups.com.
To unsubscribe from this group, send email to percona-discuss...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/percona-discussion?hl=en.




--
David W. Juntgen

Cherian Thomas

unread,
Mar 26, 2012, 11:36:22 AM3/26/12
to percona-d...@googlegroups.com

Thanks David.

The script is a simplified version of the above statement

NOWDATE=`date +%Y-%m-%d-%h-%I`

# backup everything

sudo /usr/bin/innobackupex --user=user --password=pass /tmp/mysqlbackup/ --stream=tar | gzip > /tmp/mysqlbackup/mysql_$NOWDATE.tar.gz

 

# upload backed up files

/usr/bin/s3cmd put --acl-private /tmp/mysqlbackup/mysql_$NOWDATE.tar.gz s3://backup.site.com/mysql_$NOWDATE.tar.gz

# remove archive

rm /tmp/mysqlbackup/mysql_$NOWDATE.tar.gz

 


Regards,
Cherian

John Fanjoy

unread,
Mar 26, 2012, 12:41:46 PM3/26/12
to percona-d...@googlegroups.com

I may be off base here but if this is your cronjob you shouldn't need to use sudo and doing so would likely cause it to fail would it not.

As far as getting rid of the stdout and only paying attention to stderr, why don't you just log all output and test for success... Ex.
Innobackupex > logfile 2>&1
[ $? -gt 0 ] && echo "problem"
I haven't tested this with innobackupex but if it finds failure I'm pretty sure it will exit 1 like most other applications

Cherian Thomas

unread,
Mar 26, 2012, 2:18:05 PM3/26/12
to percona-d...@googlegroups.com

Thanks John. The sudo is certainly a concern. Will remove.

I wanted to resist greping the output since XtraDBbackup is spitting out normal values to STDERR and this would be a hack around it. I wanted to understand if there is a reason behind it. 


Regards,
Cherian

David Juntgen

unread,
Mar 26, 2012, 3:17:35 PM3/26/12
to percona-d...@googlegroups.com
1) yes - drop the sudo when running cronjob.
2) According to the documentation from xtrabackup it asks that you check the last line to make sure it says "completed OK!"  I would 

snippet from backup log:

...

IMPORTANT: Please check that the backup run completes successfully.
           At the end of a successful backup run innobackupex
           prints "completed OK!".
...

So for example to automate check:

#!/bin/bash

logfile=/tmp/mysql.log
(
CMD="innobackup ...."
$CMD
if [ `tail -n 1 $logfile | grep "completed OK\!" | wc -l` -eq 1 ]
then
   echo "`date` Backup was successful!"
else
   echo "`date` Backup failed!"
fi
) > $logfile 2>&1

There are ton of ways to skin this cat, this is simply one of them.

--Dave

Baron Schwartz

unread,
Mar 26, 2012, 5:06:07 PM3/26/12
to percona-d...@googlegroups.com
Cherian,

On Mar 26, 2012, at 2:18 PM, Cherian Thomas wrote:

I wanted to resist greping the output since XtraDBbackup is spitting out normal values to STDERR and this would be a hack around it. I wanted to understand if there is a reason behind it. 

Yes -- streaming backups send data to STDOUT, so that must not be mixed with other output.

- Baron

--
Win free MySQL conference tickets! http://goo.gl/mvZ4W

Cherian Thomas

unread,
Mar 28, 2012, 9:58:45 AM3/28/12
to percona-d...@googlegroups.com
Thanks a lot everyone.
This worked for me

result=$((/usr/bin/innobackupex --user=root --password=ajeesh123 /tmp/mysqlbackup/ --stream=tar | gzip > /tmp/mysqlbackup/mysql_$NOWDATE.tar.gz) 2>&1)
echo $result
things_are_ok='innobackupex: completed OK'
if [[ "$result" != *"$things_are_ok"* ]]; then
  echo "$result" 1>&2
else
  echo "$result" >&1
fi


Regards,
Cherian



Reply all
Reply to author
Forward
0 new messages