From: Patrick Canterino Date: Sat, 1 Jan 2022 16:41:46 +0000 (+0100) Subject: Catch exception when creating a directory for a database backup X-Git-Tag: 0.1 X-Git-Url: https://git.p6c8.net/psmysqlbackup.git/commitdiff_plain/1a72611102cac70674f358c0ec2c558172ed873c?ds=sidebyside Catch exception when creating a directory for a database backup --- diff --git a/psmysqlbackup.ps1 b/psmysqlbackup.ps1 index 03d63ea..f544cca 100644 --- a/psmysqlbackup.ps1 +++ b/psmysqlbackup.ps1 @@ -111,7 +111,14 @@ foreach($d in $databasesToBackup) { $databaseBackupDir = Join-Path -Path $configBackupDir -ChildPath $d if(!(Test-Path $databaseBackupDir)) { - New-Item -ItemType directory -Path $databaseBackupDir -ErrorAction Stop | Out-Null + try { + New-Item -ItemType directory -Path "$databaseBackupDir" -ErrorAction Stop | Out-Null + } + catch { + Write-Output "Failed to create directory $databaseBackupDir" + Write-Output $_ + exit 1 + } } $databaseBackupFile = Join-Path -Path $databaseBackupDir -ChildPath "backup-$d-$currDaytime.sql"