shell 备份mysql
shell脚本备份mysql,放在crontab中,可以作为每日测试用数据库备份
#!/bin/bash string_time=`date +%Y%m%d%H%M`; file_path=`date +%Y%m%d`; work_dir='/data/backup_dir/pet'; echo $work_dir; echo $file_path; file_path=$work_dir'/'$file_path; echo $file_path; if [ ! -d $file_path ];then mkdir $file_path else echo dir exist fi prefix=$1 if [ $prefix ]; then prefix=$prefix'_' fi echo $prefix cd $file_path date # 备份所有的 /usr/local/mysql/bin/mysqldump -uroot -pPaic1234 -h192.168.5.211 -P3306 --set-gtid-purged=OFF --single-transaction --hex-blob dbname > ${prefix}sit_${string_time}_dbname.sql; # 备份ddl /usr/local/mysql/bin/mysqldump -uroot -pPaic1234 -h192.168.5.211 -P3306 -d --set-gtid-purged=OFF --single-transaction --hex-blob dbname > ${prefix}sit_${string_time}_dbname.sql; # 备份dml /usr/local/mysql/bin/mysqldump -uroot -pPaic1234 -h192.168.5.211 -P3306 -t --set-gtid-purged=OFF --single-transaction --hex-blob dbname > ${prefix}sit_${string_time}_dbname.sql; date
欢迎关注技术公众号: