数据恢复的脚本
数据恢复的脚本
#!/bin/bash
if [ -d /root/`date +%Y-%m-%d` ];then
innobackupex --apply-log /root/`date +%Y-%m-%d` >>/var/log/sjhf`date +%Y%m%d`.log 2>&1
if [ $? -eq 0 ];then
if [ -d /usr/local/mysql/data_bak ];then
service mysqld stop >>/var/log/sjhf`date +%Y%m%d`.log 2>&1
rm -rf /usr/local/mysql/data_bak >>/var/log/sjhf`date +%Y%m%d`.log 2>&1
mv /usr/local/mysql/data /usr/local/mysql/data_bak >>/var/log/sjhf`date +%Y%m%d`.log 2>&1
mkdir /usr/local/mysql/data >>/var/log/sjhf`date +%Y%m%d`.log 2>&1
cp -ra /root/`date +%Y-%m-%d`/* /usr/local/mysql/data/ >>/var/log/sjhf`date +%Y%m%d`.log 2>&1
chown -R mysql.mysql /usr/local/mysql/data/ >>/var/log/sjhf`date +%Y%m%d`.log 2>&1
service mysqld start >>/var/log/sjhf`date +%Y%m%d`.log 2>&1
else
exit
fi
else
exit
fi
else
exit
fi