Perform a full hot backup of the Extmail database daily 01:00, and you can fully recover!
First, create a backup script, as follows:
1234567891011121314151617 |
vi
mysql_extmail_bak.sh
#!/bin/bash
# Program
# use mysqldump to Fully backup mysql data per week!
BakDir=
/mysqlback
#要备份到的目录
LogFile=
/var/log/bak
.log
#备份记录日志
Date=`
date
+%Y%m%d`
Begin=`
date
+
"%Y年%m月%d日 %H:%M:%S"
`
cd $BakDir
DB=extmail
#要备份的数据库名称
DumpFile=$DB$Date.sql
GZDumpFile=$Date.sql.
tar
.gz
/usr/bin/mysqldump
-uroot -p123123 --quick --databases $DB --flush-logs --single-transaction > $DumpFile
/bin/tar
czvf $GZDumpFile $DumpFile
/bin/rm $DumpFile
Last=`
date +
"%Y年%m月%d日 %H:%M:%S"
`
echo
开始:$Begin 结束:$Last $GZDumpFile succ >> $LogFile
|
Second, restore the backup SQL file as follows:
1234 |
cd
/mysqlback
tar
zxvf extmail20170515.
tar
.gz
mv
extmail20170515.sql extmail.sql
mysql -uroot -p < extmail.sql
|
This article from "12016522" blog, declined reprint!
MySQL backup script