Mysql完全備份

1.查看mysql上都有哪些庫
mysql> show databases G
*************************** 1. row ***************************
Database: information_schema
*************************** 2. row ***************************
Database: mysql
*************************** 3. row ***************************
Database: test
  3 rows in set (0.00 sec)
2.執行完全備份
  sh back.sh
  back.sh
  #!/bin/sh
export back_dir=/data/bak
export pass=”123″
export mysql_dir=/usr/local/mysql-5.1.56
for i in $(mysql -uroot -p$pass -e show databases G | grep Database | cut -d: -f2)
  do
  $mysql_dir/bin/mysqldump –opt $i -p$pass –skip-lock-tables>$back_dir/$i.$(date +%Y%m%d).sql
done
 #use fetion to notice dba
  LD_LIBRARY_PATH=/usr/lib  /usr/local/fetion/fetion  –mobile=159xxxx3240 –pwd=123456 –to=159xxxx3240 –msg-utf8=mysql backup is     success !
3.計劃任務
 crontab -e
 0 3 * * * sh /usr/bin/back.sh

You May Also Like