]> git.p6c8.net - psmysqlbackup.git/commitdiff
Changed creation of backup files
authorPatrick Canterino <patrick@patrick-canterino.de>
Mon, 27 Dec 2021 12:05:34 +0000 (13:05 +0100)
committerPatrick Canterino <patrick@patrick-canterino.de>
Mon, 27 Dec 2021 12:05:34 +0000 (13:05 +0100)
- Every database has its own directory
- Every backup file has a timestamp in its filename

psmysqlbackup.ps1

index 164bdeb93d17a25ea887e2b975c533799536c06e..7ca585a28afe40a4736aae1ba3fbe79360883103 100644 (file)
@@ -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

patrick-canterino.de