MySql-Backup-Windows
Backup MySQL databases and gzip the output sql files. Using PowerShell script language for Windows. Got the idea from mysql-backup-windows.bat.
Requirements
- Powershell
- 7-Zip
- MySql Workbench if this script is not run on the mysql server, provides the tools mysqldump.exe and mysql.exe
Setup
Download the github archive and extract to your script folder.
On mysqlbackup.ps1 file:
- Change the value of the variable
$backupDir
to the path to the folder where the backup files will be stored. - If required change the value of the variable
$mysqldump
to the path to mysqldump.exe file. - If required change the value of the variable
$mysql
to the path to mysql.exe file. - If required change the value of the variable
$zip
to the path to 7z.exe file.
On my.cnf file:
In section [client]
change the user and password to your backup user. I recommend create user for backup with limit to hosts matching: localhost or the server where you run the script and Administrative Roles: BackupAdmin(Global Privileges: EVENT, LOCK TABLES, SELECT, SHOW DATABASES).
Example my.cnf
[client]
user="user"
password="password"
host="host.domain.name"
[mysqldump]
single-transaction
add-drop-database
add-drop-table
On Task Scheduler:
Сreate a task to run the mysqlbackup.ps1 script. Import the XML file and update to your environment.