1 [String]$configMysqlHost = "localhost"
2 [String]$configMysqlUser = "backup"
3 [String]$configMysqlPassword = "backup"
5 [String]$configMysqlCli = "C:\Program Files\MariaDB 10.5\bin\mysql.exe"
6 [String]$configMysqldumpCli = "C:\Program Files\MariaDB 10.5\bin\mysqldump.exe"
8 [String]$configBackupDir = "backup"
9 [String]$configRotate = 7
11 function Get-Databases() {
12 $databaseString = (& $configMysqlCli --host=$configMysqlHost --user=$configMysqlUser --password=$configMysqlPassword --batch --skip-column-names -e "SHOW DATABASES;")
13 $databases = $databaseString.split([Environment]::NewLine)
18 function Create-Backup([String]$database, [String]$target) {
19 & $configMysqldumpCli --host=$configMysqlHost --user=$configMysqlUser --password=$configMysqlPassword --single-transaction --result-file=$target $database
22 $currDaytime = Get-Date -format "yyyyMMdd-HHmmss"
24 $databases = Get-Databases | Where-Object { $_ -ne "information_schema" -and $_ -ne "performance_schema"}
26 foreach($d in $databases) {
27 $databaseBackupDir = Join-Path -Path $configBackupDir -ChildPath $d
29 if(!(Test-Path $databaseBackupDir)) {
30 New-Item -ItemType directory -Path $databaseBackupDir -ErrorAction Stop | Out-Null
33 $databaseBackupFile = Join-Path -Path $databaseBackupDir -ChildPath "backup-$d-$currDaytime.sql"
34 Write-Output "Backing up $d to $databaseBackupFile..."
35 Create-Backup $d $databaseBackupFile