DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

MySql Backups Under Windows

03.13.2006
| 24311 views |
  • submit to reddit
        This batch script will backup any MySql database on the local machine, including all routines (stored procedures and functions), to a file named after the database followed by the date (YYYY-MM-DD) and time (HHMMSSSS). The first argument is the database name, second is the username to run the backup as and third is the password.

This script requires your date and time formats to be the windows default formats. Changing them can break this script. The script pauses at the end to cause a cmd window to remain open for long enough for the user to read the output.

@echo off
echo Starting Backup of Database: %1

For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set dt=%%c-%%a-%%b)
For /f "tokens=1-4 delims=:." %%a in ('echo %time%') do (set tm=%%a%%b%%c%%d)
set bkupfilename=%1 %dt% %tm%.bak
echo Backing up to file: %bkupfilename%

mysqldump %1 --routines -u %2 -p%3 > "%bkupfilename%"

echo Backup Complete!
pause
echo on

-- 
Version 0.1.0 - 2006-03-13
STEM: The STEM Cells of PHP
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License
http://creativecommons.org/licenses/by-sa/2.5/