shell腳本備份mysql,放在crontab中,能夠做爲每日測試用數據庫備份mysql
#!/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
歡迎關注技術公衆號:sql