feat:backup und restore der contao Datenbank über sql file

This commit is contained in:
Robert Wartenberg committed 2026-08-18 17:24:12 +02:00
1 parent 1c1bf84b7a
commit e44b16e523
6 files changed
+237 -1

No files matched your search

@@ -0,0 +1,47 @@
[CmdletBinding()]
param(
[string]$ComposeFile = (Join-Path $PSScriptRoot '..\docker-compose.yml'),
[string]$OutputPath = (Join-Path $PSScriptRoot '..\database\contao-baseline.sql'),
[switch]$Force
)
$ErrorActionPreference = 'Stop'
$tables = @('tl_theme', 'tl_layout', 'tl_module', 'tl_page', 'tl_article', 'tl_content', 'tl_form', 'tl_form_field')
if ((Test-Path -LiteralPath $OutputPath) -and -not $Force) {
$confirmation = Read-Host "Die Datei '$OutputPath' existiert bereits. Überschreiben? [j/N]"
if ($confirmation.Trim().ToLowerInvariant() -notin @('j', 'ja', 'y', 'yes')) {
Write-Host 'Export nicht überschrieben.'
return
}
}
$composeFile = (Resolve-Path -LiteralPath $ComposeFile).Path
$outputDirectory = Split-Path -Parent $OutputPath
New-Item -ItemType Directory -Path $outputDirectory -Force | Out-Null
# Credentials bleiben im Compose-Service und werden nicht in den Export geschrieben.
$command = 'exec mariadb-dump -u"$MARIADB_USER" -p"$MARIADB_PASSWORD" --no-tablespaces --no-create-info --skip-comments --skip-triggers --skip-add-locks --skip-disable-keys --complete-insert --skip-extended-insert --order-by-primary --hex-blob "$MARIADB_DATABASE" tl_theme tl_layout tl_module tl_page tl_article tl_content tl_form tl_form_field'
$dump = & docker compose -f $composeFile exec -T db sh -lc $command
if ($LASTEXITCODE -ne 0) {
throw 'Der Contao-Baseline-Export ist fehlgeschlagen.'
}
$header = @(
'-- Contao website baseline for local development.',
'--',
'-- Contains only versionable website data. It deliberately excludes users,',
'-- credentials, sessions, logs, cache entries and file metadata.',
'-- Generated with scripts/Export-ContaoBaseline.ps1.',
''
)
$utf8WithoutBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText(
(Resolve-Path -LiteralPath $outputDirectory).Path + [System.IO.Path]::DirectorySeparatorChar + (Split-Path -Leaf $OutputPath),
(($header + $dump) -join [Environment]::NewLine) + [Environment]::NewLine,
$utf8WithoutBom
)
Write-Host "Contao-Baseline exportiert nach $OutputPath"