Script simple backup database Mysql dengan command prompt
Confused looking for automatic backup for mysql database?
Here are easy and simple steps to perform scheduled automatic backups using the command prompt bat script and Task Scheduler
1. Create a bat file with the name backupdb.bat with the following command
mysqldump.exe -h localhost –user=root –password=admin –databases dbbackup > C:\backup\dbbackup-%date:~-4.4%%date:~-10.2%%date:~ -7,2%.sql
“C:\Program Files\7-Zip\7z.exe” a -mx=9 C:\backup\dbbackup-%date:~-4.4%%date:~-10.2%%date:~- 7.2%.7z C:\backup\dbbackup-%date:~-4.4%%date:~-10.2%%date:~-7.2%.sql
del C:\backup\dbbackup-%date:~-4.4%%date:~-10.2%%date:~-7.2%.sql
Note: the command above performs a database backup with the name db dbbackup using mysqldump in the c:\backup folder the sample backup named dbbackup-20151125.sql takes from the system date, then compressed via 7zip, the last command deletes the sql file, leaving only the file compressed db backup
2. Click Control Panel -> Administrative Tools -> Task Scheduler
Check Run whether the user is logged on or not so that the schedule job runs even if the user is logged in or not
3. On the Actions tab, right click Create Task, input the name of schedule
4. Select the Triggers tab, click New, determine whether your backup schedule is only for one process / per day / per week / per month.
Also specify when the date and time the schedule starts. Click OK.
5. Select the Actions tab, fill in Program/Script, select the backupdb.bat file that was created above. Click OK.
6. Click Ok to save the backup job
To make sure the backup runs smoothly, try to test the bat file and on the job schedule, you can run the job schedule directly.
Required software:
mysql
7zip