From 1a72611102cac70674f358c0ec2c558172ed873c Mon Sep 17 00:00:00 2001 From: Patrick Canterino Date: Sat, 1 Jan 2022 17:41:46 +0100 Subject: [PATCH] Catch exception when creating a directory for a database backup --- psmysqlbackup.ps1 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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" -- 2.34.1