X-Git-Url: https://git.p6c8.net/psmysqlbackup.git/blobdiff_plain/22cc4213448f24a39515d9b3c6a906b85dfbdb19..00c62a33770c2c932dbd14d46a7f443c9c8f4d5e:/psmysqlbackup.ps1?ds=sidebyside diff --git a/psmysqlbackup.ps1 b/psmysqlbackup.ps1 index 164bdeb..7ca585a 100644 --- a/psmysqlbackup.ps1 +++ b/psmysqlbackup.ps1 @@ -19,10 +19,18 @@ function Create-Backup([String]$database, [String]$target) { & $configMysqldumpCli --host=$configMysqlHost --user=$configMysqlUser --password=$configMysqlPassword --single-transaction --result-file=$target $database } +$currDaytime = Get-Date -format "yyyyMMdd-HHmmss" + $databases = Get-Databases | Where-Object { $_ -ne "information_schema" -and $_ -ne "performance_schema"} foreach($d in $databases) { - $backupFile = $configBackupDir + "\" + $d + ".sql" - Write-Output "Backing up $d to $backupFile..." - Create-Backup $d $backupFile + $databaseBackupDir = Join-Path -Path $configBackupDir -ChildPath $d + + if(!(Test-Path $databaseBackupDir)) { + New-Item -ItemType directory -Path $databaseBackupDir -ErrorAction Stop | Out-Null + } + + $databaseBackupFile = Join-Path -Path $databaseBackupDir -ChildPath "backup-$d-$currDaytime.sql" + Write-Output "Backing up $d to $databaseBackupFile..." + Create-Backup $d $databaseBackupFile } \ No newline at end of file