Open Notepad and copy and paste below code snippet into notepad and
save it as "dbbackup.bat" file in the location where the FILE_PATH is
setted in the .bat file(Recommended)
Supported files can be downloaded from here
Explanation for code snippet:
1.In the "db backup.bat" file line 3 to 8 are to set the present date into variables
2.line 9 is to set the backup folder location to variable (i.e, set FILE_PATH=D:/Abc) this file location should contain 7za.exe(which is in supported files link) which is needed for compression of sql file.
3.line 11 is to make the database dump(mysqldump -u <username> -p<pasword> <schema name>) here in above code snippet user:root ans pass:root and schema=dbname1 are used change these values according to user requirements
4.line 12 is to zip the database dump file using 7zip(7za a -tzip <zipfilename.zip> <file.sql>)
5.line 13 is to delete the original database dump file(because it is already zipped)
this database backup script is dependent on operationg system. This database script is only applicable on windows systems.
Note: To make automatic backup of database use the "task schedular" tool in windows operating system.
Schedule the "dbbackup.bat" file to be run on Daily basis on desired time.
if any doubts feel free to mail on : sk.baji6@gmail.com
REM [at] echo off
for /f "tokens=1" %%i in ('date /t') do set DATE_DOW=%%i
for /f "tokens=2" %%i in ('date /t') do set DATE_DAY=%%i
for /f %%i in ('echo %date_day:/=-%') do set DATE_DAY=%%i
for /f %%i in ('time /t') do set DATE_TIME=%%i
for /f %%i in ('echo %date_time::=-%') do set DATE_TIME=%%i
set FILE_PATH=D:\Abc
"C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqldump" -u root -proot dbname1> "%FILE_PATH%\%DATE_DAY%_%DATE_TIME%dbname1.sql"
"%FILE_PATH%\7za" a -tzip "%FILE_PATH%\%DATE_DAY%_%DATE_TIME%dbname1.zip" "%FILE_PATH%\%DATE_DAY%_%DATE_TIME%dbname1.sql"
del "%FILE_PATH%\*.sql"
Supported files can be downloaded from here
Explanation for code snippet:
1.In the "db backup.bat" file line 3 to 8 are to set the present date into variables
2.line 9 is to set the backup folder location to variable (i.e, set FILE_PATH=D:/Abc) this file location should contain 7za.exe(which is in supported files link) which is needed for compression of sql file.
3.line 11 is to make the database dump(mysqldump -u <username> -p<pasword> <schema name>) here in above code snippet user:root ans pass:root and schema=dbname1 are used change these values according to user requirements
4.line 12 is to zip the database dump file using 7zip(7za a -tzip <zipfilename.zip> <file.sql>)
5.line 13 is to delete the original database dump file(because it is already zipped)
this database backup script is dependent on operationg system. This database script is only applicable on windows systems.
Note: To make automatic backup of database use the "task schedular" tool in windows operating system.
Schedule the "dbbackup.bat" file to be run on Daily basis on desired time.
if any doubts feel free to mail on : sk.baji6@gmail.com
إرسال تعليق