Jump to content
  • 0

I have been looking to improve my DB backup script


kylemcqueen75

Question

Hey Guys,

I have been working on a BD backup batch. I know there is a forum post already but this a SQL Dump for Remote servers. I am going to point out now, I did not make this from scratch, I search the interwebz for a lot of this code. (Minus the create dir lines and del files.) I have a script right now that works for the most part but I want to make something like this available to everyone and easily reconfigured, as it is not atm. Anyway here is what I have at the moment:
 

@ECHO OFF
echo Getting Time...
:: get date
for /F "tokens=2-4 delims=/ " %%i in ('date /t') do (
set mm=%%i
set dd=%%j
set yy=%%k
)
 
:: get time
for /F "tokens=5-8 delims=:. " %%i in ('echo.^| time ^| find "current" ') do (
set hh=%%i
set mm=%%j
)
set backupdir="C:\customdirhere\customdirhere\"
set dirName=%yy%%mm%%dd%_%hh%%mm%
set dbUser=user
set dbPassword=password
echo Creating Dir...
mkdir %backupDir%\%dirName%
echo Running dump...
mysqldump --host="hostname/ip" --user=%dbUser% --password=%dbPassword% dbname > %backupDir%\%dirName%\backup.sql
echo Zipping SQL...
set zip="F:\Program Files\7-Zip\7z.exe"
%zip% a -tgzip %backupdir%\%dirName%\backup.sql.gz %backupdir%\%dirName%\backup.sql
echo Deleting UnZipped SQL
del %backupdir%\%dirName%\backup.sql
echo Done!

A few notes:
- Makes tons of folders. I prefer this method instead of looking at a thousand files. (Not sure why, files annoy me :P)
- No idea why it will not use "--databases" instead of listed db names.
- You need 7-Zip
- I use Windows Schedule to automate it.

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...