标签:.gz eve -- ast 保存 说明 style The tor
操作系统:CentOS release 6.5
MySQL数据:MySQL 5.1.73
1 #!/bin/bash 2 3 # log file name 4 LOG=/backup/mysql/$(date +%Y%m%d -d -1day).log 5 6 # create backup directory 7 BACKUP_DIR=/backup/mysql/$(date +%Y%m%d -d -1day) 8 9 if [ ! -d "${BACKUP_DIR}" ]; then 10 echo "create backup directory ${BACKUP_DIR}" >> $LOG 11 mkdir ${BACKUP_DIR} 12 fi 13 14 15 # backup db data 16 for i in `mysql -uroot -p123456 -e "show databases;"` 17 do 18 19 if [ "$i" != "Database" ]; then 20 echo "start backup $i" >> $LOG 21 mysqldump -uroot -p123456 -B "$i" --flush-privileges --single-transaction --master-data=2 --flush-logs --triggers --routines --events --hex-blob | gzip > ${BACKUP_DIR}/backup_"$i"_$(date +%Y%m%d -d -1day).sql.gz 22 echo "end backup $i" >> $LOG 23 fi 24 25 done 26 27 echo "end backup" >> $LOG
1 [root@xugf-test mysql]# crontab -e 2 0 0 * * * /bin/sh /root/scripts/db_backup.sh >/dev/null 2>&1
需要把输出重定向到空
前一天yyyymmdd
date +%Y%m%d -d -1day
gzip
cat install.log | gzip > install.log.gz
mysql命令查询所有库
mysql -uroot -p123456 -e "show databases;"
mysqldump命令备份数据库
mysqldump -uroot -p123456 -B test --flush-privileges --single-transaction --master-data=2 --flush-logs --triggers --routines --events --hex-blob | gzip > /backup/mysql/20180515/backup_test_20180515.sql.gz
标签:.gz eve -- ast 保存 说明 style The tor
原文地址:https://www.cnblogs.com/xugf/p/9073974.html