backupMysql.sh
#!/bin/sh #!/bin/bash function backup() { for i in $* do mysqldump -h$hostip -P$port -u$username -p$password -E -R $i >> $filelocation/$edate/DB_$i'_'$edate.sql done # echo $filelocation"records listed below:" # echo `ls $filelocation` for x in `ls $filelocation` do echo "for" $x if [ -d "$filelocation/$x" ];then #echo $(date +%s -d $edate) #echo $(date +%s -d $x) time1=$(($(date +%s -d $edate) - $(date +%s -d $x))); time1=$(($time1/60/24/60)) echo "the dis is "$time1" days" if [ $time1 -gt $dis ];then #echo $dis '<' $time1 #echo 'delete dir '$x `rm -rf $filelocation/$x` # else #echo $dis '>' $time1 #echo 'save dir' $x fi fi done } username=root password="password" hostip=127.0.0.1 port=3306 filelocation=/home/jet/backup/mysql edate=`date +%Y-%m-%d` dis=7 if [ ! -d $filelocation ]; then `mkdir "$filelocation"` fi if [ ! -d "$filelocation/$edate" ];then `mkdir "$filelocation/$edate"` fi backup datebase1 database2 database3
"世界上只有一种真正的英雄主义,就是认清了生活的真相后,还依然执着地热爱它。"
——罗曼·罗兰