简体   繁体   English

使用Coldfusion备份MySQL数据库

[英]Backup MySQL db with Coldfusion

What I want to do is run a backup task in Coldfusion (probably in a scheduled task) which will back up the structure and data in a MySql database. 我想要做的是在Coldfusion中运行备份任务(可能在计划任务中),它将备份MySql数据库中的结构和数据。

The hosting server I use always blocks the use of cfexecute for security purposes so I can't use mysqldump. 我使用的托管服务器总是阻止使用cfexecute用于安全目的,所以我不能使用mysqldump。

eg 例如

<cfexecute name="c:\program files\mysql\mysql server 4.1\bin\mysqldump"
 arguments="--user=xxx --password=yyy dharma" 
 outputfile="#expandPath("./ao.sql")#" timeout="30"/>

(From Raymond Camden) (来自雷蒙德卡姆登)

Are there any other options available to me ? 我还有其他选择吗?

Backing up database files is a good idea, but if you back them up to the same drive, and the drive fails, you are screwed. 备份数据库文件是一个好主意,但是如果你将它们备份到同一个驱动器,并且驱动器出现故障,那么你就搞砸了。 I backup my databases daily to my local system. 我每天将我的数据库备份到本地系统。 Here is the script I use in a .bat file 这是我在.bat文件中使用的脚本

@ECHO OFF


@REM Set dir variables. Use ~1 format in win2k

SET basedir={directory where zip files will be put}
SET workdir={Working directory}
SET mysqldir=c:\PROGRA~1\mysql\mysqls~1.5\bin
SET gzipdir=c:\PROGRA~2\GnuWin32\bin
SET mysqlpassword={db password}
SET mysqluser={db user}
SET host={host IP or domain name}
for /f "tokens=1-4 delims=/ " %%a in ('date/t') do ( 
set mm=%%a
set dd=%%b
set yy=%%c
)

ECHO Check connection
PING -n 1 %host%|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESS
IF ERRORLEVEL 1 goto :END

:SUCCESS
ECHO Connection found, run backup

@REM Change to mysqldir
CD %mysqldir%

@REM dump database. This is all one line
mysqldump -h %host% -u %mysqluser% -p%mysqlpassword% --databases {space delimited list of databases to backup >%workdir%\backup.sql

@REM Change to workdir  
CD %workdir%

@REM Zip up database
%gzipdir%\gzip.exe backup.sql

@REM Move to random file name
MOVE backup.sql.gz %basedir%\%yy%_%mm%_%dd%_backup.gz

@REM Change back to base dir
CD %basedir%

:END
ECHO No connection, do not run

I use Windows task scheduler to run this every night. 我使用Windows任务计划程序每晚运行它。 You could probably update it to remove older backups. 您可以更新它以删除旧备份。

You will need to make sure you have gzip installed. 您需要确保安装了gzip。

This will put copies of the DB on your local system - I then use a backup service to back up the backups to another offsite system. 这将把DB的副本放在本地系统上 - 然后我使用备份服务将备份备份到另一个异地系统。

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

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