用mysqldump导出所有mysql库的bash脚本

四月 21st, 2012

在给网站搬迁主机的时候,经常有若干个甚至数十数百的MySQL库需要迁移,用直接复制的方式并不能保证数据库的状态一定完好,相比之下用mysqldump可以更可靠的保证数据的完整性与可靠性。
这个脚本只需简单的输入mysql的root账户信息,指定mysql数据所在的目录以及你想要备份到的目录,即可实现一次性导出所有库。

#!/bin/sh
echo for more information please visit http://fullpanel.net
echo this will dump all the mysql databases into .sql files
echo input the the database dir \(for example /var/lib/mysql     /usr/local/mysql/var\):
read databasedir
cd $databasedir
ls -lh | grep -e "^d" | awk '{print $9}' > /tmp/mysql.txt
echo where are you going to put the sql files:
read outputdir
echo input your root password
read password
cat /tmp/mysql.txt | while read iii
do
mysqldump -uroot -p$password $iii --lock-tables=false > $outputdir/$iii.sql
done
rm -rf /tmp/mysql.txt
echo done!!

*说明
*使用方法,保存代码为mysqldump.sh,运行sh mysqldump.sh。
*根据脚本提示一次输入mysql数据文件所在目录,导出文件所在目录,root密码即可。
*centos默认情况下mysql数据目录为/var/lib/mysql , LNMP套件的mysql数据目录为/usr/local/mysql/var,具体位置请查询my.cnf
*你也可以直接下载http://files.fullpanel.net/scripts/mysql/mysqldumpall.sh运行。

LINUX下阻止PHPDDOS攻击的脚本

四月 10th, 2012

PHPDDOS是通过UDP协议对外发包,但全部屏蔽又会阻止服务器进行正常的DNS查询,因此提供这个脚本,可以自动提取服务器使用的DNS过滤掉进行阻止。

#!/bin/sh
echo for more information please visit http://fullpanel.net
echo this will drop the php flood ddos
cat /etc/resolv.conf |grep nameserver |awk '{print $2 }' > /tmp/nameservers.txt
cat /tmp/nameservers.txt | while read iii
do
iptables -I OUTPUT -p udp --dport 53 -d $iii -j ACCEPT
done
iptables -A OUTPUT -p udp -j DROP
rm -rf /tmp/nameservers.txt
echo done!!!
iptables -L

如重启服务器,请记得先把防火墙配置保存。

hello

四月 6th, 2012
#!/opt/bin/bash
bakCmd=/bin/tar
cmdOpt="-zcvf"
bakDir=bakDir
srcDir=srcDir
dateTime=`date '+%Y%m%d%H%M%S'`
fileSuffix=".tar.gz"
cd $srcDir ; $bakCmd $cmdOpt $bakDir/bakFile-$dateTime$fileSuffix targDir > /dev/null