mysql_backup.sh
#!/bin/bash path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin export path #数据库用户名 dbuser='1111' #数据库用密码 dbpasswd='2222' #备份数据库 dbname='3333' #备份时间 BACKUP_TIME=`date +"%Y/%m/%d %H:%M.%S"` backup_time=`date +"%Y%m%d"` #日志备份路径 logpath='/var/log/MySQL_backup' [ ! -e "$logpath" ] && mkdir $logpath cd $logpath touch mysql_backup.log cd #数据备份路径 datapath='/home/backup/mysql_back' [ ! -e "$datapath" ] && mkdir $datapath #日志记录头部 echo "备份时间为${BACKUP_TIME},备份数据库表 ${dbname} 开始" >> ${logpath}/mysql_backup.log #正式备份数据库 SQLBakName="${backup_time}.lxhp.tar.gz" mysqldump --user=$dbuser --password=$dbpasswd --databases $dbname > $datapath/mysql_backup_${backup_time}.sql find $datapath -type f -mtime +7 -exec rm -rf {} \; > /dev/null 2>&1
分享名称:mysql_backup.sh
标题路径:http://cdiso.cn/article/gdcdjj.html