]> git.p6c8.net - psmysqlbackup.git/blob - psmysqlbackup.ps1
dca87c2b8a8c01c95bd31c8c0fa1a46b7c5f36d4
[psmysqlbackup.git] / psmysqlbackup.ps1
1 [String]$config_mysql_host = "localhost"
2 [String]$config_mysql_user = "backup"
3 [String]$config_mysql_password = "backup"
4
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"
7
8 [String]$config_backup_dir = "backup"
9 [String]$config_rotate = 7
10
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)
14
15 return $databases
16 }
17
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
20 }
21
22 $databases = Get-Databases | Where-Object { $_ -ne "information_schema" -and $_ -ne "performance_schema"}
23
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
28 }

patrick-canterino.de