AI智能
改变未来

shell实现mysql数据库备份

#!/bin/bash#作者:comyn 2020-04-01#用于数据库备份#备份路径backup_path=/data1/backup/`date +%Y%m%d`;#mysql参数mysql_port=3306mysql_host=127.0.0.1mysql_user=rootmysql_pwd=123456mysql_db=testmysql_backup_file=test.sql# 创建备份文件夹echo \"备份路径:$backup_path\"if [ -d $backup_path ];thenecho “路径已存在”;elsemkdir -p $backup_path;if [ $? -eq 0 ];thenecho \"$backup_path 创建成功\";elseecho \"$backup_path 创建失败,请检查!\";fifi# mysql备份命令echo -e \"\\033[32m开始备份$backup_path/$mysql_backup_file\\033[0m\"mysqldump --defaults-extra-file=/etc/mysql/my.cnf -h$mysql_host -p$mysql_port -u$mysql_user -p$mysql_pwd --databases $mysql_db > $backup_path/$mysql_backup_fileif [ $? -eq 0 ];thenecho \"备份成功,备份文件为:$backup_path/$mysql_backup_file\";elseecho \"备份失败,请检查!\";echo \"备份命令:mysqldump --defaults-extra-file=/etc/mysql/my.cnf -h$mysql_host -p$mysql_port -u$mysql_user -p$mysql_pwd --databases $mysql_db > $backup_path/$mysql_backup_file\"fi

执行结果:

赞(0) 打赏
未经允许不得转载:爱站程序员基地 » shell实现mysql数据库备份