mysql数据库备份脚本
mysql数据库分库备份脚本:
[root@localhost tmp]# cat mysql.sh
#!/bin/bash
USER=root
PASSWORD=joy4you
SOCKET=/tmp/mysql3306.sock
LOGIN="mysql -S $SOCKET -u $USER -p$PASSWORD"
DUMP="mysqldump -S $SOCKET -u $USER -p$PASSWORD"
DATA=$($LOGIN -e "show databases;" | egrep -v "schema$|test|mysql" | sed '1d')
for data in $DATA;do
$DUMP $data | gzip >/data/${data}_$(date +%Y_%m_%d_%H).sql.gz
done
mysql数据库分表备份脚本:
#!/bin/bash
USER=root
PASSWORD=joy4you
SOCKET=/tmp/mysql3306.sock
LOGIN="mysql -S $SOCKET -u $USER -p$PASSWORD"
DUMP="mysqldump -S $SOCKET -u $USER -p$PASSWORD"
DATA=$($LOGIN -e "show databases;" | egrep -v "schema$|test|mysql" | sed '1d')
for data in $DATA;do
TABLE=$($LOGIN -e "use $data;show tables;"|sed '1d')
for table in $TABLE;do
[ ! -d /data/$data ] && /bin/mkdir /data/$data
$DUMP $data $table | gzip >/data/$data/${data}_${table}_$(date +%Y_%m_%d_%H).sql.gz
done
done