Last active
September 4, 2019 03:10
-
-
Save PoplarYang/cde9ee632017c91c1d4e76b984cd07dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bash <(curl -s http://pkzxwcntr.bkt.clouddn.com/wow.sh) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash -e | |
| export PATH=$PATH:/usr/local/mysql/bin | |
| # 设置用户、密码和主机IP | |
| DATE=$(date +%Y%m%d) | |
| username=root | |
| password=密码 | |
| hostip=localhost | |
| dblists=$(mysql -u$username -p$password -h$hostip -e"SHOW DATABASES;") | |
| denylists=(Database mysql test information_schema performance_schema) | |
| #循环备份数据库 | |
| mkdir /web/backup/$DATE | |
| for dbname in ${dblists[*]}; do | |
| #排除不用备份的数据库 | |
| flag=0 | |
| for i in ${denylists[*]}; do | |
| if [ "$i" = "$dbname" ]; then | |
| flag=1 | |
| fi | |
| done | |
| if [ $flag -ne 1 ]; then | |
| | |
| #指定时间日期和备份目录 | |
| backupdir=/web/backup/$DATE/$dbname$(date +%Y-%m-%d_%H%M%S).sql.gz | |
| LogFile=/web/backup/backlog/baklog$(date +%Y-%m-%d_%H%M%S).log | |
| | |
| #写入备份操作日志文件 | |
| echo "-------------------------------------------" >> $LogFile | |
| echo " " >> $LogFile | |
| mysql -u$username -p$password -h$hostip $dbname -e"SHOW MASTER STATUS;" >>$LogFile | |
| | |
| #开始备份数据库 | |
| mysqldump -u$username -p$password -h$hostip $dbname -e --max_allowed_packet=1048 --net_buffer_length=16384 | gzip>$backupdir | |
| echo " " >> $LogFile | |
| mysql -u$username -p$password -h$hostip $dbname -e"SHOW MASTER STATUS;" >>$LogFile | |
| echo " " >> $LogFile | |
| echo " " >> $LogFile | |
| echo " " >> $LogFile | |
| echo $(date +"%y-%m-%d %H:%M:%S") >> $LogFile | |
| echo "--------------------------" >> $LogFile | |
| fi | |
| done | |
| #删除十天前备份 | |
| find /web/backup -mtime +10 -name "2015*" -exec rm -rf {} \; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # 随机取数 | |
| a=([0]=jerry [1]=tom [5]=nikita) | |
| index=$[RANDOM%6] | |
| echo ${a[$index]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # 生成100以内指定个数的不重复随机数 | |
| read -p "Enter the number of array elements: " elements_number | |
| declare -a array | |
| for i in `seq 0 $[$elements_number-1]`; do | |
| while true; do | |
| tmp_number=$[RANDOM%100] | |
| if ! echo ${array[@]} | grep -w "$tmp_number" &> /dev/null; then | |
| array[$i]=$tmp_number | |
| echo ${array[$i]} | |
| break | |
| fi | |
| done | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| trap 'rm -rf /tmp/test;echo "Cleaning...";echo "Clean over.";exit 5' INT | |
| mkdir -p /tmp/test | |
| while true; do | |
| touch /tmp/test/file_`date +%s` | |
| sleep 2 | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment