In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
1. Full backup and incremental backup of mysql. Enable the logbin log function of mysql. Add the following code to the / etc/my.cnf file:
[mysqld]
Log-bin = "/ home/mysql/logbin.log"
Binlog-format = ROW
Log-bin-index = "/ home/mysql/logindex"
Binlog_cache_size=32m
Max_binlog_cache_size=512m
Max_binlog_size=512m
Just restart mysql. The users and groups in the path / home/mysql should be changed to mysql.
2. Incremental backup
Create the following directory under the / home/mysql/ directory:
Mkdir-p/home/mysql/backup/daily
Incremental backup script
Cd / home/mysql
Vi binlogbak.sh
#! / bin/bash
Export.UTF-8
BakDir=/home/mysql/backup/daily
BinDir=/home/mysql
LogFile=/home/mysql/backup/binlog.log
BinFile=/home/mysql/logindex.index
Mysqladmin-uroot-proot123flush-logs
# this is used to generate new mysql-bin.00000* files
Counter= `wc-l $BinFile | awk' {print $1}'`
NextNum=0
The for loop is used to compare the two values of $Counter,$NextNum to determine whether the file exists or is up to date.
For file in `cat $BinFile`
Do
Base= `basename $file`
# basename is used to intercept the mysql-bin.00000* file name and remove the. / before the. / mysql-bin.000005
NextNum= `expr $NextNum + 1`
If [$NextNum-eq $Counter]
Then
Echo $base skip! > > $LogFile
Else
Dest=$BakDir/$base
If (test-e $dest)
# test-e is used to detect whether the target file exists. Write exist if it exists! Go to $LogFile.
Then
Echo $base exist! > > $LogFile
Else
Cp $BinDir/$base $BakDir
Echo $base copying > > $LogFile
Fi
Fi
Done
Echo `date + "Y% m% d% H:%M:%S" `Bakup succ! > > $LogFile
Give binlogbak.sh execution permission
Chmod a+x/home/mysql/binlogbak.sh
3. Full backup
Vi databak.sh
#! / bin/bash
Export.UTF-8
BakDir=/home/mysql/backup
LogFile=/home/mysql/backup/bak.log
Date= `date +% Y% m% d`
Begin= `date + "Y% m / d% H:%M:%S" `
Cd $BakDir
DumpFile=$Date.sql
GZDumpFile=$Date.sql.tgz
Mysqldump-uroot-proot123--all-databases-flush-logs-delete-master-logs-single-transaction > $DumpFile
Tar-czvf $GZDumpFile $DumpFile
Rm $DumpFile
Count=$ (ls-l * .tgz | wc-l)
If [$count-ge 5]
Then
File=$ (ls-l * .tgz | awk'{print$9}'| awk 'NR==1')
Rm-f $file
Fi
# keep only the contents of the database in the past four weeks
Last= `date + "Y% m / d% H:%M:%S" `
Echo start: $Begin end: $Last$GZDumpFile succ > > $LogFile
Cd $BakDir/daily
Rm-f *
Give databak.sh execution permission
Chmod a+x/home/mysql/databak.sh
4. Start the timing task
Crontab-e
# execute a full backup script at 3:00 every Sunday morning
0 3 * * 0/home/mysql/databak.sh > / dev/null 2 > & 1
# do incremental backups from Monday to Saturday at 3:00
0 3 * * 1-6/home/mysql/binlogbak.sh > / dev/null 2 > & 1
Make the above scheduled tasks effective
Crontab / etc/crontab
View scheduled tasks
Crontab-l
Done.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.