MySQL automatic backup and FTP remote backup in CentOS Linux

Source: Internet
Author: User
Tags mysql automatic backup server port

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.