当前位置:Gxlcms > mysql > mysql自动备份的实现_MySQL

mysql自动备份的实现_MySQL

时间:2021-07-01 10:21:17 帮助过:4人阅读

最近接手了个win2003的服务器,需要做个mysql的备份

@echooff

sethour=%time:~0,2%

if"%hour:~0,1%"==" "sethour=0%hour:~1,1%

setmin=%time:~3,2%

if"%min:~0,1%"==" "setmin=0%min:~1,1%

setsecs=%time:~6,2%

if"%secs:~0,1%"==" "setsecs=0%secs:~1,1%

set"Ymd=%date:~,4%%date:~5,2%%date:~8,2%"

setM=%date:~5,2%

setD=%date:~8,2%

set"Time=%hour%%min%"

mysqldump-u[username]-p[dbpwd][dbname]>D:/tmp/[dbname]_%Ymd%%Time%.sql

7zaaD:/db_bak/%M%/%D%/[dbname]_%Ymd%%Time%.7zD:/tmp/[dbname]_%Ymd%%Time%.sql

delD:/tmp/[dbname]_%Ymd%%Time%.sql

@echoon

用7z压缩可以更省空间(需先将对应的7za.exe拖至system32下 或以完整路径调用等),相对于tar.gz只占其75%左右的空间
winserver的计划任务在控制面板

附linux的

USER="[dbuser]"

PWD="[dbpwd]"PORT="3306"DB="[dbname]"

DAY=`date+%Y%m%d%H%M`

YM=`date+%Y%m`D=`date+%d`

/usr/bin/mysqldump -u$USER-p$PWD-P$PORT -B$DB>>/tmp/${DB}_$DAY.sql

mkdir-p/mysqldata/$YM/$D/

7zaa/mysqldata/$YM/$D/${DB}_$DAY.7z /tmp/${DB}_$DAY.sql

rm-f/tmp/${DB}_$DAY.sql

人气教程排行