shell脚本备份mysql,放在crontab中,可以作为每日测试用数据库备份
#!/bin/bashstring_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_pathelse echo dir existfiprefix=$1if [ $prefix ]; then prefix=$prefix'_'fiecho $prefixcd $file_pathdate# 备份所有的/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
欢迎关注技术公众号: