From 13125b9deaa430ff6c083bfa656fa1ba20c3b4e7 Mon Sep 17 00:00:00 2001 From: Patrick Canterino Date: Mon, 27 Dec 2021 13:05:34 +0100 Subject: [PATCH 1/1] Changed creation of backup files - Every database has its own directory - Every backup file has a timestamp in its filename --- psmysqlbackup.ps1 | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 -- 2.34.1