[root@ip data]# cat mysql_back.sh
#!/bin/bash
user=user
pass=pass
table1=table1
table2=table2
date=`date +%Y%m%d --date "-1 days"`
mysqldump -u$user -p$pass --default-character-set=utf8 --comments=FALSE --tables --no-create-info=FALSE --add-drop-table=TRUE --no-data=FALSE $table1 | sed 's/AUTO_INCREMENT=[0-9]*\s//g' >/data/backup_CN/$table1$date.sql
mysqldump -u$user -p$pass --default-character-set=utf8 --comments=FALSE --tables --no-create-info=FALSE --add-drop-table=TRUE --no-data=FALSE $table2 | sed 's/AUTO_INCREMENT=[0-9]*\s//g' >/data/backup_JP/$table2$date.sql
find backup_CN/ -name "*.sql" -type f -mtime +5 -exec rm {} \; > /dev/null 2>&1
find backup_JP/ -name "*.sql" -type f -mtime +5 -exec rm {} \; > /dev/null 2>&1
网友评论