1 [String]$config_mysql_host = "localhost"
2 [String]$config_mysql_user = "backup"
3 [String]$config_mysql_password = "backup"
5 [String]$config_mysql_cli = "C:\Program Files\MariaDB 10.5\bin\mysql.exe"
6 [String]$config_mysqldump_cli = "C:\Program Files\MariaDB 10.5\bin\mysqldump.exe"
8 [String]$config_backup_dir = "backup"
9 [String]$config_rotate = 7
11 function Get-Databases() {
12 $databaseString = (& $config_mysql_cli --host=$config_mysql_host --user=$config_mysql_user --password=$config_mysql_password --batch --skip-column-names -e "SHOW DATABASES;")
13 $databases = $databaseString.split([Environment]::NewLine)
18 function Create-Backup([String]$database, [String]$target) {
19 & $config_mysqldump_cli --host=$config_mysql_host --user=$config_mysql_user --password=$config_mysql_password --single-transaction --result-file=$target $database
22 $databases = Get-Databases | Where-Object { $_ -ne "information_schema" -and $_ -ne "performance_schema"}
24 foreach($d in $databases) {
25 $backupFile = $config_backup_dir + "\" + $d + ".sql"
26 Write-Output "Backing up $d to $backupFile..."
27 Create-Backup $d $backupFile