#并发备份数据库
#!/bin/bash
exec &> /tmp/mysql_bak.log
if ! which innobackupex &>/dev/null
then
echo "安装xtrabackup工具"
rpm -ivh http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm && \
yum install -y percona-xtrabackup-24
if [ $? -ne 0 ]
then
echo "安装xtrabackup工具出错,请检查。"
exit 1
fi
fi
bakdir=/data/backup/mysql
bakuser=vyNctM
bakpass=99omeaBHh
function bak_data {
db_name=$1
db_host=$2
db_port=$3
cnf=$4
[ -d $bakdir/$db_name ] || mkdir -p $bakdir/$db_name
innobackupex --defaults-file=$4 --host=$2 --port=$3 --user=$bakuser --password=$bakpass $bakdir/$1
if [ $? -ne 0 ]
then
echo "备份数据库$! 出现问题。"
fi
}
fifofile=/tmp/$$
mkfifo $fifofile
exec 1000<>$fifofile
thread=10
for ((i=0;i<$thread;i++))
do
echo >&1000
done
cat /tmp/database.list |while read line
do
read -u1000
{
bak_data `echo $line`
echo >&1000
} &
done
wait
exec 1000>&-
rm -f $fifofile
#打印三角形
#!/bin/bash
while true
do
read -p "please input the lenth: " ne
if [ -z $n ]
then
echo "要输入一个数字。"
continue
else
n1=`echo $n|sed 's/[0-9]//g'`
if [ -n "$n1" ]
then
echo "你输入的不是纯数字,重新输入。"
continue
else
break
fi
fi
done
for i in `seq 1 $n`
do
j=$[$n-$i]
for m in `seq $j`
do
echo -n " "
done
for p in `seq 1 $i`
do
echo -n "* "
done
done
#截取字符器
#!/bin/bash
var=http://www.aaa.com/root/123.html
echo $var |awk -F '//' '{print $2}'
echo $var |sed 's#http://##'
echo $var |awk -F '/' '{print $5}'
echo $var |sed 's#/123.htm##'
echo $var |awk -F '//' '{print $1}'
echo $var |awk -F 'www' '{print $1}'
echo $var |awk -F '/' '{print $4"/"$5}'
echo $var |awk -F '/' '{print $5}' | awk -F '.' '{print $1}'
#修改文本格式,将两行合并为一行。
#!/bin/bash
#sed 'N;s/\n/:/' test3.txt
n=`wc -l test3.txt|awk '{print $1}'`
n2=$[$n/2]
for i in `seq 1 $n2`
do
i2=$[$i*2]
j=$[$i2-1]
l1=`sed -n "$i2"p test3.txt`
l2=`sed -n "$j"p test3.txt`
echo $l2:$l1
done
#自定义 rm
#!/bin/bash
filename=$1
big_filesystem=/data/backup/mysql
if [ ! -e $1 ]
then
echo "$1 不存在,请使用绝对路径。"
exit
fi
d=`date +%Y%m%d%H%M`
read -[ "Are U sure delete the file or directory $1? y/n: " c
case $c in
y|Y)
mkdir -p $big_filesystem/.$d && rsync -aR $1 $big_filesystem/.$d/$1 && /bin/rm -rf $1
;;
n|N)
exit 0
;;
*)
echo "Please input 'y' or 'n'."
;;
esac
SHELL训练营--day31_shell练习96-100
原创
©著作权归作者所有:来自51CTO博客作者sincethen的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
shell训练营Day24
shell基础练习
shell linux