From: Patrick Canterino Date: Mon, 27 Dec 2021 12:05:34 +0000 (+0100) Subject: Changed creation of backup files X-Git-Tag: 0.1~20 X-Git-Url: https://git.p6c8.net/psmysqlbackup.git/commitdiff_plain/13125b9deaa430ff6c083bfa656fa1ba20c3b4e7?ds=inline Changed creation of backup files - Every database has its own directory - Every backup file has a timestamp in its filename --- 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