23 lines
1009 B
PowerShell
23 lines
1009 B
PowerShell
param(
|
|
[ValidateSet('production', 'demo')][string]$Mode = 'production',
|
|
[string]$OutputDirectory = ''
|
|
)
|
|
. (Join-Path $PSScriptRoot 'sense-common.ps1')
|
|
|
|
try {
|
|
$root = Get-SensePackageRoot
|
|
$state = Initialize-SenseRuntime -PackageRoot $root -Mode $Mode -AllowOccupiedPort
|
|
$pgDump = Get-SensePostgresTool -Name 'pg_dump'
|
|
if ([string]::IsNullOrWhiteSpace($OutputDirectory)) { $OutputDirectory = Join-Path $root 'backups' }
|
|
$OutputDirectory = [IO.Path]::GetFullPath($OutputDirectory)
|
|
New-Item -ItemType Directory -Force -Path $OutputDirectory | Out-Null
|
|
$stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
|
|
$output = Join-Path $OutputDirectory "sense-$($state.Database.Database)-$stamp.dump"
|
|
Invoke-SensePostgresTool -Tool $pgDump -Database $state.Database -Arguments @('--dbname', $state.Database.Sanitized, '--format=custom', '--no-owner', '--file', $output)
|
|
Write-Host "Sense backup created: $output"
|
|
exit 0
|
|
} catch {
|
|
Write-Error $_.Exception.Message
|
|
exit 1
|
|
}
|