首页 >数据库 >mysql教程 >mysql 自动备份的实现_MySQL

mysql 自动备份的实现_MySQL

WBOY
WBOY原创
2016-06-01 13:12:36878浏览

最近接手了个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

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn