Wednesday 15 May 2013

mysql - how to log mysqldump errors & warnings to file? -



mysql - how to log mysqldump errors & warnings to file? -

i have mysqlbackup script to: - backup databases individually - log errors file - email file

what have right is:

\#!/bin/sh timestamp=$(date +"%f-%h-%m") backup_dir="/mnt/usb/mysql/" mysql_user="backup" mysql=/usr/bin/mysql mysql_password="*****" mysqldump=/usr/bin/mysqldump email=***** retention="+14" msg=/tmp/mysqlbackup.messages echo "date: $(date)">$msg echo "hostname: $(hostname)" >>$msg echo "backup script has run. [don't worry, won't far!]" >>$msg echo " ----- ----- ----- " >> $msg echo " " >> $msg echo " " >> $msg mkdir -p "$backup_dir/$timestamp" databases=`$mysql --user=$mysql_user -p$mysql_password -e "show databases;" | grep -ev "(database|information_schema|performance_schema)"` db in $databases; $mysqldump --force --opt --user=$mysql_user -p$mysql_password --databases $db | gzip > "$backup_dir/$timestamp/$db.gz" echo "backing up: $db" >> $msg done echo " " >> $msg echo " " >> $msg echo " ----- ----- ----- " >> $msg echo " " >> $msg echo " " >> $msg find $backup_dir* -mtime $retention -exec rm {} \; >> $msg 2>&1 mail service -s "mysql backup script has run" "$email" <$msg rm -f $msg

which works pretty much perfectly, however, these errors/warniongs console:

[root@linux scripts]# ./mysqldump-all-databases.sh mysqldump: error 1194: table 'xxxxx' marked crashed , should repaired when dumping table `xxxxx` @ row: 81052 mysqldump: error 1194: table 'xxxxx' marked crashed , should repaired when dumping table `xxxxx` @ row: 68532 -- warning: skipping info of table mysql.event. specify --events alternative explicitly.

how can log them $msg file emailed? better, possible alter email subject if errors found [so doesn't ignored]

mysql linux bash shell mysql-backup

No comments:

Post a Comment