🌙 Daily MySQL Backup (Windows)
Nurul Islam Rimon

Nurul Islam Rimon @nurulislamrimon

About: Thanks for being here! I'm Nurul Islam Rimon, a MERN & PERN stack developer. I'm a student of competitive programming. I love to explore new technology.

Location:
Chaprashirhat, Kabirhat, Noakhali
Joined:
Jan 20, 2024

🌙 Daily MySQL Backup (Windows)

Publish Date: Apr 21
9 0

🧾 What It Does

📦 Exports your MySQL database to a .sql file
🕒 Runs automatically every day
🧹 Deletes old backups after 7 days (optional)

📁 Folder Setup

Create this folder on your PC:

D:\datas\Automatic_Backup
Enter fullscreen mode Exit fullscreen mode

🧑‍💻 Backup Script

Create a file named:
D:\datas\Automatic_Backup\auto_mysql_backup.bat

Paste this:

@echo off
set TIMESTAMP=%DATE:~10,4%-%DATE:~4,2%-%DATE:~7,2%_%TIME:~0,2%-%TIME:~3,2%
set TIMESTAMP=%TIMESTAMP: =0%

set BACKUP_DIR=D:\datas\Automatic_Backup
set DB_HOST=82.197.71.175
set DB_USER=ni
set DB_PASS=your_password_here
set DB_NAME=bdcommerce_37295

mkdir "%BACKUP_DIR%" 2>nul
mysqldump -h %DB_HOST% -u %DB_USER% -p%DB_PASS% %DB_NAME% > "%BACKUP_DIR%\%DB_NAME%_%TIMESTAMP%.sql"

forfiles /p "%BACKUP_DIR%" /m *.sql /d -7 /c "cmd /c del @path"
Enter fullscreen mode Exit fullscreen mode

✅ Replace your_password_here with your actual password.

🕒 Automate It

  1. Open Task Scheduler
  2. Click Create Basic Task
  3. Trigger: Daily
  4. Action: Start a Program → Select your .bat file
  5. Done 🎉

✅ Example Output

bdcommerce_37295_2025-04-21_03-00.sql
Enter fullscreen mode Exit fullscreen mode

Regards,
N I Rimon

Comments 0 total

    Add comment