The cluster of Project 3.0 is built to complete, leaving only the details of the configuration, and the post-security and optimization of processing, taking into account the database data needs to be backed up processing,
But daily manual backup processing is too passive, and daytime user access, there will be data changes and in the backup will affect the performance of the server's normal operation,
So consider writing a script and developing a timed task to perform a script backup of the data;
#!/bin/bash
# # #数据库定时备份, and package the backed up library for compression
User=root
passwd=123456
Back_path=/vdb1/mysql/backup
Data_name=zmq123
Date= ' Date +%y%m%d '
mkdir $back _path/$date
Mysqldump-u $user-p$passwd $data _name |gzip > $back _path/$date/$data _name.sql.gz
#定时任务, schedule a data backup every night 23:55
55 23 * * *. /vdb1/mysql/mysqldump.sh
After running for a while, and found that the backup of the data some of the disk space, and I want to save only the last January of data can be, so the script to upgrade,
In the case where no one is aware, the disk will not be full of backup data;
# # #升级版每天晚上11:55 minutes for scheduled backups,
#!/bin/bash
year= ' date +%y '
month= ' date +%m '
day= ' date +%d '
backpath=/ vdb1/mysql/backup/$year $month/
user=root
passwd=123456
dataname=zmq123
[-D $backpath] | | mkdir-p $ Backpath
rq= ' date +%y%m%d '
mysqldump-u $user-p$passwd $dataname |gzip > $backpath/$RQ. sql.gz
#定时任务
Timeshare Sun Moon Week
23 * * *./vdb1/mysql/mysqldump.sh
####### #每月2号晚上11:30 for scheduled deletion last month back up data
#!/bin/bash
Year= ' Date +%y '
Month= ' Date +%m '
Month= ' Expr $month-1 '
If [$month-eq 0];then
Month=12
Day=31
Year= ' expr $year-1 '
Fi
If [$month-lt];then
Pre=0
Fi
backdir=/vdb1/mysql/backup/$year $pre$month
RM-RF $backdir #删除上一个月的数据
# #定时任务
30 23 2 * *. /vdb1/mysql/delmysqlbak.sh
Ok! Write to finish, first run for a while to see it! There is a situation for further improvement;
MySQL scheduled backup data script