]> git.p6c8.net - psmysqlbackup.git/blob - psmysqlbackup.ps1
Changed config variables to CamelCase
[psmysqlbackup.git] / psmysqlbackup.ps1
1 [String]$configMysqlHost = "localhost"
2 [String]$configMysqlUser = "backup"
3 [String]$configMysqlPassword = "backup"
4
5 [String]$configMysqlCli = "C:\Program Files\MariaDB 10.5\bin\mysql.exe"
6 [String]$configMysqldumpCli = "C:\Program Files\MariaDB 10.5\bin\mysqldump.exe"
7
8 [String]$configBackupDir = "backup"
9 [String]$configRotate = 7
10
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)
14
15 return $databases
16 }
17
18 function Create-Backup([String]$database, [String]$target) {
19 & $configMysqldumpCli --host=$configMysqlHost --user=$configMysqlUser --password=$configMysqlPassword --single-transaction --result-file=$target $database
20 }
21
22 $databases = Get-Databases | Where-Object { $_ -ne "information_schema" -and $_ -ne "performance_schema"}
23
24 foreach($d in $databases) {
25 $backupFile = $configBackupDir + "\" + $d + ".sql"
26 Write-Output "Backing up $d to $backupFile..."
27 Create-Backup $d $backupFile
28 }

patrick-canterino.de