Installation Environment: CentOS 6,mysql5.5
I. BACKGROUND
recently, the company to strengthen the database data security, automatic database backup, this article will be used under Linux crontab automatic backup and FTP upload database.
Second, the implementation of the script
Create Script dbbackup.sh
#!/bin/bashdate= ' date +%y%m%d%h%m ' database=**** #备份数据库DB_USER =**** #备份用户名DB_PASS = "*******" #备份用户名的密码BACKUP =******** #备份路径 /usr/local/ mysql/bin/mysqldump -u$db_user -p$db_pass -h 127.0.0.1 -r --opt $DATABASE |gzip > ${BACKUP}\/${DATABASE}_${DATE}.sql.gz #备份及压缩sleep 3find $BACKUP -mtime +7 |xargs rm -rf #删除7天以上的备份文件sleep 3ftp -vn<<EOF open *.*.*.26 21 #打开ftp服务器, 21 for FTP server port User username password #ftp用户名及密码binary #二进制上传cd backup #切换ftp目录lcd $BACkup # Switch Local directory prompt #控制是否使用交互模式, use turn off this feature mput ${database}_${date}.sql.gz #上传备份文件closebyeEOF
Add executable permissions
chmod +x dbbackup.sh
Join the crontab scheduled task, which is automatically performed 3 o'clock in the morning every day.
CRONTAB-E 0 3 * * */root/dbbackup.sh >/dev/null 2>&1
Insufficient: The backup test failed to add more than 7 days of deletion due to the FTP upload, so it was not added to the script. And some of the settings in the script do not use variables, not to achieve the success of mail notification backup, follow-up will continue to improve. The next article describes SQL Server backup and FTP uploads small software.
This article is from the "Frank" blog, so be sure to keep this source http://zhoufan.blog.51cto.com/4278592/1790389
MySQL automatic backup and FTP remote backup in CentOS Linux