CentOS system automatic backup MySQL send to remote FTP

Source: Internet
Author: User

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

The most important thing is the data, but tomorrow manual backup is too cumbersome, and 8630.html "> Sometimes afraid to forget, especially the use of VPS friends, perhaps the day IDC ran out of the finished, so today to prepare a copy of the MySQL database automatically script, There are a lot of similar scripts on the web, but testing a few is not the problem, or you can only back up a single database export SQL files. It's not particularly ideal anyway. Night selected one of the tests for half a day can not upload, read the data made a little change, OK, to completely normal use, share out for everyone to reference it. To start with the characteristics of this script, the advantage of this script is to package the data file directly, of course, can contain all the databases under the Data folder, and others to pour out. SQL file compared to more convenient as long as the MySQL version, backup out of the data, restore as long as the MySQL service stop directly copied to the VPS MySQL Data folder coverage can be, the biggest advantage is that the database will not be a big point of SQL import failure.

What you need to be aware of using the script: The script is best not in the local Notepad to open the edit, test found that the permissions can be easily caused by the problem will not be able to run, it is best to download directly to the VPS with IV edit, or you can use VI to create a script and then copy the

I. VPS DIRECT DOWNLOAD

wget http://www.vpsck.com/soft/mysql_databak.sh

Script Content and description

#!/bin/sh/etc/init.d/mysqld stop #执行备份前先停止MySql to prevent data from being written, backup error date= ' date +%y%m%d ' #获取当前日期 days=3 #DAYS = 3 means to delete a backup 3 days ago. That is, only the last 3 days of backup Bk_dr=/home/mysql_data #备份文件存放路径 db_dr=/www/wdlinux/mysql-5.1.63/var #数据库所有在路径 linux_user=root #系统用户名 tar ZCVF $BK _dr/mysql_data$date.tar.gz $DB _dr #备份数据/etc/init.d/mysqld start #备份完成后, starting MySQL chown-r $LINUX _user: $LINUX _ USER $BK _dr #更改备份数据库文件的所有者 find $BK _dr-name "mysql_data*"-type f-mtime + $DAYS-exec rm {} \; #删除3天前的备份文件 (note: {} \; There are spaces in the middle) deldate= ' date-d -3day +%y_%m_%d ' #删除ftp服务器空间3天前的备份 ftp-v-n 192.168.0.1 << End #这个地方写 You remote FTP IP or domain name user vpsbf 123456 #用户名, password binary #设置二进制传输 CD Mysqlbak #进入ftp目录 (Note: This directory remote FTP first manually created) Lcd/home/mysql_data #列出 Local directory prompt mput mysql_data$date.tar.gz mysql_data$date.tar.gz #上传目录中的文件 mdelete mysql_data$deldate.tar.gz mysql_data$ deldate.tar.gz #删除ftp空间7天前的备份 close #关闭 bye #退出 end

Two. Create/home/mysql_data folder on VPS

SSH creation can also command creation or whatever.

Three. Edit script related content

vi/root/mysql_databak.sh

VI command used for the time being does not write a description if you do not search first, two days to write a tutorial

Four. Give script Execute permission

chmod +x/home/mysql_databak.sh

Five. The use of crontab to realize the timing of automatic operation (if not installed can be searched before the installation process to fill the tutorial)

Vi/etc/crontab

Add run code below

2 * * * root/home/mysql_databak.sh

Indicates a backup is performed 2:10 A.M. daily

Six. Test script is set up successfully

./mysql_databak.sh

If successful, FTP and VPS corresponding to the directory will produce a backup of the good files

Seven. Set crontab

Chkconfig Crond on #设为开机启动 service Crond start #启动任务

Through a series of settings, your data is very safe, scheduled to be backed up tomorrow. Not afraid of any accident cause data loss.

 

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.