简体   繁体   English

在xampp windows 8上自动进行mysql备份?

[英]Automatic mysql backup on xampp windows 8?

I recently got in problem, my hard disk got crashed! 我最近遇到了问题,我的硬盘崩溃了!

ibdata1 file at "F:\\xampp\\mysql\\data\\ibdata1" in my hard disk got corrupt! 我硬盘中“F:\\ xampp \\ mysql \\ data \\ ibdata1”的ibdata1文件损坏了!

The file size was 8 gb but when I was trying to copy after 6 gb it was showing redundancy check error! 文件大小是8 GB,但当我试图复制6 gb后,它显示冗余检查错误!

I recently installed new xampp installation, just wondering if there is any way that it create automatic backup of files like webhosting service provider does. 我最近安装了新的xampp安装,只是想知道是否有任何方法可以创建像webhosting服务提供商那样的文件的自动备份。

Any help will be much appreciated. 任何帮助都感激不尽。

To extend answer you could use script below (for XAMPP or other mysql configuration). 要扩展答案,您可以使用下面的脚本(对于XAMPP或其他mysql配置)。 After creating bat file it can be set up in Windows Scheduler as weekly task for example. 创建bat文件后,可以在Windows Scheduler中将其设置为每周任务。

This script would create files like C:\\backups\\db1-2014-03-27.sql depending on date 此脚本将根据日期创建类似C:\\ backups \\ db1-2014-03-27.sql的文件

mysqldumper.bat mysqldumper.bat

FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
SET date=%yyyy%-%mm%-%dd%

C:\xampp\mysql\bin\mysqldump.exe db1 -h localhost -u user1 -pPassWord1 > C:\backups\db1-%date%.sql
C:\xampp\mysql\bin\mysqldump.exe db2 -h localhost -u user2 -pPassWord2 > C:\backups\db2-%date%.sql

I use a batch file that calls mysqldump and is executed on a schedule by Windows Task Scheduler. 我使用调用mysqldump的批处理文件,并由Windows任务计划程序按计划执行。

First you need to create a batch file. 首先,您需要创建批处理文件。 Open a new text file and inlclude something similar to this. 打开一个新的文本文件,并包含类似于此的内容。 Save it as a .BAT. 将其保存为.BAT。 You have to update the location of your MySQL bin. 您必须更新MySQL bin的位置。 on the first line. 在第一行。 This should be in your xamppfiles directory.Then include the proper mysql user name, database name and password in the mysqldump command 这应该在你的xamppfiles目录中。然后在mysqldump命令中包含正确的mysql用户名,数据库名和密码

REM Export all data from this database
cd C:\Program Files\MySQL\MySQL Server 5.6\bin

REM To export to file (structure only)
mysqldump --no-data [DATABASENAME] -h localhost -u [USER] -p[PASSWORD] > C:\databackup\database_ddl_backup.sql
mysqldump --no-create-info --no-create-db [DATABASENAME] -h localhost -u [USER] -p[PASSWORD] > C:\databackup\database_data.sql

Then you just have to schedule this batch file using Windows Task Scheduler. 然后,您只需使用Windows任务计划程序安排此批处理文件。 Here is an article that explains this for W7 and W8: 这是一篇为W7和W8解释的文章:

http://www.thewindowsclub.com/how-to-schedule-batch-file-run-automatically-windows-7 http://www.thewindowsclub.com/how-to-schedule-batch-file-run-automatically-windows-7

Just to extend a little more the given answers in case anyone wants to add time to the generated backup filenames. 只是为了扩展一些给定的答案,以防任何人想要为生成的备份文件名添加时间。

Using this: https://stackoverflow.com/a/19741875 使用此: https//stackoverflow.com/a/19741875

We can build the following batch file: 我们可以构建以下批处理文件:

FOR /f %%a IN ('WMIC OS GET LocalDateTime ^| FIND "."') DO SET DTS=%%a
SET date=%DTS:~0,8%-%DTS:~8,6%

C:\xampp\mysql\bin\mysqldump.exe db1 -h localhost -u user1 -pPassWord1 > C:\backups\db1-%date%.sql
C:\xampp\mysql\bin\mysqldump.exe db2 -h localhost -u user2 -pPassWord2 > C:\backups\db2-%date%.sql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM